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

Commit bee4e14

Browse files
authored
Merge pull request #1040 from rspec/upgrade-rubocop
Upgrade rubocop, motivated by CVE.
2 parents fffbfda + 267ecec commit bee4e14

File tree

12 files changed

+234
-24
lines changed

12 files changed

+234
-24
lines changed

.rubocop.yml

Lines changed: 35 additions & 1 deletion
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
# Over time we'd like to get this down, but this is what we're at now.
45
LineLength:
@@ -7,3 +8,36 @@ LineLength:
78
# We have some situations where we need to use `raise ExceptionClass.new(argument)`.
89
Style/RaiseArgs:
910
Enabled: false
11+
12+
Metrics/AbcSize:
13+
Max: 26
14+
15+
# Offense count: 2
16+
# Configuration parameters: CountComments, ExcludedMethods.
17+
Metrics/BlockLength:
18+
Max: 96
19+
20+
# Offense count: 1
21+
# Configuration parameters: CountComments.
22+
Metrics/ModuleLength:
23+
Max: 236
24+
25+
# Offense count: 4
26+
Metrics/PerceivedComplexity:
27+
Max: 14
28+
29+
AccessModifierIndentation:
30+
Exclude:
31+
- 'lib/rspec/expectations/syntax.rb' # Too much diff to fix
32+
33+
# Offense count: 6
34+
Lint/IneffectiveAccessModifier:
35+
Exclude:
36+
- 'lib/rspec/matchers.rb'
37+
- 'lib/rspec/matchers/built_in/compound.rb'
38+
- 'lib/rspec/matchers/expecteds_for_multiple_diffs.rb'
39+
- 'lib/rspec/matchers/generated_descriptions.rb'
40+
41+
Lint/InheritException:
42+
Exclude:
43+
- 'lib/rspec/expectations.rb'

.rubocop_rspec_base.yml

Lines changed: 189 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# can customize by inheriting this file and overriding particular settings.
66

77
AccessModifierIndentation:
8-
EnforcedStyle: outdent
8+
Enabled: false
99

1010
# "Use alias_method instead of alias"
1111
# We're fine with `alias`.
@@ -50,9 +50,6 @@ DoubleNegation:
5050
EachWithObject:
5151
Enabled: false
5252

53-
Encoding:
54-
EnforcedStyle: when_needed
55-
5653
FormatString:
5754
EnforcedStyle: percent
5855

@@ -73,7 +70,7 @@ MethodLength:
7370
Max: 15
7471

7572
# Who cares what we call the argument for binary operator methods?
76-
OpMethod:
73+
BinaryOperatorParameterName:
7774
Enabled: false
7875

7976
PercentLiteralDelimiters:
@@ -98,9 +95,6 @@ PredicateName:
9895
Proc:
9996
Enabled: false
10097

101-
RedundantReturn:
102-
AllowMultipleReturnValues: true
103-
10498
# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
10599
RescueException:
106100
Enabled: true
@@ -121,10 +115,196 @@ StringLiterals:
121115
Style/SpecialGlobalVars:
122116
Enabled: false
123117

124-
Style/TrailingComma:
118+
Style/TrailingCommaInLiteral:
119+
Enabled: false
120+
121+
Style/TrailingCommaInArguments:
125122
Enabled: false
126123

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

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ platforms :rbx do
3939
gem 'rubysl'
4040
end
4141

42-
if RUBY_VERSION >= '2' && RUBY_VERSION <= '2.1'
43-
# todo upgrade rubocop and run on a recent version e.g. 2.3 or 2.4
44-
gem 'rubocop', "~> 0.23.0"
42+
if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby'
43+
gem 'rubocop', "~> 0.52.1"
4544
end
4645

4746
eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')

lib/rspec/expectations/block_snippet_extractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module RSpec
22
module Expectations
33
# @private
4-
class BlockSnippetExtractor # rubocop:disable Style/ClassLength
4+
class BlockSnippetExtractor # rubocop:disable Metrics/ClassLength
55
# rubocop should properly handle `Struct.new {}` as an inner class definition.
66

77
attr_reader :proc, :method_name

lib/rspec/matchers/built_in/compound.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module Matchers
33
module BuiltIn
44
# @api private
55
# Base class for `and` and `or` compound matchers.
6-
# rubocop:disable ClassLength
76
class Compound < BaseMatcher
87
# @private
98
attr_reader :matcher_1, :matcher_2, :evaluator

lib/rspec/matchers/built_in/contain_exactly.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def convert_actual_to_an_array
8989
elsif actual.respond_to?(:to_a) && !to_a_disallowed?(actual)
9090
@actual = actual.to_a
9191
else
92-
return false
92+
false
9393
end
9494
end
9595

lib/rspec/matchers/built_in/has.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def predicate
7777
end
7878

7979
def method_description
80-
@method_name.to_s.gsub('_', ' ')
80+
@method_name.to_s.tr('_', ' ')
8181
end
8282

8383
def args_description

lib/rspec/matchers/built_in/respond_to.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def with_keywords_string
151151
@expected_keywords.map(&:inspect).join(' and ')
152152
else
153153
"#{@expected_keywords[0...-1].map(&:inspect).join(', ')}, and #{@expected_keywords.last.inspect}"
154-
end
154+
end
155155

156156
"keyword#{@expected_keywords.count == 1 ? '' : 's'} #{kw_str}"
157157
end

lib/rspec/matchers/built_in/satisfy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def failure_message_when_negated
3434
"expected #{actual_formatted} not to #{description}"
3535
end
3636

37-
private # rubocop:disable Lint/UselessAccessModifier
37+
private
3838

3939
if RSpec::Support::RubyFeatures.ripper_supported?
4040
def block_representation

lib/rspec/matchers/english_phrasing.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def self.list(obj)
4444
# So it appears that `Array` can trigger that (e.g. by calling `to_a` on the passed object?)
4545
# So here we replace `Kernel#Array` with our own warning-free implementation for 1.8.7.
4646
# @private
47-
# rubocop:disable Style/MethodName
47+
# rubocop:disable Naming/MethodName
4848
def self.Array(obj)
4949
case obj
5050
when Array then obj
5151
else [obj]
5252
end
5353
end
54-
# rubocop:enable Style/MethodName
54+
# rubocop:enable Naming/MethodName
5555
end
5656
end
5757
end

lib/rspec/matchers/generated_descriptions.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def self.generated_description
2121
"#{last_expectation_handler.verb} #{last_description}"
2222
end
2323

24-
private
25-
2624
# @private
2725
def self.last_description
2826
last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE

script/functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function check_documentation_coverage {
180180

181181
function check_style_and_lint {
182182
echo "bin/rubocop lib"
183-
bin/rubocop lib
183+
eval "(unset RUBYOPT; exec bin/rubocop lib)"
184184
}
185185

186186
function run_all_spec_suites {

0 commit comments

Comments
 (0)