From 5aa2d374713309599503303a05eebd1ca43f35b9 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 31 Dec 2023 18:34:37 +0200 Subject: [PATCH] Disable some Rubocop rules --- .rubocop.yml | 9 ++++++++ .rubocop_gemspec.yml | 9 ++++++++ .rubocop_performance.yml | 3 +++ .rubocop_rspec.yml | 14 +++++++++++- lib/dynamoid/adapter_plugin/aws_sdk_v3.rb | 2 ++ .../adapter_plugin/aws_sdk_v3/item_updater.rb | 2 ++ lib/dynamoid/type_casting.rb | 4 ++++ spec/dynamoid/criteria/chain_spec.rb | 9 +++++--- spec/dynamoid/document_spec.rb | 2 +- spec/dynamoid/fields_spec.rb | 2 +- spec/dynamoid/indexes_spec.rb | 2 ++ spec/dynamoid/persistence_spec.rb | 22 +++++++++---------- spec/dynamoid/sti_spec.rb | 8 +++++++ spec/dynamoid/type_casting_spec.rb | 6 ++--- 14 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 .rubocop_gemspec.yml diff --git a/.rubocop.yml b/.rubocop.yml index 3dec5c25..5f3b3092 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ # We chose not to make these changes inherit_from: + - .rubocop_gemspec.yml - .rubocop_performance.yml - .rubocop_rspec.yml - .rubocop_thread_safety.yml @@ -17,6 +18,7 @@ require: AllCops: DisplayCopNames: true # Display the name of the failing cops TargetRubyVersion: 2.3 + NewCops: enable # It's a matter of taste Layout/ParameterAlignment: @@ -100,3 +102,10 @@ Naming/PredicateName: Security/YAMLLoad: Enabled: false +Lint/EmptyClass: + Exclude: + - README.md +Lint/EmptyBlock: + Exclude: + - README.md + diff --git a/.rubocop_gemspec.yml b/.rubocop_gemspec.yml new file mode 100644 index 00000000..bcdcb697 --- /dev/null +++ b/.rubocop_gemspec.yml @@ -0,0 +1,9 @@ +# specifying Ruby version would be a breaking change +# we may consider adding `required_ruby_version` in the next major release +Gemspec/RequiredRubyVersion: + Enabled: false + +# development dependencies specified in the gemspec file are shared +# by the main Gemfile and gemfiles in the gemfiles/ directory that are used on CI +Gemspec/DevelopmentDependencies: + Enabled: false diff --git a/.rubocop_performance.yml b/.rubocop_performance.yml index b65f167e..5ef13e72 100644 --- a/.rubocop_performance.yml +++ b/.rubocop_performance.yml @@ -1,3 +1,6 @@ # See: https://github.com/rubocop/rubocop-performance/issues/322 Performance/RegexpMatch: Enabled: false + +Performance/MethodObjectAsBlock: + Enabled: false diff --git a/.rubocop_rspec.yml b/.rubocop_rspec.yml index 079933da..7c1f669c 100644 --- a/.rubocop_rspec.yml +++ b/.rubocop_rspec.yml @@ -4,6 +4,9 @@ RSpec/FilePath: RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false + RSpec/NamedSubject: Enabled: false @@ -21,7 +24,7 @@ RSpec/InstanceVariable: RSpec/NestedGroups: Enabled: false - + RSpec/ExpectInHook: Enabled: false @@ -30,3 +33,12 @@ RSpec/ExpectInHook: # got # => 101.0 (0.101e3) RSpec/BeEql: Enabled: false + +RSpec/BeEq: + Enabled: false + +RSpec/StubbedMock: + Enabled: false + +RSpec/IndexedLet: + Enabled: false diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb index 8bb51ad5..65b08454 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb @@ -46,6 +46,7 @@ class AwsSdkV3 CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout].freeze # See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html + # rubocop:disable Metrics/CollectionLiteralLength RESERVED_WORDS = Set.new( %i[ ABORT ABSOLUTE ACTION ADD AFTER AGENT AGGREGATE ALL ALLOCATE ALTER ANALYZE @@ -107,6 +108,7 @@ class AwsSdkV3 WHILE WINDOW WITH WITHIN WITHOUT WORK WRAPPED WRITE YEAR ZONE ] ).freeze + # rubocop:enable Metrics/CollectionLiteralLength attr_reader :table_cache diff --git a/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb b/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb index d30a5247..b9b6a248 100644 --- a/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb +++ b/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb @@ -102,6 +102,7 @@ def attribute_updates # The only difference is that to update item we need to track whether # attribute value is nil or not. def sanitize_attributes(attributes) + # rubocop:disable Lint/DuplicateBranch attributes.transform_values do |v| if v.is_a?(Hash) v.stringify_keys @@ -113,6 +114,7 @@ def sanitize_attributes(attributes) v end end + # rubocop:enable Lint/DuplicateBranch end end end diff --git a/lib/dynamoid/type_casting.rb b/lib/dynamoid/type_casting.rb index dd11c74b..7217e274 100644 --- a/lib/dynamoid/type_casting.rb +++ b/lib/dynamoid/type_casting.rb @@ -72,6 +72,7 @@ def process(value) class IntegerTypeCaster < Base def process(value) + # rubocop:disable Lint/DuplicateBranch if value == true 1 elsif value == false @@ -85,11 +86,13 @@ def process(value) else value.to_i end + # rubocop:enable Lint/DuplicateBranch end end class NumberTypeCaster < Base def process(value) + # rubocop:disable Lint/DuplicateBranch if value == true 1 elsif value == false @@ -105,6 +108,7 @@ def process(value) else value.to_d end + # rubocop:enable Lint/DuplicateBranch end end diff --git a/spec/dynamoid/criteria/chain_spec.rb b/spec/dynamoid/criteria/chain_spec.rb index 448f39de..d611ea9f 100644 --- a/spec/dynamoid/criteria/chain_spec.rb +++ b/spec/dynamoid/criteria/chain_spec.rb @@ -1210,6 +1210,7 @@ def request_params # https://github.com/Dynamoid/dynamoid/issues/435 context 'when inheritance field (:type by default) is a GSI hash key' do it 'works without exception' do + # rubocop:disable Lint/ConstantDefinitionInBlock UserWithGSI = new_class class_name: 'UserWithGSI' do field :type @@ -1217,6 +1218,8 @@ def request_params range_key: :created_at, projected_attributes: :all end + # rubocop:enable Lint/ConstantDefinitionInBlock + obj = UserWithGSI.create actual = UserWithGSI.where(type: 'UserWithGSI').all.to_a @@ -1302,7 +1305,7 @@ def request_params object = klass_with_callback.create!(name: 'Alex') expect do - klass_with_callback.where(name: 'Alex').find_by_pages { |*| } + klass_with_callback.where(name: 'Alex').find_by_pages { |*| } # rubocop:disable Lint/EmptyBlock end.to output('run after_initialize').to_stdout end @@ -1315,7 +1318,7 @@ def request_params object = klass_with_callback.create!(name: 'Alex') expect do - klass_with_callback.where(name: 'Alex').find_by_pages { |*| } + klass_with_callback.where(name: 'Alex').find_by_pages { |*| } # rubocop:disable Lint/EmptyBlock end.to output('run after_find').to_stdout end @@ -1329,7 +1332,7 @@ def request_params object = klass_with_callback.create!(name: 'Alex') expect do - klass_with_callback.where(name: 'Alex').find_by_pages { |*| } + klass_with_callback.where(name: 'Alex').find_by_pages { |*| } # rubocop:disable Lint/EmptyBlock end.to output('run after_initializerun after_find').to_stdout end end diff --git a/spec/dynamoid/document_spec.rb b/spec/dynamoid/document_spec.rb index 5f585863..9cf992df 100644 --- a/spec/dynamoid/document_spec.rb +++ b/spec/dynamoid/document_spec.rb @@ -240,7 +240,7 @@ def city=(value) shared_examples 'it has equality testing and hashing' do it 'is equal to itself' do - expect(document).to eq document + expect(document).to eq document # rubocop:disable RSpec/IdenticalEqualityAssertion end it 'is equal to another document with the same key(s)' do diff --git a/spec/dynamoid/fields_spec.rb b/spec/dynamoid/fields_spec.rb index 29c4d01f..7ad302b8 100644 --- a/spec/dynamoid/fields_spec.rb +++ b/spec/dynamoid/fields_spec.rb @@ -129,7 +129,7 @@ def foobar_before_type_cast?; end expect(address.city).to eq 'Chicago' end - it 'declares a query attribute' do + it 'declares a query attribute' do # rubocop:disable Lint/EmptyBlock, RSpec/NoExpectationExample end it 'automatically declares id' do diff --git a/spec/dynamoid/indexes_spec.rb b/spec/dynamoid/indexes_spec.rb index d3081839..25849cfd 100644 --- a/spec/dynamoid/indexes_spec.rb +++ b/spec/dynamoid/indexes_spec.rb @@ -378,6 +378,7 @@ context 'with custom type key params' do let(:doc_class) do new_class do + # rubocop:disable Lint/ConstantDefinitionInBlock class CustomType def dynamoid_dump name @@ -387,6 +388,7 @@ def self.dynamoid_load(string) new(string.to_s) end end + # rubocop:enable Lint/ConstantDefinitionInBlock field :custom_type_field, CustomType field :custom_type_range_field, CustomType diff --git a/spec/dynamoid/persistence_spec.rb b/spec/dynamoid/persistence_spec.rb index e101c650..f1e4d6ea 100644 --- a/spec/dynamoid/persistence_spec.rb +++ b/spec/dynamoid/persistence_spec.rb @@ -868,7 +868,7 @@ def around_save_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -1336,7 +1336,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -2583,7 +2583,7 @@ def around_save_callback obj = klass_with_callbacks.new(name: 'Alex') # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -2670,7 +2670,7 @@ def around_save_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -2887,7 +2887,7 @@ def around_save_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect { obj.save }.not_to change { obj.updated_at } end @@ -3100,7 +3100,7 @@ def around_save_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect do obj.update_attribute(:title, 'Old title') @@ -3282,7 +3282,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_save', 'start around_save', 'run before_update', @@ -3395,7 +3395,7 @@ def around_update_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect do obj.update_attributes(title: 'Old title') @@ -3586,7 +3586,7 @@ def around_update_callback it 'does not change updated_at if attributes were assigned the same values' do obj = klass.create(title: 'Old title', updated_at: Time.now - 1) - obj.title = obj.title + obj.title = obj.title # rubocop:disable Lint/SelfAssignment expect do obj.update_attributes!(title: 'Old title') @@ -3758,7 +3758,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_validation', 'run after_validation', 'run before_save', @@ -4535,7 +4535,7 @@ def around_update_callback end # print each message on new line to force RSpec to show meaningful diff - expected_output = [ + expected_output = [ # rubocop:disable Style/StringConcatenation 'run before_update', 'start around_update', 'finish around_update', diff --git a/spec/dynamoid/sti_spec.rb b/spec/dynamoid/sti_spec.rb index 3220209a..77467502 100644 --- a/spec/dynamoid/sti_spec.rb +++ b/spec/dynamoid/sti_spec.rb @@ -47,6 +47,7 @@ describe 'persistence' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do field :type end @@ -65,6 +66,7 @@ def self.name 'D' end end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do @@ -125,6 +127,7 @@ def self.name describe '`inheritance_field` document option' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do table inheritance_field: :type_new @@ -137,6 +140,7 @@ def self.name 'B' end end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do @@ -163,6 +167,7 @@ def self.name describe '`sti_name` support' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do field :type @@ -178,6 +183,7 @@ def self.sti_name 'beta' end end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do @@ -194,9 +200,11 @@ def self.sti_name describe 'sti_class_for' do before do + # rubocop:disable Lint/ConstantDefinitionInBlock A = new_class class_name: 'A' do field :type end + # rubocop:enable Lint/ConstantDefinitionInBlock end after do diff --git a/spec/dynamoid/type_casting_spec.rb b/spec/dynamoid/type_casting_spec.rb index b64e3f79..38b91a82 100644 --- a/spec/dynamoid/type_casting_spec.rb +++ b/spec/dynamoid/type_casting_spec.rb @@ -445,7 +445,7 @@ end end - describe 'Raw field' do + describe 'Raw field' do # rubocop:disable Lint/EmptyBlock end describe 'Map field' do @@ -680,10 +680,10 @@ def settings.to_hash end end - describe 'Serialized field' do + describe 'Serialized field' do # rubocop:disable Lint/EmptyBlock end - describe 'Custom type field' do + describe 'Custom type field' do # rubocop:disable Lint/EmptyBlock end context 'there is no such field' do