Skip to content

Commit

Permalink
Disable some Rubocop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Dec 31, 2023
1 parent 3422a9e commit 5aa2d37
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -100,3 +102,10 @@ Naming/PredicateName:
Security/YAMLLoad:
Enabled: false

Lint/EmptyClass:
Exclude:
- README.md
Lint/EmptyBlock:
Exclude:
- README.md

9 changes: 9 additions & 0 deletions .rubocop_gemspec.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .rubocop_performance.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# See: https://github.com/rubocop/rubocop-performance/issues/322
Performance/RegexpMatch:
Enabled: false

Performance/MethodObjectAsBlock:
Enabled: false
14 changes: 13 additions & 1 deletion .rubocop_rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ RSpec/FilePath:
RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NamedSubject:
Enabled: false

Expand All @@ -21,7 +24,7 @@ RSpec/InstanceVariable:

RSpec/NestedGroups:
Enabled: false

RSpec/ExpectInHook:
Enabled: false

Expand All @@ -30,3 +33,12 @@ RSpec/ExpectInHook:
# got #<BigDecimal:...> => 101.0 (0.101e3)
RSpec/BeEql:
Enabled: false

RSpec/BeEq:
Enabled: false

RSpec/StubbedMock:
Enabled: false

RSpec/IndexedLet:
Enabled: false
2 changes: 2 additions & 0 deletions lib/dynamoid/adapter_plugin/aws_sdk_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -113,6 +114,7 @@ def sanitize_attributes(attributes)
v
end
end
# rubocop:enable Lint/DuplicateBranch
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/dynamoid/type_casting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def process(value)

class IntegerTypeCaster < Base
def process(value)
# rubocop:disable Lint/DuplicateBranch
if value == true
1
elsif value == false
Expand All @@ -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
Expand All @@ -105,6 +108,7 @@ def process(value)
else
value.to_d
end
# rubocop:enable Lint/DuplicateBranch
end
end

Expand Down
9 changes: 6 additions & 3 deletions spec/dynamoid/criteria/chain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1210,13 +1210,16 @@ 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

global_secondary_index hash_key: :type,
range_key: :created_at,
projected_attributes: :all
end
# rubocop:enable Lint/ConstantDefinitionInBlock

obj = UserWithGSI.create

actual = UserWithGSI.where(type: 'UserWithGSI').all.to_a
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/dynamoid/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/dynamoid/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/dynamoid/indexes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions spec/dynamoid/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions spec/dynamoid/sti_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

describe 'persistence' do
before do
# rubocop:disable Lint/ConstantDefinitionInBlock
A = new_class class_name: 'A' do
field :type
end
Expand All @@ -65,6 +66,7 @@ def self.name
'D'
end
end
# rubocop:enable Lint/ConstantDefinitionInBlock
end

after do
Expand Down Expand Up @@ -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

Expand All @@ -137,6 +140,7 @@ def self.name
'B'
end
end
# rubocop:enable Lint/ConstantDefinitionInBlock
end

after do
Expand All @@ -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

Expand All @@ -178,6 +183,7 @@ def self.sti_name
'beta'
end
end
# rubocop:enable Lint/ConstantDefinitionInBlock
end

after do
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/dynamoid/type_casting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
end
end

describe 'Raw field' do
describe 'Raw field' do # rubocop:disable Lint/EmptyBlock
end

describe 'Map field' do
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5aa2d37

Please sign in to comment.