Skip to content

Commit

Permalink
Switch from Rubocop to Standard (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
spickermann authored Dec 25, 2023
1 parent a7875ae commit 2d328a0
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 163 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
ruby: [3.3.0-preview1, 3.2.2, 3.1.4, 3.0.5, 2.7.7, 2.6.10, 2.5.9]
ruby: [3.3.0, 3.2.2, 3.1.4, 3.0.6]

name: CI Ruby ${{ matrix.ruby }}
steps:
Expand All @@ -26,18 +26,18 @@ jobs:
run: bundle install
- name: RSpec
run: bundle exec rspec
- name: Rubocop
run: bundle exec rubocop
- name: Standard
run: bundle exec standardrb
- name: Coveralls
if: ${{ matrix.ruby == '3.2.2' }}
if: ${{ matrix.ruby == '3.3.0' }}
continue-on-error: true
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Code Climate
if: ${{ matrix.ruby == '3.2.2' }}
if: ${{ matrix.ruby == '3.3.0' }}
continue-on-error: true
uses: paambaati/codeclimate-action@v4.0.0
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_TOKEN }}
with:
Expand Down
24 changes: 0 additions & 24 deletions .rubocop.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .ruby-style.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .standard-rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require:
- rubocop-rspec
7 changes: 7 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ruby_version: 3.0

plugins:
- standard-performance

extend_config:
- .standard-rspec.yml
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
*Unreleased*
*2.2.1 (December 25, 2023)*

* Ensure Ruby 3.3 compability
* Stop testing against Ruby < 3.0
* Switch from Rubocop to Standard

*2.2.0 (May 17, 2023)*

Expand Down
17 changes: 8 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-lcov'
gem "rake"
gem "rspec"
gem "rubocop-rspec"
gem "simplecov"
gem "simplecov-lcov"
gem "standard"
gem "standard-performance"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/spicke
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new pull request
5. Create a new pull request.

## License

Expand Down
9 changes: 4 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "standard/rake"

RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
RuboCop::RakeTask.new(:rubocop)

task default: %i[spec rubocop]
task default: %i[spec standard]
28 changes: 14 additions & 14 deletions deep_hash_transformer.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'deep_hash_transformer/version'
require "deep_hash_transformer/version"

Gem::Specification.new do |spec|
spec.authors = ['Martin Spickermann']
spec.email = ['[email protected]']
spec.homepage = 'https://github.com/spickermann/deep_hash_transformer'
spec.license = 'MIT'
spec.authors = ["Martin Spickermann"]
spec.email = ["[email protected]"]
spec.homepage = "https://github.com/spickermann/deep_hash_transformer"
spec.license = "MIT"

spec.name = 'deep_hash_transformer'
spec.version = DeepHashTransformer::VERSION
spec.name = "deep_hash_transformer"
spec.version = DeepHashTransformer::VERSION

spec.summary = 'Transforms deeply nested hash structure'
spec.description = <<-DESCRIPTION
spec.summary = "Transforms deeply nested hash structure"
spec.description = <<-DESCRIPTION
DeepHashTransformer helps to transform keys in deeply nested hash structures
DESCRIPTION

spec.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README', 'lib/**/*', 'spec/**/*']
spec.files = Dir["CHANGELOG", "MIT-LICENSE", "README", "lib/**/*", "spec/**/*"]

spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.5.0'
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 3.0.0"

spec.metadata['rubygems_mfa_required'] = 'true'
spec.metadata["rubygems_mfa_required"] = "true"
end
22 changes: 11 additions & 11 deletions lib/deep_hash_transformer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'deep_hash_transformer/collection_operation'
require 'deep_hash_transformer/element_operation'
require 'deep_hash_transformer/version'
require "deep_hash_transformer/collection_operation"
require "deep_hash_transformer/element_operation"
require "deep_hash_transformer/version"

