Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit b48d851

Browse files
authored
Merge pull request #2498 from rspec/upgrade-rubocop
Upgrade rubocop, motivated by CVE.
2 parents c4d3073 + 1f8e831 commit b48d851

14 files changed

+262
-77
lines changed

.rubocop.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
inherit_from: .rubocop_rspec_base.yml
1+
inherit_from:
2+
- .rubocop_rspec_base.yml
23

34
AllCops:
45
Exclude:
@@ -10,7 +11,6 @@ Metrics/ClassLength:
1011
Max: 330
1112

1213
Encoding:
13-
EnforcedStyle: when_needed
1414
Exclude:
1515
- lib/rspec/core/formatters/exception_presenter.rb
1616

@@ -53,23 +53,17 @@ Style/StringLiteralsInInterpolation:
5353
Style/SymbolProc:
5454
Enabled: false
5555

56-
Style/SpaceAroundOperators:
57-
MultiSpaceAllowedForOperators:
58-
- '='
59-
- '||='
60-
- '==='
61-
- '=>'
62-
- '<<'
63-
- '||'
56+
Layout/SpaceAroundOperators:
57+
AllowForAlignment: true
6458

65-
Style/AccessModifierIndentation:
59+
Layout/AccessModifierIndentation:
6660
Enabled: false
6761

6862
Style/RegexpLiteral:
6963
Enabled: false
7064

7165
# This could change depending of the style used
72-
Style/MultilineOperationIndentation:
66+
Layout/MultilineOperationIndentation:
7367
Enabled: false
7468

7569
Style/BarePercentLiterals:
@@ -95,3 +89,22 @@ Style/RaiseArgs:
9589
- lib/rspec/core/hooks.rb
9690
- lib/rspec/core/option_parser.rb
9791
- lib/rspec/core/pending.rb
92+
93+
Performance/RedundantBlockCall:
94+
Exclude:
95+
- lib/rspec/core/rake_task.rb
96+
97+
Lint/IneffectiveAccessModifier:
98+
Exclude:
99+
- lib/rspec/core/memoized_helpers.rb # Fixing this file was too much of a diff
100+
101+
Performance/Caller:
102+
Exclude:
103+
# The suggested fix for this cop only works on more recent rubies. The
104+
# speed up can be substantial (previous optimization work I've done on
105+
# RSpec involved caller optimization) but I haven't benchmarked this
106+
# particular case to see if it's worth introducing version branching.
107+
- 'lib/rspec/core/example_group.rb'
108+
109+
Metrics/BlockLength:
110+
Max: 193

.rubocop_rspec_base.yml

Lines changed: 189 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# This file was generated on 2018-01-02T08:14:15-08:00 from the rspec-dev repo.
2-
# DO NOT modify it by hand as your changes will get lost the next time it is generated.
3-
41
# This file contains defaults for RSpec projects. Individual projects
52
# can customize by inheriting this file and overriding particular settings.
63

74
AccessModifierIndentation:
8-
EnforcedStyle: outdent
5+
Enabled: false
96

107
# "Use alias_method instead of alias"
118
# We're fine with `alias`.
@@ -50,9 +47,6 @@ DoubleNegation:
5047
EachWithObject:
5148
Enabled: false
5249

53-
Encoding:
54-
EnforcedStyle: when_needed
55-
5650
FormatString:
5751
EnforcedStyle: percent
5852

@@ -73,7 +67,7 @@ MethodLength:
7367
Max: 15
7468

7569
# Who cares what we call the argument for binary operator methods?
76-
OpMethod:
70+
BinaryOperatorParameterName:
7771
Enabled: false
7872

7973
PercentLiteralDelimiters:
@@ -98,9 +92,6 @@ PredicateName:
9892
Proc:
9993
Enabled: false
10094

101-
RedundantReturn:
102-
AllowMultipleReturnValues: true
103-
10495
# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
10596
RescueException:
10697
Enabled: true
@@ -121,10 +112,196 @@ StringLiterals:
121112
Style/SpecialGlobalVars:
122113
Enabled: false
123114

124-
Style/TrailingComma:
115+
Style/TrailingCommaInLiteral:
116+
Enabled: false
117+
118+
Style/TrailingCommaInArguments:
125119
Enabled: false
126120

