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

Commit fd1ff3b

Browse files
authored
Merge pull request #338 from rspec/upgrade-rubocop
Upgrade rubocop, motivated by CVE.
2 parents 2173113 + 1d3f76a commit fd1ff3b

File tree

6 files changed

+222
-22
lines changed

6 files changed

+222
-22
lines changed

.rubocop.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
1-
inherit_from: .rubocop_rspec_base.yml
1+
inherit_from:
2+
- .rubocop_rspec_base.yml
3+
4+
Metrics/AbcSize:
5+
Max: 28
6+
7+
Metrics/BlockLength:
8+
Max: 86
9+
10+
Metrics/PerceivedComplexity:
11+
Max: 10
12+
13+
Security/MarshalLoad:
14+
Exclude:
15+
- 'lib/rspec/support/spec/in_sub_process.rb'
16+
17+
Style/EvalWithLocation:
18+
Exclude:
19+
# eval is only used here to check syntax
20+
- 'lib/rspec/support/ruby_features.rb'
21+
22+
Lint/AssignmentInCondition:
23+
Exclude:
24+
# The pattern makes sense here
25+
- 'lib/rspec/support/mutex.rb'

.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 2017-12-30T17:04:25-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
@@ -24,8 +24,9 @@ if RUBY_VERSION < '2.0.0' && !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|min
2424
gem 'ffi', '< 1.9.15' # allow ffi to be installed on older rubies on windows
2525
end
2626

27-
if RUBY_VERSION >= '2.0' && RUBY_VERSION <= '2.1'
28-
gem 'rubocop', "~> 0.23.0"
27+
# No need to run rubocop on earlier versions
28+
if RUBY_VERSION >= '2.4' && RUBY_ENGINE == 'ruby'
29+
gem "rubocop", "~> 0.52.1"
2930
end
3031

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

lib/rspec/support/object_formatter.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Support
55
# Provide additional output details beyond what `inspect` provides when
66
# printing Time, DateTime, or BigDecimal
77
# @api private
8-
class ObjectFormatter # rubocop:disable Style/ClassLength
8+
class ObjectFormatter # rubocop:disable Metrics/ClassLength
99
ELLIPSIS = "..."
1010

1111
attr_accessor :max_formatted_output_length
@@ -31,15 +31,15 @@ def initialize(max_formatted_output_length=200)
3131

3232
def format(object)
3333
if max_formatted_output_length.nil?
34-
return prepare_for_inspection(object).inspect
34+
prepare_for_inspection(object).inspect
3535
else
3636
formatted_object = prepare_for_inspection(object).inspect
3737
if formatted_object.length < max_formatted_output_length
38-
return formatted_object
38+
formatted_object
3939
else
4040
beginning = truncate_string formatted_object, 0, max_formatted_output_length / 2
4141
ending = truncate_string formatted_object, -max_formatted_output_length / 2, -1
42-
return beginning + ELLIPSIS + ending
42+
beginning + ELLIPSIS + ending
4343
end
4444
end
4545
end

lib/rspec/support/ruby_features.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def supports_rebinding_module_methods?
109109
end
110110
else
111111
# RBX / JRuby et al support is unknown for keyword arguments
112-
# rubocop:disable Lint/Eval
113112
begin
114113
eval("o = Object.new; def o.m(a: 1); end;"\
115114
" raise SyntaxError unless o.method(:m).parameters.include?([:key, :a])")
@@ -147,7 +146,6 @@ def supports_rebinding_module_methods?
147146
false
148147
end
149148
end
150-
# rubocop:enable Lint/Eval
151149
end
152150

153151
def module_refinement_supported?

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)