Skip to content

Commit 1e91a7b

Browse files
committed
Add rubocop-performance extension
This commit adds the rubocop-performance extension to Puppet as part of its Gemfile and .rubocop.yml configuration file. I've specified version 1.13.3 as it's the last version compatible with Ruby 2.5, which mirrors the version of Rubocop we have pinned and the version of Ruby that is targeted in the Rubocop configuration file. This commit also regenerates the Rubocop todo file and manually adds pending Performance cops to both the configuration and todo files.
1 parent 09904df commit 1e91a7b

File tree

3 files changed

+123
-15
lines changed

3 files changed

+123
-15
lines changed

.rubocop.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
inherit_from: .rubocop_todo.yml
22

33
require:
4-
rubocop-i18n
4+
- rubocop-i18n
5+
- rubocop-performance
56

67
AllCops:
78
TargetRubyVersion: 2.5
@@ -154,3 +155,21 @@ Naming/VariableName:
154155

155156
Naming/VariableNumber:
156157
Enabled: false
158+
159+
Performance/AncestorsInclude: # new in 1.7
160+
Enabled: true
161+
162+
Performance/BigDecimalWithNumericArgument: # new in 1.7
163+
Enabled: true
164+
165+
Performance/ConcurrentMonotonicTime: # new in 1.12
166+
Enabled: true
167+
168+
Performance/MapCompact: # new in 1.11
169+
Enabled: true
170+
171+
Performance/RedundantSortBlock: # new in 1.7
172+
Enabled: true
173+
174+
Performance/ReverseFirst: # new in 1.7
175+
Enabled: true

.rubocop_todo.yml

Lines changed: 102 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ I18n/RailsI18n/DecorateString:
2525
# Configuration parameters: AllowedMethods.
2626
# AllowedMethods: enums
2727
Lint/ConstantDefinitionInBlock:
28-
Enabled: false
28+
Exclude:
29+
- 'lib/puppet/face/config.rb'
30+
- 'lib/puppet/face/help.rb'
31+
- 'lib/puppet/face/node/clean.rb'
32+
- 'lib/puppet/provider/package/aix.rb'
33+
- 'lib/puppet/provider/package/apt.rb'
34+
- 'lib/puppet/provider/package/gem.rb'
35+
- 'lib/puppet/provider/package/pip.rb'
36+
- 'lib/puppet/provider/package/yum.rb'
37+
- 'lib/puppet/provider/service/upstart.rb'
38+
- 'lib/puppet/provider/user/directoryservice.rb'
39+
- 'lib/puppet/type/file.rb'
40+
- 'lib/puppet/type/file/source.rb'
41+
- 'lib/puppet/type/resources.rb'
42+
- 'lib/puppet/type/schedule.rb'
43+
- 'lib/puppet/type/tidy.rb'
2944

3045
Lint/MissingSuper:
3146
Enabled: false
@@ -85,6 +100,90 @@ Lint/ToJSON:
85100
Lint/UnusedMethodArgument:
86101
Enabled: false
87102

103+
Performance/BlockGivenWithExplicitBlock: # new in 1.9
104+
Enabled: false
105+
106+
Performance/CollectionLiteralInLoop: # new in 1.8
107+
Enabled: false
108+
109+
Performance/ConstantRegexp: # new in 1.9
110+
Enabled: false
111+
112+
# This cop supports safe auto-correction (--auto-correct).
113+
Performance/Count:
114+
Exclude:
115+
- 'lib/puppet/confine/any.rb'
116+
- 'lib/puppet/confine/false.rb'
117+
- 'lib/puppet/confine/true.rb'
118+
- 'lib/puppet/graph/relationship_graph.rb'
119+
- 'lib/puppet/provider.rb'
120+
121+
# This cop supports unsafe auto-correction (--auto-correct-all).
122+
Performance/InefficientHashSearch:
123+
Exclude:
124+
- 'lib/puppet/face/node/clean.rb'
125+
- 'lib/puppet/provider/nameservice/directoryservice.rb'
126+
- 'lib/puppet/provider/user/directoryservice.rb'
127+
- 'lib/puppet/resource.rb'
128+
- 'lib/puppet/util/windows/adsi.rb'
129+
130+
Performance/MethodObjectAsBlock: # new in 1.9
131+
Enabled: false
132+
133+
# This cop supports safe auto-correction (--auto-correct).
134+
Performance/RedundantBlockCall:
135+
Exclude:
136+
- 'lib/puppet/application.rb'
137+
- 'lib/puppet/context.rb'
138+
- 'lib/puppet/file_bucket/file.rb'
139+
- 'lib/puppet/functions/max.rb'
140+
- 'lib/puppet/functions/min.rb'
141+
- 'lib/puppet/gettext/stubs.rb'
142+
- 'lib/puppet/network/http/api/server/v3.rb'
143+
- 'lib/puppet/pal/pal_impl.rb'
144+
- 'lib/puppet/pops/adaptable.rb'
145+
- 'lib/puppet/pops/lookup/invocation.rb'
146+
- 'lib/puppet/pops/model/factory.rb'
147+
- 'lib/puppet/util.rb'
148+
149+
Performance/RedundantEqualityComparisonBlock: # new in 1.10
150+
Enabled: false
151+
152+
# This cop supports unsafe auto-correction (--auto-correct-all).
153+
# Configuration parameters: MaxKeyValuePairs.
154+
Performance/RedundantMerge:
155+
Exclude:
156+
- 'lib/puppet/x509/cert_provider.rb'
157+
158+
Performance/RedundantSplitRegexpArgument: # new in 1.10
159+
Enabled: false
160+
161+
Performance/RedundantStringChars: # new in 1.7
162+
Enabled: false
163+
164+
# This cop supports safe auto-correction (--auto-correct).
165+
Performance/RegexpMatch:
166+
Enabled: false
167+
168+
Performance/SortReverse: # new in 1.7
169+
Enabled: false
170+
171+
Performance/Squeeze: # new in 1.7
172+
Enabled: false
173+
174+
Performance/StringIdentifierArgument: # new in 1.13
175+
Enabled: false
176+
177+
Performance/StringInclude: # new in 1.7
178+
Enabled: false
179+
180+
Performance/Sum: # new in 1.8
181+
Enabled: false
182+
183+
# This cop supports safe auto-correction (--auto-correct).
184+
Performance/UnfreezeString:
185+
Enabled: false
186+
88187
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
89188
# SupportedStyles: inline, group
90189
Style/AccessModifierDeclarations:
@@ -280,7 +379,6 @@ Style/EmptyBlockParameter:
280379
# This cop supports safe auto-correction (--auto-correct).
281380
Style/EmptyCaseCondition:
282381
Exclude:
283-
- 'lib/puppet/pops/lookup/hiera_config.rb'
284382
- 'lib/puppet/pops/serialization/serializer.rb'
285383
- 'lib/puppet/pops/types/type_calculator.rb'
286384
- 'lib/puppet/settings.rb'
@@ -298,7 +396,6 @@ Style/EmptyElse:
298396
# This cop supports safe auto-correction (--auto-correct).
299397
Style/EmptyLiteral:
300398
Exclude:
301-
- 'lib/puppet/indirector/face.rb'
302399
- 'lib/puppet/parser/scope.rb'
303400
- 'lib/puppet/pops/puppet_stack.rb'
304401
- 'lib/puppet/pops/visitor.rb'
@@ -327,11 +424,6 @@ Style/Encoding:
327424
- 'lib/puppet/type/package.rb'
328425
- 'lib/puppet/util/windows/service.rb'
329426