127121
TrivialAccessors:
128122
AllowDSLWriters: true
129123
AllowPredicates: true
130124
ExactNameMatch: true
125+
126+
Style/ParallelAssignment:
127+
Enabled: false
128+
129+
Layout/EmptyLineBetweenDefs:
130+
Enabled: false
131+
132+
Layout/FirstParameterIndentation:
133+
Enabled: false
134+
135+
Naming/ConstantName:
136+
Enabled: false
137+
138+
Style/ClassCheck:
139+
Enabled: false
140+
141+
Style/ConditionalAssignment:
142+
Enabled: false
143+
144+
Style/EmptyMethod:
145+
Enabled: false
146+
147+
Style/FormatStringToken:
148+
Enabled: false
149+
150+
Style/GuardClause:
151+
Enabled: false
152+
153+
Style/IdenticalConditionalBranches:
154+
Enabled: false
155+
156+
Style/IfUnlessModifier:
157+
Enabled: false
158+
159+
Style/IfUnlessModifierOfIfUnless:
160+
Enabled: false
161+
162+
Style/MethodMissing:
163+
Enabled: false
164+
165+
Style/MixinUsage:
166+
Enabled: false
167+
168+
Style/MultipleComparison:
169+
Enabled: false
170+
171+
Style/MutableConstant:
172+
Enabled: false
173+
174+
Style/NestedModifier:
175+
Enabled: false
176+
177+
Style/NestedParenthesizedCalls:
178+
Enabled: false
179+
180+
Style/NumericPredicate:
181+
Enabled: false
182+
183+
Style/RedundantParentheses:
184+
Enabled: false
185+
186+
Style/StringLiteralsInInterpolation:
187+
Enabled: false
188+
189+
Style/SymbolArray:
190+
Enabled: false
191+
192+
Style/SymbolProc:
193+
Enabled: false
194+
195+
Style/YodaCondition:
196+
Enabled: false
197+
198+
Style/ZeroLengthPredicate:
199+
Enabled: false
200+
201+
Layout/ClosingParenthesisIndentation:
202+
Enabled: false
203+
204+
Layout/ExtraSpacing:
205+
Enabled: false
206+
207+
Layout/MultilineMethodCallBraceLayout:
208+
Enabled: false
209+
210+
Layout/MultilineMethodCallIndentation:
211+
Enabled: false
212+
213+
Layout/MultilineOperationIndentation:
214+
Enabled: false
215+
216+
Layout/SpaceAroundBlockParameters:
217+
Enabled: false
218+
219+
Layout/SpaceAroundOperators:
220+
Enabled: false
221+
222+
Layout/SpaceBeforeComma:
223+
Enabled: false
224+
225+
Style/BlockDelimiters:
226+
Enabled: false
227+
228+
Style/EmptyCaseCondition:
229+
Enabled: false
230+
231+
Style/MultilineIfModifier:
232+
Enabled: false
233+
234+
Style/RescueStandardError:
235+
Enabled: false
236+
237+
Style/StderrPuts:
238+
Enabled: false
239+
240+
Style/TernaryParentheses:
241+
Enabled: false
242+
243+
# This could likely be enabled, but it had a false positive on rspec-mocks
244+
# (suggested change was not behaviour preserving) so I don't trust it.
245+
Performance/HashEachMethods:
246+
Enabled: false
247+
248+
Naming/HeredocDelimiterNaming:
249+
Enabled: false
250+
251+
Layout/EmptyLineAfterMagicComment:
252+
Enabled: false
253+
254+
Layout/IndentArray:
255+
Enabled: false
256+
257+
Layout/IndentAssignment:
258+
Enabled: false
259+
260+
Layout/IndentHeredoc:
261+
Enabled: false
262+
263+
Layout/SpaceInsidePercentLiteralDelimiters:
264+
Enabled: false
265+
266+
Style/EmptyElse:
267+
Enabled: false
268+
269+
Style/IfInsideElse:
270+
Enabled: false
271+
272+
Style/RedundantReturn:
273+
Enabled: false
274+
275+
Style/StructInheritance:
276+
Enabled: false
277+
278+
Naming/VariableNumber:
279+
Enabled: false
280+
281+
Layout/SpaceInsideStringInterpolation:
282+
Enabled: false
283+
284+
Style/DateTime:
285+
Enabled: false
286+
287+
Style/ParenthesesAroundCondition:
288+
Enabled: false
289+
290+
Layout/EmptyLinesAroundBlockBody:
291+
Enabled: false
292+
293+
Lint/ImplicitStringConcatenation:
294+
Enabled: false
295+
296+
Lint/NestedMethodDefinition:
297+
Enabled: false
298+
299+
Style/RegexpLiteral:
300+
Enabled: false
301+
302+
Style/TrailingUnderscoreVariable:
303+
Enabled: false
304+
305+
Layout/EmptyLinesAroundAccessModifier:
306+
Enabled: false
307+

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ end
4242

