Skip to content

Commit c6988a8

Browse files
authored
Modernize RuboCop configuration and fix offenses (#1660)
- migrate from `require` to `plugins` - remove explicit new cops in favour of `NewCops: enable` - remove version boundaries from `rubocop-packaging` and `rubocop-performance` gems - add and enable `rubocop-rake` gem - auto-correct (safe only) a bunch of offenses - manually correct "useless private scoping of constant" offences - regen `.rubocop_todo.yml` to add remaining few complex offences
1 parent 32e010f commit c6988a8

File tree

18 files changed

+68
-206
lines changed

18 files changed

+68
-206
lines changed

.rubocop.yml

Lines changed: 3 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
inherit_from: .rubocop_todo.yml
22

3-
require:
3+
plugins:
44
- rubocop-packaging
55
- rubocop-performance
6+
- rubocop-rake
67

78
AllCops:
89
DisplayCopNames: true
910
DisplayStyleGuide: true
1011
TargetRubyVersion: 3.0
12+
NewCops: enable
1113

1214
# Custom config
1315
Gemspec/RequireMFA: # we don't know if this works with auto-deployments yet
@@ -32,169 +34,3 @@ Style/DoubleNegation:
3234
Enabled: false
3335
Style/IfUnlessModifier:
3436
Enabled: false
35-
36-
# New cops
37-
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
38-
Enabled: true
39-
Layout/LineContinuationLeadingSpace: # new in 1.31
40-
Enabled: true
41-
Layout/LineContinuationSpacing: # new in 1.31
42-
Enabled: true
43-
Layout/LineEndStringConcatenationIndentation: # new in 1.18
44-
Enabled: true
45-
Layout/SpaceBeforeBrackets: # new in 1.7
46-
Enabled: true
47-
Lint/AmbiguousAssignment: # new in 1.7
48-
Enabled: true
49-
Lint/AmbiguousOperatorPrecedence: # new in 1.21
50-
Enabled: true
51-
Lint/AmbiguousRange: # new in 1.19
52-
Enabled: true
53-
Lint/ConstantOverwrittenInRescue: # new in 1.31
54-
Enabled: true
55-
Lint/DeprecatedConstants: # new in 1.8
56-
Enabled: true
57-
Lint/DuplicateBranch: # new in 1.3
58-
Enabled: true
59-
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
60-
Enabled: true
61-
Lint/EmptyBlock: # new in 1.1
62-
Enabled: true
63-
Lint/EmptyClass: # new in 1.3
64-
Enabled: true
65-
Lint/EmptyInPattern: # new in 1.16
66-
Enabled: true
67-
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
68-
Enabled: true
69-
Lint/LambdaWithoutLiteralBlock: # new in 1.8
70-
Enabled: true
71-
Lint/NoReturnInBeginEndBlocks: # new in 1.2
72-
Enabled: true
73-
Lint/NonAtomicFileOperation: # new in 1.31
74-
Enabled: true
75-
Lint/NumberedParameterAssignment: # new in 1.9
76-
Enabled: true
77-
Lint/OrAssignmentToConstant: # new in 1.9
78-
Enabled: true
79-
Lint/RedundantDirGlobSort: # new in 1.8
80-
Enabled: true
81-
Lint/RefinementImportMethods: # new in 1.27
82-
Enabled: true
83-
Lint/RequireRangeParentheses: # new in 1.32
84-
Enabled: true
85-
Lint/RequireRelativeSelfPath: # new in 1.22
86-
Enabled: true
87-
Lint/SymbolConversion: # new in 1.9
88-
Enabled: true
89-
Lint/ToEnumArguments: # new in 1.1
90-
Enabled: true
91-
Lint/TripleQuotes: # new in 1.9
92-
Enabled: true
93-
Lint/UnexpectedBlockArity: # new in 1.5
94-
Enabled: true
95-
Lint/UnmodifiedReduceAccumulator: # new in 1.1
96-
Enabled: true
97-
Lint/UselessRuby2Keywords: # new in 1.23
98-
Enabled: true
99-
Naming/BlockForwarding: # new in 1.24
100-
Enabled: true
101-
Security/CompoundHash: # new in 1.28
102-
Enabled: true
103-
Security/IoMethods: # new in 1.22
104-
Enabled: true
105-
Style/ArgumentsForwarding: # new in 1.1
106-
Enabled: true
107-
Style/CollectionCompact: # new in 1.2
108-
Enabled: true
109-
Style/DocumentDynamicEvalDefinition: # new in 1.1
110-
Enabled: true
111-
Style/EmptyHeredoc: # new in 1.32
112-
Enabled: true
113-
Style/EndlessMethod: # new in 1.8
114-
Enabled: true
115-
Style/EnvHome: # new in 1.29
116-
Enabled: true
117-
Style/FetchEnvVar: # new in 1.28
118-
Enabled: true
119-
Style/FileRead: # new in 1.24
120-
Enabled: true
121-
Style/FileWrite: # new in 1.24
122-
Enabled: true
123-
Style/HashConversion: # new in 1.10
124-
Enabled: true
125-
Style/HashExcept: # new in 1.7
126-
Enabled: true
127-
Style/IfWithBooleanLiteralBranches: # new in 1.9
128-
Enabled: true
129-
Style/InPatternThen: # new in 1.16
130-
Enabled: true
131-
Style/MapCompactWithConditionalBlock: # new in 1.30
132-
Enabled: true
133-
Style/MapToHash: # new in 1.24
134-
Enabled: true
135-
Style/MultilineInPatternThen: # new in 1.16
136-
Enabled: true
137-
Style/NegatedIfElseCondition: # new in 1.2
138-
Enabled: true
139-
Style/NestedFileDirname: # new in 1.26
140-
Enabled: true
141-
Style/NilLambda: # new in 1.3
142-
Enabled: true
143-
Style/NumberedParameters: # new in 1.22
144-
Enabled: true
145-
Style/NumberedParametersLimit: # new in 1.22
146-
Enabled: true
147-
Style/ObjectThen: # new in 1.28
148-
Enabled: true
149-
Style/OpenStructUse: # new in 1.23
150-
Enabled: true
151-
Style/QuotedSymbols: # new in 1.16
152-
Enabled: true
153-
Style/RedundantArgument: # new in 1.4
154-
Enabled: true
155-
Style/RedundantInitialize: # new in 1.27
156-
Enabled: true
157-
Style/RedundantSelfAssignmentBranch: # new in 1.19
158-
Enabled: true
159-
Style/SelectByRegexp: # new in 1.22
160-
Enabled: true
161-
Style/StringChars: # new in 1.12
162-
Enabled: true
163-
Style/SwapValues: # new in 1.1
164-
Enabled: true
165-
Performance/AncestorsInclude: # new in 1.7
166-
Enabled: true
167-
Performance/BigDecimalWithNumericArgument: # new in 1.7
168-
Enabled: true
169-
Performance/BlockGivenWithExplicitBlock: # new in 1.9
170-
Enabled: true
171-
Performance/CollectionLiteralInLoop: # new in 1.8
172-
Enabled: true
173-
Performance/ConcurrentMonotonicTime: # new in 1.12
174-
Enabled: true
175-
Performance/ConstantRegexp: # new in 1.9
176-
Enabled: true
177-
Performance/MapCompact: # new in 1.11
178-
Enabled: true
179-
Performance/MethodObjectAsBlock: # new in 1.9
180-
Enabled: true
181-
Performance/RedundantEqualityComparisonBlock: # new in 1.10
182-
Enabled: true
183-
Performance/RedundantSortBlock: # new in 1.7
184-
Enabled: true
185-
Performance/RedundantSplitRegexpArgument: # new in 1.10
186-
Enabled: true
187-
Performance/RedundantStringChars: # new in 1.7
188-
Enabled: true
189-
Performance/ReverseFirst: # new in 1.7
190-
Enabled: true
191-
Performance/SortReverse: # new in 1.7
192-
Enabled: true
193-
Performance/Squeeze: # new in 1.7
194-
Enabled: true
195-
Performance/StringIdentifierArgument: # new in 1.13
196-
Enabled: true
197-
Performance/StringInclude: # new in 1.7
198-
Enabled: true
199-
Performance/Sum: # new in 1.8
200-
Enabled: true

.rubocop_todo.yml

Lines changed: 29 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 2023-12-27 11:12:52 UTC using RuboCop version 1.59.0.
3+
# on 2026-02-07 23:35:21 UTC using RuboCop version 1.84.1.
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
@@ -23,22 +23,29 @@ Lint/EmptyBlock:
2323
- 'spec/faraday/rack_builder_spec.rb'
2424
- 'spec/faraday/response_spec.rb'
2525

26+
# Offense count: 2
27+
# This cop supports unsafe autocorrection (--autocorrect-all).
28+
# Configuration parameters: AllowedReceivers.
29+
Lint/UselessDefaultValueArgument:
30+
Exclude:
31+
- 'spec/faraday/options/options_spec.rb'
32+
2633
# Offense count: 13
2734
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
2835
Metrics/AbcSize:
29-
Max: 42
36+
Max: 41
3037

31-
# Offense count: 3
38+
# Offense count: 4
3239
# Configuration parameters: CountComments, CountAsOne.
3340
Metrics/ClassLength:
34-
Max: 235
41+
Max: 231
3542

36-
# Offense count: 9
43+
# Offense count: 8
3744
# Configuration parameters: AllowedMethods, AllowedPatterns.
3845
Metrics/CyclomaticComplexity:
3946
Max: 13
4047

41-
# Offense count: 27
48+
# Offense count: 28
4249
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
4350
Metrics/MethodLength:
4451
Max: 33
@@ -53,7 +60,15 @@ Metrics/ParameterLists:
5360
Metrics/PerceivedComplexity:
5461
Max: 14
5562

56-
# Offense count: 19
63+
# Offense count: 2
64+
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
65+
# AllowedMethods: call
66+
# WaywardPredicates: infinite?, nonzero?
67+
Naming/PredicateMethod:
68+
Exclude:
69+
- 'lib/faraday/adapter/test.rb'
70+
71+
# Offense count: 2
5772
# This cop supports safe autocorrection (--autocorrect).
5873
# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames.
5974
# RedundantRestArgumentNames: args, arguments
@@ -62,10 +77,16 @@ Metrics/PerceivedComplexity:
6277
Style/ArgumentsForwarding:
6378
Exclude:
6479
- 'lib/faraday.rb'
65-
- 'lib/faraday/rack_builder.rb'
6680

6781
# Offense count: 3
6882
Style/DocumentDynamicEvalDefinition:
6983
Exclude:
7084
- 'lib/faraday/connection.rb'
7185
- 'lib/faraday/options.rb'
86+
87+
# Offense count: 1
88+
# This cop supports unsafe autocorrection (--autocorrect-all).
89+
# Configuration parameters: AllowedMethods, AllowedPatterns.
90+
Style/ReturnNilInPredicateMethodDefinition:
91+
Exclude:
92+
- 'lib/faraday/adapter/test.rb'

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ end
2121
group :development, :lint do
2222
gem 'racc', '~> 1.7' # for RuboCop, on Ruby 3.3
2323
gem 'rubocop'
24-
gem 'rubocop-packaging', '~> 0.5'
25-
gem 'rubocop-performance', '~> 1.0'
24+
gem 'rubocop-packaging'
25+
gem 'rubocop-performance'
26+
gem 'rubocop-rake'
2627
gem 'yard-junk'
2728
end
2829

lib/faraday/adapter.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ class Adapter
88

99
CONTENT_LENGTH = 'Content-Length'
1010

11+
TIMEOUT_KEYS = {
12+
read: :read_timeout,
13+
open: :open_timeout,
14+
write: :write_timeout
15+
}.freeze
16+
1117
# This module marks an Adapter as supporting parallel requests.
1218
module Parallelism
1319
attr_writer :supports_parallel
@@ -23,6 +29,7 @@ def inherited(subclass)
2329
end
2430

2531
extend Parallelism
32+
2633
self.supports_parallel = false
2734

2835
def initialize(_app = nil, opts = {}, &block)
@@ -89,12 +96,6 @@ def request_timeout(type, options)
8996
end
9097
options[key] || options[:timeout]
9198
end
92-
93-
TIMEOUT_KEYS = {
94-
read: :read_timeout,
95-
open: :open_timeout,
96-
write: :write_timeout
97-
}.freeze
9899
end
99100
end
100101

lib/faraday/encoders/flat_params_encoder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Faraday
66
module FlatParamsEncoder
77
class << self
88
extend Forwardable
9+
910
def_delegators :'Faraday::Utils', :escape, :unescape
1011
end
1112

lib/faraday/encoders/nested_params_encoder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class << self
170170
attr_accessor :sort_params, :array_indices
171171

172172
extend Forwardable
173+
173174
def_delegators :'Faraday::Utils', :escape, :unescape
174175
end
175176

lib/faraday/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ServerError < Error
172172
# A unified client error for timeouts.
173173
class TimeoutError < ServerError
174174
def initialize(exc = 'timeout', response = nil)
175-
super(exc, response)
175+
super
176176
end
177177
end
178178

lib/faraday/middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def close
6565
if app.respond_to?(:close)
6666
app.close
6767
else
68-
warn "#{app} does not implement \#close!"
68+
warn "#{app} does not implement #close!"
6969
end
7070
end
7171
end

lib/faraday/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def self.memoized_attributes
186186
def [](key)
187187
key = key.to_sym
188188
if (method = self.class.memoized_attributes[key])
189-
super(key) || (self[key] = instance_eval(&method))
189+
super || (self[key] = instance_eval(&method))
190190
else
191191
super
192192
end

lib/faraday/options/env.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module Faraday
7878
# @param value [Object] a value fitting Option.from(v).
7979
# @return [Env] from given value
8080
def self.from(value)
81-
env = super(value)
81+
env = super
8282
if value.respond_to?(:custom_members)
8383
env.custom_members.update(value.custom_members)
8484
end
@@ -90,7 +90,7 @@ def [](key)
9090
return self[current_body] if key == :body
9191

9292
if in_member_set?(key)
93-
super(key)
93+
super
9494
else
9595
custom_members[key]
9696
end
@@ -105,7 +105,7 @@ def []=(key, value)
105105
end
106106

107107
if in_member_set?(key)
108-
super(key, value)
108+
super
109109
else
110110
custom_members[key] = value
111111
end

0 commit comments

Comments
 (0)