330-
# This cop supports safe auto-correction (--auto-correct).
331-
Style/EvalWithLocation:
332-
Exclude:
333-
- 'lib/puppet/interface/action_builder.rb'
334-
335427
# This cop supports safe auto-correction (--auto-correct).
336428
Style/EvenOdd:
337429
Exclude:
@@ -511,7 +603,6 @@ Style/MethodDefParentheses:
511603
Exclude:
512604
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
513605
- 'lib/puppet/pops/evaluator/relationship_operator.rb'
514-
- 'lib/puppet/pops/evaluator/runtime3_support.rb'
515606
- 'lib/puppet/pops/issues.rb'
516607
- 'lib/puppet/pops/label_provider.rb'
517608
- 'lib/puppet/pops/model/factory.rb'
@@ -622,7 +713,6 @@ Style/NestedModifier:
622713
Style/NestedParenthesizedCalls:
623714
Exclude:
624715
- 'lib/puppet/provider/user/directoryservice.rb'
625-
- 'lib/puppet/type/service.rb'
626716

627717
# This cop supports safe auto-correction (--auto-correct).
628718
Style/NestedTernaryOperator:
@@ -648,7 +738,6 @@ Style/Next:
648738
# SupportedStyles: predicate, comparison
649739
Style/NilComparison:
650740
Exclude:
651-
- 'lib/puppet/pops/model/ast.rb'
652741
- 'lib/puppet/pops/types/type_factory.rb'
653742
- 'lib/puppet/pops/types/types.rb'
654743
- 'lib/puppet/provider/package/dnfmodule.rb'
@@ -681,7 +770,7 @@ Style/NumericLiteralPrefix:
681770
# This cop supports safe auto-correction (--auto-correct).
682771
# Configuration parameters: Strict, AllowedNumbers.
683772
Style/NumericLiterals:
684-
MinDigits: 20
773+
MinDigits: 11
685774

686775
# This cop supports unsafe auto-correction (--auto-correct-all).
687776
# Configuration parameters: EnforcedStyle, IgnoredMethods.
@@ -832,7 +921,6 @@ Style/RedundantException:
832921
# Configuration parameters: SafeForConstants.
833922
Style/RedundantFetchBlock:
834923
Exclude:
835-
- 'lib/puppet/pops/model/ast.rb'
836924
- 'lib/puppet/pops/types/p_sem_ver_range_type.rb'
837925

838926
# This cop supports safe auto-correction (--auto-correct).
@@ -1187,4 +1275,4 @@ Style/ZeroLengthPredicate:
11871275
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
11881276
# URISchemes: http, https
11891277
Layout/LineLength:
1190-
Enabled: false
1278+
Max: 582

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ group(:test) do
4949

5050
gem 'rubocop', '1.28.0', require: false, platforms: [:ruby]
5151
gem 'rubocop-i18n', '~> 3.0', require: false, platforms: [:ruby]
52+
gem 'rubocop-performance', '1.13.3', require: false, platforms: [:ruby]
5253
end
5354

5455
group(:development, optional: true) do

0 commit comments

Comments
 (0)