4343
gem 'simplecov', '~> 0.8'
4444

45-
if RUBY_VERSION >= '1.9.3' && RUBY_VERSION < '2.4.0' && !(%w[java jruby].include? RUBY_ENGINE)
46-
gem "rubocop", "~> 0.32.1"
45+
# No need to run rubocop on earlier versions
46+
if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby'
47+
gem "rubocop", "~> 0.52.1"
4748
end
4849

4950
gem 'test-unit', '~> 3.0' if RUBY_VERSION.to_f >= 2.2

lib/rspec/core/bisect/runner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def command_for(locations)
2929
parts << "--format" << "bisect"
3030
parts << "--drb-port" << @server.drb_port
3131

32-
parts.concat reusable_cli_options
33-
parts.concat locations.map { |l| open3_safe_escape(l) }
32+
parts.concat(reusable_cli_options)
33+
parts.concat(locations.map { |l| open3_safe_escape(l) })
3434

3535
parts.join(" ")
3636
end

lib/rspec/core/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ def define_derived_metadata(*filters, &block)
17711771
# require 'support/db'
17721772
# end
17731773
# end
1774-
def when_first_matching_example_defined(*filters, &block)
1774+
def when_first_matching_example_defined(*filters)
17751775
specified_meta = Metadata.build_hash_from(filters, :warn_about_example_group_filtering)
17761776

17771777
callback = lambda do |example_or_group_meta|
@@ -1782,7 +1782,7 @@ def when_first_matching_example_defined(*filters, &block)
17821782
# Ensure the callback only fires once.
17831783
@derived_metadata_blocks.delete(callback, specified_meta)
17841784

1785-
block.call
1785+
yield
17861786
end
17871787

17881788
@derived_metadata_blocks.append(callback, specified_meta)

lib/rspec/core/example.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def display_exception=(ex)
393393
end
394394
end
395395

396-
# rubocop:disable Style/AccessorMethodName
396+
# rubocop:disable Naming/AccessorMethodName
397397

398398
# @private
399399
#
@@ -420,7 +420,7 @@ def set_aggregate_failures_exception(exception)
420420
self.display_exception = exception
421421
end
422422

423-
# rubocop:enable Style/AccessorMethodName
423+
# rubocop:enable Naming/AccessorMethodName
424424

425425
# @private
426426
#
@@ -642,12 +642,12 @@ def initialize(hook_description, reporter)
642642
@reporter = reporter
643643
end
644644

645-
# rubocop:disable Style/AccessorMethodName
645+
# rubocop:disable Naming/AccessorMethodName
646646
def set_exception(exception)
647647
reporter.notify_non_example_exception(exception, "An error occurred in #{description}.")
648648
RSpec.world.wants_to_quit = true
649649
end
650-
# rubocop:enable Style/AccessorMethodName
650+
# rubocop:enable Naming/AccessorMethodName
651651
end
652652
end
653653
end

lib/rspec/core/formatters/deprecation_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def too_many_warnings_message
8181

8282
def output_formatted(str)
8383
return str unless str.lines.count > 1
84-
separator = "#{'-' * 80}"
84+
separator = '-' * 80
8585
"#{separator}\n#{str.chomp}\n#{separator}"
8686
end
8787

0 commit comments

Comments
 (0)