class DeepHashTransformer
ELEMENT_OPS = %i[
Expand Down Expand Up @@ -31,7 +31,7 @@ def tr(*ops)
unknown_transformations = ops.map(&:to_s) - OPS.map(&:to_s)
if unknown_transformations.any?
raise(
ArgumentError, "unknown transformation(s): #{unknown_transformations.join(',')}"
ArgumentError, "unknown transformation(s): #{unknown_transformations.join(",")}"
)
end

Expand All @@ -54,13 +54,13 @@ def transform_collection(collection, ops)

def transform_value(value, ops)
collection = case value
when Array
value.map { |e| transform_value(e, ops) }
when Hash
value.map { |k, v| [transform_key(k, ops), transform_value(v, ops)] }.to_h
else
value
end
when Array
value.map { |e| transform_value(e, ops) }
when Hash
value.map { |k, v| [transform_key(k, ops), transform_value(v, ops)] }.to_h
else
value
end

transform_collection(collection, ops)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/deep_hash_transformer/blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class DeepHashTransformer
class Blank
BLANK_STRING = /\A[[:space:]]*\z/.freeze
BLANK_STRING = /\A[[:space:]]*\z/

def self.call(value)
new(value).blank?
Expand All @@ -13,10 +13,10 @@ def initialize(value)
end

def blank?
return true unless value
return value.blank? if value.respond_to?(:blank?)
return true unless value
return value.blank? if value.respond_to?(:blank?)
return BLANK_STRING.match?(value) if value.is_a?(String)
return value.empty? if value.respond_to?(:empty?)
return value.empty? if value.respond_to?(:empty?)

false
end
Expand Down
2 changes: 1 addition & 1 deletion lib/deep_hash_transformer/collection_operation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative 'blank'
require_relative "blank"

class DeepHashTransformer
module CollectionOperation
Expand Down
6 changes: 3 additions & 3 deletions lib/deep_hash_transformer/element_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def camel_case(val)

def dasherize(val)
stringify(val)
.tr('_', '-')
.tr("_", "-")
end

def identity(val)
Expand All @@ -34,14 +34,14 @@ def symbolize(val)

def underscore(val)
stringify(val)
.tr('-', '_')
.tr("-", "_")
end

def snake_case(val)
stringify(val)
.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr('-', '_')
.tr("-", "_")
.downcase
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/deep_hash_transformer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class DeepHashTransformer
VERSION = '2.2.0'
VERSION = "2.2.1"
end
6 changes: 3 additions & 3 deletions spec/deep_hash_transformer/blank_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

RSpec.describe DeepHashTransformer::Blank do
describe '.call' do
describe ".call" do
subject { described_class.call(value) }

presents = [true, 1, 0, 'any', [nil], { A: nil }]
blanks = [nil, false, '', ' ', [], {}]
presents = [true, 1, 0, "any", [nil], {A: nil}]
blanks = [nil, false, "", " ", [], {}]

presents.each do |value|
context "with #{value.inspect}" do
Expand Down
10 changes: 5 additions & 5 deletions spec/deep_hash_transformer/collection_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

RSpec.describe DeepHashTransformer::CollectionOperation do
examples = [
{ a: 'b' }, { a: nil }, { a: ' ' }, [:foo], ['', nil]
{a: "b"}, {a: nil}, {a: " "}, [:foo], ["", nil]
]

subject do
examples.map { |value| described_class.public_send(method, value) }
end

describe '.compact' do
describe ".compact" do
let(:method) { :compact }

expected_output = [
{ a: 'b' }, {}, { a: ' ' }, [:foo], ['']
{a: "b"}, {}, {a: " "}, [:foo], [""]
]

it { is_expected.to eq(expected_output) }
end

describe '.compact_blank' do
describe ".compact_blank" do
let(:method) { :compact_blank }

expected_output = [
{ a: 'b' }, {}, {}, [:foo], []
{a: "b"}, {}, {}, [:foo], []
]

it { is_expected.to eq(expected_output) }
Expand Down
18 changes: 9 additions & 9 deletions spec/deep_hash_transformer/element_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe DeepHashTransformer::ElementOperation do
examples = [
:symbol, 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under_scored'
:symbol, "string", "camelCase", "dashed-key", "PascalCase", "under_scored"
]

subject do
Expand All @@ -11,14 +11,14 @@

# rubocop:disable Layout/HashAlignment, Style/SymbolArray, Style/WordArray
expected_output = {
camel_case: ['symbol', 'string', 'camelCase', 'dashedKey', 'pascalCase', 'underScored'],
dasherize: ['symbol', 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under-scored'],
identity: [:symbol, 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under_scored'],
pascal_case: ['Symbol', 'String', 'CamelCase', 'DashedKey', 'PascalCase', 'UnderScored'],
snake_case: ['symbol', 'string', 'camel_case', 'dashed_key', 'pascal_case', 'under_scored'],
stringify: ['symbol', 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under_scored'],
symbolize: [:symbol, :string, :camelCase, :'dashed-key', :PascalCase, :under_scored],
underscore: ['symbol', 'string', 'camelCase', 'dashed_key', 'PascalCase', 'under_scored']
camel_case: ["symbol", "string", "camelCase", "dashedKey", "pascalCase", "underScored"],
dasherize: ["symbol", "string", "camelCase", "dashed-key", "PascalCase", "under-scored"],
identity: [:symbol, "string", "camelCase", "dashed-key", "PascalCase", "under_scored"],
pascal_case: ["Symbol", "String", "CamelCase", "DashedKey", "PascalCase", "UnderScored"],
snake_case: ["symbol", "string", "camel_case", "dashed_key", "pascal_case", "under_scored"],
stringify: ["symbol", "string", "camelCase", "dashed-key", "PascalCase", "under_scored"],
symbolize: [:symbol, :string, :camelCase, :"dashed-key", :PascalCase, :under_scored],
underscore: ["symbol", "string", "camelCase", "dashed_key", "PascalCase", "under_scored"]
}
# rubocop:enable Layout/HashAlignment, Style/SymbolArray, Style/WordArray

Expand Down
Loading

0 comments on commit 2d328a0

Please sign in to comment.