Skip to content

Commit b455477

Browse files
authored
Some maintainance tasks. (#339)
- updates rubocop and make it happy
1 parent 13e80ba commit b455477

File tree

10 files changed

+40
-77
lines changed

10 files changed

+40
-77
lines changed

.rubocop.yml

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ AllCops:
55
- vendor/**/*
66
- example/**/*
77
TargetRubyVersion: 2.7
8+
UseCache: true
9+
NewCops: enable
810

911
# Layout stuff
1012
#
@@ -27,25 +29,18 @@ Layout/SpaceAroundMethodCallOperator:
2729

2830
# Lint stuff
2931
#
30-
Lint/DeprecatedOpenSSLConstant:
31-
Enabled: true
32-
33-
Lint/DuplicateElsifCondition:
34-
Enabled: true
35-
36-
Lint/MixedRegexpCaptureTypes:
37-
Enabled: true
38-
39-
Lint/RaiseException:
40-
Enabled: true
41-
42-
Lint/StructNewOverride:
32+
Lint/ConstantDefinitionInBlock:
4333
Enabled: true
34+
Exclude:
35+
- spec/**/*
4436

4537
# Metrics stuff
4638
#
4739
Metrics/AbcSize:
4840
Max: 25
41+
IgnoredMethods:
42+
# from lib/grape_entity/exposure/nesting_exposure.rb
43+
- 'normalized_exposures'
4944

5045
Metrics/BlockLength:
5146
Exclude:
@@ -64,6 +59,12 @@ Metrics/MethodLength:
6459

6560
Metrics/PerceivedComplexity:
6661
Max: 11
62+
IgnoredMethods:
63+
# from lib/grape_entity/entity.rb
64+
- 'expose'
65+
- 'merge_options'
66+
# from lib/grape_entity/exposure/nesting_exposure.rb
67+
- 'normalized_exposures'
6768

6869
# Naming stuff
6970
#
@@ -73,56 +74,13 @@ Naming:
7374

7475
# Style stuff
7576
#
76-
Style/AccessorGrouping:
77-
Enabled: true
78-
79-
Style/ArrayCoercion:
80-
Enabled: true
81-
82-
Style/BisectedAttrAccessor:
83-
Enabled: true
84-
85-
Style/CaseLikeIf:
86-
Enabled: true
87-
8877
Style/Documentation:
8978
Enabled: false
9079

91-
Style/ExponentialNotation:
92-
Enabled: true
93-
94-
Style/HashAsLastArrayItem:
95-
Enabled: true
96-
97-
Style/HashEachMethods:
98-
Enabled: true
99-
100-
Style/HashLikeCase:
101-
Enabled: true
102-
103-
Style/HashTransformKeys:
104-
Enabled: true
105-
106-
Style/HashTransformValues:
107-
Enabled: true
108-
109-
Style/RedundantAssignment:
110-
Enabled: true
111-
112-
Style/RedundantFetchBlock:
113-
Enabled: true
114-
115-
Style/RedundantFileExtensionInRequire:
116-
Enabled: true
117-
118-
Style/RedundantRegexpCharacterClass:
119-
Enabled: true
120-
121-
Style/RedundantRegexpEscape:
122-
Enabled: true
123-
124-
Style/RegexpLiteral:
125-
Enabled: false
126-
127-
Style/SlicingWithRange:
128-
Enabled: true
80+
Style/OptionalBooleanParameter:
81+
AllowedMethods:
82+
# from lib/grape_entity/condition/base.rb
83+
- 'initialize'
84+
# form lib/grape_entity/entity.rb
85+
- 'entity_class'
86+
- 'present_collection'

.rubocop_todo.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-02-18 16:38:42 +0100 using RuboCop version 0.79.0.
3+
# on 2020-11-07 00:01:40 UTC using RuboCop version 1.2.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -14,17 +14,11 @@ Gemspec/RequiredRubyVersion:
1414
- 'grape-entity.gemspec'
1515

1616
# Offense count: 6
17+
# Cop supports --auto-correct.
1718
Lint/BooleanSymbol:
1819
Exclude:
1920
- 'spec/grape_entity/exposure_spec.rb'
2021

21-
# Offense count: 1
22-
# Configuration parameters: EnforcedStyle.
23-
# SupportedStyles: inline, group
24-
Style/AccessModifierDeclarations:
25-
Exclude:
26-
- 'spec/grape_entity/entity_spec.rb'
27-
2822
# Offense count: 1
2923
# Cop supports --auto-correct.
3024
# Configuration parameters: IgnoredMethods.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source 'http://rubygems.org'
55
gemspec
66

77
group :development, :test do
8-
gem 'rubocop', '~> 0.88.0', require: false
8+
gem 'rubocop', '~> 1.0', require: false
99
end
1010

1111
group :test do

lib/grape_entity/condition/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def inversed?
2121
end
2222

2323
def met?(entity, options)
24-
!@inverse ? if_value(entity, options) : unless_value(entity, options)
24+
@inverse ? unless_value(entity, options) : if_value(entity, options)
2525
end
2626

2727
def if_value(_entity, _options)

lib/grape_entity/entity.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def delegation_opts
139139
def self.inherited(subclass)
140140
subclass.root_exposure = root_exposure.dup
141141
subclass.formatters = formatters.dup
142+
143+
super
142144
end
143145

144146
# This method is the primary means by which you will declare what attributes

lib/grape_entity/exposure/base.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ def key(entity = nil)
113113
@key.respond_to?(:call) ? entity.exec_with_object(@options, &@key) : @key
114114
end
115115

116-
def with_attr_path(entity, options)
116+
def with_attr_path(entity, options, &block)
117117
path_part = attr_path(entity, options)
118-
options.with_attr_path(path_part) do
119-
yield
120-
end
118+
options.with_attr_path(path_part, &block)
121119
end
122120

123121
def override?

lib/grape_entity/exposure/nesting_exposure.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def normalized_exposures(entity, options)
9191
output[exposure.key(entity)] ||= []
9292
output[exposure.key(entity)] << exposure
9393
end
94+
9495
table.map do |key, exposures|
9596
last_exposure = exposures.last
9697

lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def clear
3636
@exposures.clear
3737
end
3838

39+
# rubocop:disable Style/DocumentDynamicEvalDefinition
3940
%i[
4041
each
4142
to_ary to_a
@@ -55,6 +56,7 @@ def #{name}(*args, &block)
5556
end
5657
RUBY
5758
end
59+
# rubocop:enable Style/DocumentDynamicEvalDefinition
5860

5961
# Determine if we have any nesting exposures with the same name.
6062
def deep_complex_nesting?(entity)

lib/grape_entity/exposure/nesting_exposure/output_builder.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def initialize(entity)
99
@entity = entity
1010
@output_hash = {}
1111
@output_collection = []
12+
13+
super
1214
end
1315

1416
def add(exposure, result)
@@ -49,6 +51,7 @@ def output
4951
output
5052
end
5153

54+
# rubocop:disable Lint/EmptyBlock
5255
# In case if we want to solve collisions providing lambda to :merge option
5356
def merge_strategy(for_merge)
5457
if for_merge.respond_to? :call
@@ -57,6 +60,7 @@ def merge_strategy(for_merge)
5760
-> {}
5861
end
5962
end
63+
# rubocop:enable Lint/EmptyBlock
6064
end
6165
end
6266
end

spec/grape_entity/entity_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
it 'makes sure that :format_with as a proc cannot be used with a block' do
3232
# rubocop:disable Style/BlockDelimiters
33+
# rubocop:disable Lint/EmptyBlock
3334
expect { subject.expose :name, format_with: proc {} do p 'hi' end }.to raise_error ArgumentError
35+
# rubocop:enable Lint/EmptyBlock
3436
# rubocop:enable Style/BlockDelimiters
3537
end
3638

@@ -1693,10 +1695,12 @@ class FriendEntity < Grape::Entity
16931695
end
16941696
end
16951697

1698+
# rubocop:disable Lint/EmptyBlock
16961699
fresh_class.class_eval do
16971700
expose :first_friend, using: EntitySpec::FriendEntity do |_user, _opts|
16981701
end
16991702
end
1703+
# rubocop:enable Lint/EmptyBlock
17001704

17011705
rep = subject.value_for(:first_friend)
17021706
expect(rep).to be_kind_of EntitySpec::FriendEntity

0 commit comments

Comments
 (0)