cookstyle 6.3.4 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/config/cookstyle.yml +290 -15
- data/config/disable_all.yml +13 -1
- data/config/upstream.yml +82 -22
- data/lib/cookstyle.rb +1 -1
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/chef/platform_helpers.rb +2 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +10 -4
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +141 -0
- data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +86 -0
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +59 -0
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +6 -1
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +24 -3
- data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +64 -0
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
- data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +1 -1
- data/lib/rubocop/cop/target_chef_version.rb +4 -0
- data/lib/rubocop/monkey_patches/team.rb +24 -0
- metadata +13 -6
- data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +0 -81
- data/lib/rubocop/monkey_patches/commissioner.rb +0 -26
data/config/disable_all.yml
CHANGED
@@ -59,6 +59,8 @@ Layout/EmptyLinesAroundAccessModifier:
|
|
59
59
|
Enabled: false
|
60
60
|
Layout/EmptyLinesAroundArguments:
|
61
61
|
Enabled: false
|
62
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
63
|
+
Enabled: false
|
62
64
|
Layout/EmptyLinesAroundBeginBody:
|
63
65
|
Enabled: false
|
64
66
|
Layout/EmptyLinesAroundBlockBody:
|
@@ -213,6 +215,8 @@ Lint/Debugger:
|
|
213
215
|
Enabled: false
|
214
216
|
Lint/DeprecatedClassMethods:
|
215
217
|
Enabled: false
|
218
|
+
Lint/DeprecatedOpenSSLConstant:
|
219
|
+
Enabled: false
|
216
220
|
Lint/DisjunctiveAssignmentInConstructor:
|
217
221
|
Enabled: false
|
218
222
|
Lint/DuplicateCaseCondition:
|
@@ -261,6 +265,8 @@ Lint/Loop:
|
|
261
265
|
Enabled: false
|
262
266
|
Lint/MissingCopEnableDirective:
|
263
267
|
Enabled: false
|
268
|
+
Lint/MixedRegexpCaptureTypes:
|
269
|
+
Enabled: false
|
264
270
|
Lint/MultipleComparison:
|
265
271
|
Enabled: false
|
266
272
|
Lint/NestedMethodDefinition:
|
@@ -665,6 +671,10 @@ Style/RedundantParentheses:
|
|
665
671
|
Enabled: false
|
666
672
|
Style/RedundantPercentQ:
|
667
673
|
Enabled: false
|
674
|
+
Style/RedundantRegexpCharacterClass:
|
675
|
+
Enabled: false
|
676
|
+
Style/RedundantRegexpEscape:
|
677
|
+
Enabled: false
|
668
678
|
Style/RedundantReturn:
|
669
679
|
Enabled: false
|
670
680
|
Style/RedundantSelf:
|
@@ -697,6 +707,8 @@ Style/SingleLineBlockParams:
|
|
697
707
|
Enabled: false
|
698
708
|
Style/SingleLineMethods:
|
699
709
|
Enabled: false
|
710
|
+
Style/SlicingWithRange:
|
711
|
+
Enabled: false
|
700
712
|
Style/SpecialGlobalVars:
|
701
713
|
Enabled: false
|
702
714
|
Style/StabbyLambdaParentheses:
|
@@ -770,4 +782,4 @@ Security/MarshalLoad:
|
|
770
782
|
Security/Open:
|
771
783
|
Enabled: false
|
772
784
|
Security/YAMLLoad:
|
773
|
-
Enabled: false
|
785
|
+
Enabled: false
|
data/config/upstream.yml
CHANGED
@@ -35,6 +35,7 @@ AllCops:
|
|
35
35
|
- '**/*.watchr'
|
36
36
|
- '**/.irbrc'
|
37
37
|
- '**/.pryrc'
|
38
|
+
- '**/.simplecov'
|
38
39
|
- '**/buildfile'
|
39
40
|
- '**/Appraisals'
|
40
41
|
- '**/Berksfile'
|
@@ -53,6 +54,7 @@ AllCops:
|
|
53
54
|
- '**/Podfile'
|
54
55
|
- '**/Puppetfile'
|
55
56
|
- '**/Rakefile'
|
57
|
+
- '**/rakefile'
|
56
58
|
- '**/Snapfile'
|
57
59
|
- '**/Steepfile'
|
58
60
|
- '**/Thorfile'
|
@@ -151,12 +153,13 @@ Bundler/GemComment:
|
|
151
153
|
Description: 'Add a comment describing each gem.'
|
152
154
|
Enabled: false
|
153
155
|
VersionAdded: '0.59'
|
154
|
-
VersionChanged: '0.
|
156
|
+
VersionChanged: '0.85'
|
155
157
|
Include:
|
156
158
|
- '**/*.gemfile'
|
157
159
|
- '**/Gemfile'
|
158
160
|
- '**/gems.rb'
|
159
161
|
IgnoredGems: []
|
162
|
+
OnlyFor: []
|
160
163
|
|
161
164
|
Bundler/InsecureProtocolSource:
|
162
165
|
Description: >-
|
@@ -375,6 +378,7 @@ Layout/ConditionPosition:
|
|
375
378
|
StyleGuide: '#same-line-condition'
|
376
379
|
Enabled: true
|
377
380
|
VersionAdded: '0.53'
|
381
|
+
VersionChanged: '0.83'
|
378
382
|
|
379
383
|
Layout/DefEndAlignment:
|
380
384
|
Description: 'Align ends corresponding to defs correctly.'
|
@@ -460,6 +464,19 @@ Layout/EmptyLinesAroundArguments:
|
|
460
464
|
Enabled: true
|
461
465
|
VersionAdded: '0.52'
|
462
466
|
|
467
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
468
|
+
Description: "Keep blank lines around attribute accessors."
|
469
|
+
StyleGuide: '#empty-lines-around-attribute-accessor'
|
470
|
+
Enabled: pending
|
471
|
+
VersionAdded: '0.83'
|
472
|
+
VersionChanged: '0.84'
|
473
|
+
AllowAliasSyntax: true
|
474
|
+
AllowedMethods:
|
475
|
+
- alias_method
|
476
|
+
- public
|
477
|
+
- protected
|
478
|
+
- private
|
479
|
+
|
463
480
|
Layout/EmptyLinesAroundBeginBody:
|
464
481
|
Description: "Keeps track of empty lines around begin-end bodies."
|
465
482
|
StyleGuide: '#empty-lines-around-bodies'
|
@@ -774,13 +791,7 @@ Layout/HeredocIndentation:
|
|
774
791
|
StyleGuide: '#squiggly-heredocs'
|
775
792
|
Enabled: true
|
776
793
|
VersionAdded: '0.49'
|
777
|
-
VersionChanged: '0.
|
778
|
-
EnforcedStyle: squiggly
|
779
|
-
SupportedStyles:
|
780
|
-
- squiggly
|
781
|
-
- active_support
|
782
|
-
- powerpack
|
783
|
-
- unindent
|
794
|
+
VersionChanged: '0.85'
|
784
795
|
|
785
796
|
Layout/IndentationConsistency:
|
786
797
|
Description: 'Keep indentation straight.'
|
@@ -848,13 +859,13 @@ Layout/LeadingEmptyLines:
|
|
848
859
|
VersionChanged: '0.77'
|
849
860
|
|
850
861
|
Layout/LineLength:
|
851
|
-
Description: '
|
852
|
-
StyleGuide: '#
|
862
|
+
Description: 'Checks that line length does not exceed the configured limit.'
|
863
|
+
StyleGuide: '#max-line-length'
|
853
864
|
Enabled: true
|
854
865
|
VersionAdded: '0.25'
|
855
|
-
VersionChanged: '0.
|
866
|
+
VersionChanged: '0.84'
|
856
867
|
AutoCorrect: false
|
857
|
-
Max:
|
868
|
+
Max: 120
|
858
869
|
# To make it possible to copy or click on URIs in the code, we allow lines
|
859
870
|
# containing a URI to be longer than Max.
|
860
871
|
AllowHeredoc: true
|
@@ -1295,8 +1306,8 @@ Layout/TrailingWhitespace:
|
|
1295
1306
|
StyleGuide: '#no-trailing-whitespace'
|
1296
1307
|
Enabled: true
|
1297
1308
|
VersionAdded: '0.49'
|
1298
|
-
VersionChanged: '0.
|
1299
|
-
AllowInHeredoc:
|
1309
|
+
VersionChanged: '0.83'
|
1310
|
+
AllowInHeredoc: true
|
1300
1311
|
|
1301
1312
|
#################### Lint ##################################
|
1302
1313
|
### Warnings
|
@@ -1316,6 +1327,7 @@ Lint/AmbiguousOperator:
|
|
1316
1327
|
StyleGuide: '#method-invocation-parens'
|
1317
1328
|
Enabled: true
|
1318
1329
|
VersionAdded: '0.17'
|
1330
|
+
VersionChanged: '0.83'
|
1319
1331
|
|
1320
1332
|
Lint/AmbiguousRegexpLiteral:
|
1321
1333
|
Description: >-
|
@@ -1323,6 +1335,7 @@ Lint/AmbiguousRegexpLiteral:
|
|
1323
1335
|
a method invocation without parentheses.
|
1324
1336
|
Enabled: true
|
1325
1337
|
VersionAdded: '0.17'
|
1338
|
+
VersionChanged: '0.83'
|
1326
1339
|
|
1327
1340
|
Lint/AssignmentInCondition:
|
1328
1341
|
Description: "Don't use assignment in conditions."
|
@@ -1339,8 +1352,9 @@ Lint/BigDecimalNew:
|
|
1339
1352
|
Lint/BooleanSymbol:
|
1340
1353
|
Description: 'Check for `:true` and `:false` symbols.'
|
1341
1354
|
Enabled: true
|
1355
|
+
Safe: false
|
1342
1356
|
VersionAdded: '0.50'
|
1343
|
-
VersionChanged: '0.
|
1357
|
+
VersionChanged: '0.83'
|
1344
1358
|
|
1345
1359
|
Lint/CircularArgumentReference:
|
1346
1360
|
Description: "Default values in optional keyword arguments and optional ordinal arguments should not refer back to the name of the argument."
|
@@ -1358,6 +1372,11 @@ Lint/DeprecatedClassMethods:
|
|
1358
1372
|
Enabled: true
|
1359
1373
|
VersionAdded: '0.19'
|
1360
1374
|
|
1375
|
+
Lint/DeprecatedOpenSSLConstant:
|
1376
|
+
Description: "Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`."
|
1377
|
+
Enabled: pending
|
1378
|
+
VersionAdded: '0.84'
|
1379
|
+
|
1361
1380
|
Lint/DisjunctiveAssignmentInConstructor:
|
1362
1381
|
Description: 'In constructor, plain assignment is preferred over disjunctive.'
|
1363
1382
|
Enabled: true
|
@@ -1411,13 +1430,16 @@ Lint/EmptyInterpolation:
|
|
1411
1430
|
Lint/EmptyWhen:
|
1412
1431
|
Description: 'Checks for `when` branches with empty bodies.'
|
1413
1432
|
Enabled: true
|
1433
|
+
AllowComments: true
|
1414
1434
|
VersionAdded: '0.45'
|
1435
|
+
VersionChanged: '0.83'
|
1415
1436
|
|
1416
1437
|
Lint/EnsureReturn:
|
1417
1438
|
Description: 'Do not use return in an ensure block.'
|
1418
1439
|
StyleGuide: '#no-return-ensure'
|
1419
1440
|
Enabled: true
|
1420
1441
|
VersionAdded: '0.9'
|
1442
|
+
VersionChanged: '0.83'
|
1421
1443
|
|
1422
1444
|
Lint/ErbNewArguments:
|
1423
1445
|
Description: 'Use `:trim_mode` and `:eoutvar` keyword arguments to `ERB.new`.'
|
@@ -1511,6 +1533,11 @@ Lint/MissingCopEnableDirective:
|
|
1511
1533
|
# .inf for any size
|
1512
1534
|
MaximumRangeSize: .inf
|
1513
1535
|
|
1536
|
+
Lint/MixedRegexpCaptureTypes:
|
1537
|
+
Description: 'Do not mix named captures and numbered captures in a Regexp literal.'
|
1538
|
+
Enabled: pending
|
1539
|
+
VersionAdded: '0.85'
|
1540
|
+
|
1514
1541
|
Lint/MultipleComparison:
|
1515
1542
|
Description: "Use `&&` operator to compare multiple values."
|
1516
1543
|
Enabled: true
|
@@ -1565,6 +1592,7 @@ Lint/ParenthesesAsGroupedExpression:
|
|
1565
1592
|
StyleGuide: '#parens-no-spaces'
|
1566
1593
|
Enabled: true
|
1567
1594
|
VersionAdded: '0.12'
|
1595
|
+
VersionChanged: '0.83'
|
1568
1596
|
|
1569
1597
|
Lint/PercentStringArray:
|
1570
1598
|
Description: >-
|
@@ -1808,7 +1836,7 @@ Lint/UselessAccessModifier:
|
|
1808
1836
|
Description: 'Checks for useless access modifiers.'
|
1809
1837
|
Enabled: true
|
1810
1838
|
VersionAdded: '0.20'
|
1811
|
-
VersionChanged: '0.
|
1839
|
+
VersionChanged: '0.83'
|
1812
1840
|
ContextCreatingMethods: []
|
1813
1841
|
MethodCreatingMethods: []
|
1814
1842
|
|
@@ -1983,6 +2011,11 @@ Naming/ClassAndModuleCamelCase:
|
|
1983
2011
|
StyleGuide: '#camelcase-classes'
|
1984
2012
|
Enabled: true
|
1985
2013
|
VersionAdded: '0.50'
|
2014
|
+
VersionChanged: '0.85'
|
2015
|
+
# Allowed class/module names can be specified here.
|
2016
|
+
# These can be full or part of the name.
|
2017
|
+
AllowedNames:
|
2018
|
+
- module_parent
|
1986
2019
|
|
1987
2020
|
Naming/ConstantName:
|
1988
2021
|
Description: 'Constants should use SCREAMING_SNAKE_CASE.'
|
@@ -2003,6 +2036,10 @@ Naming/FileName:
|
|
2003
2036
|
# It further expects it to be nested inside modules which match the names
|
2004
2037
|
# of subdirectories in its path.
|
2005
2038
|
ExpectMatchingDefinition: false
|
2039
|
+
# When `false`, changes the behavior of ExpectMatchingDefinition to match only
|
2040
|
+
# whether each source file's class or module name matches the file name --
|
2041
|
+
# not whether the nested module hierarchy matches the subdirectory path.
|
2042
|
+
CheckDefinitionPathHierarchy: true
|
2006
2043
|
# If non-`nil`, expect all source file names to match the following regex.
|
2007
2044
|
# Only the file name itself is matched, not the entire file path.
|
2008
2045
|
# Use anchors as necessary if you want to match the entire name rather than
|
@@ -2194,7 +2231,7 @@ Security/JSONLoad:
|
|
2194
2231
|
Description: >-
|
2195
2232
|
Prefer usage of `JSON.parse` over `JSON.load` due to potential
|
2196
2233
|
security issues. See reference for more information.
|
2197
|
-
Reference: 'https://ruby-doc.org/stdlib-2.
|
2234
|
+
Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
|
2198
2235
|
Enabled: true
|
2199
2236
|
VersionAdded: '0.43'
|
2200
2237
|
VersionChanged: '0.44'
|
@@ -2207,7 +2244,7 @@ Security/MarshalLoad:
|
|
2207
2244
|
Description: >-
|
2208
2245
|
Avoid using of `Marshal.load` or `Marshal.restore` due to potential
|
2209
2246
|
security issues. See reference for more information.
|
2210
|
-
Reference: 'https://ruby-doc.org/core-2.
|
2247
|
+
Reference: 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
|
2211
2248
|
Enabled: true
|
2212
2249
|
VersionAdded: '0.47'
|
2213
2250
|
|
@@ -2221,7 +2258,7 @@ Security/YAMLLoad:
|
|
2221
2258
|
Description: >-
|
2222
2259
|
Prefer usage of `YAML.safe_load` over `YAML.load` due to potential
|
2223
2260
|
security issues. See reference for more information.
|
2224
|
-
Reference: 'https://ruby-doc.org/stdlib-2.
|
2261
|
+
Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
|
2225
2262
|
Enabled: true
|
2226
2263
|
VersionAdded: '0.47'
|
2227
2264
|
SafeAutoCorrect: false
|
@@ -2258,7 +2295,7 @@ Style/AndOr:
|
|
2258
2295
|
VersionChanged: '0.25'
|
2259
2296
|
# Whether `and` and `or` are banned only in conditionals (conditionals)
|
2260
2297
|
# or completely (always).
|
2261
|
-
EnforcedStyle:
|
2298
|
+
EnforcedStyle: conditionals
|
2262
2299
|
SupportedStyles:
|
2263
2300
|
- always
|
2264
2301
|
- conditionals
|
@@ -2678,6 +2715,11 @@ Style/DoubleNegation:
|
|
2678
2715
|
StyleGuide: '#no-bang-bang'
|
2679
2716
|
Enabled: true
|
2680
2717
|
VersionAdded: '0.19'
|
2718
|
+
VersionChanged: '0.84'
|
2719
|
+
EnforcedStyle: allowed_in_returns
|
2720
|
+
SupportedStyles:
|
2721
|
+
- allowed_in_returns
|
2722
|
+
- forbidden
|
2681
2723
|
|
2682
2724
|
Style/EachForSimpleLoop:
|
2683
2725
|
Description: >-
|
@@ -2841,8 +2883,7 @@ Style/FrozenStringLiteralComment:
|
|
2841
2883
|
SupportedStyles:
|
2842
2884
|
# `always` will always add the frozen string literal comment to a file
|
2843
2885
|
# regardless of the Ruby version or if `freeze` or `<<` are called on a
|
2844
|
-
# string literal.
|
2845
|
-
# possible that this will create errors in Ruby 2.3.0+.
|
2886
|
+
# string literal. It is possible that this will create errors.
|
2846
2887
|
- always
|
2847
2888
|
# `always_true` will add the frozen string literal comment to a file,
|
2848
2889
|
# similarly to the `always` style, but will also change any disabled
|
@@ -2948,6 +2989,7 @@ Style/IfWithSemicolon:
|
|
2948
2989
|
StyleGuide: '#no-semicolon-ifs'
|
2949
2990
|
Enabled: true
|
2950
2991
|
VersionAdded: '0.9'
|
2992
|
+
VersionChanged: '0.83'
|
2951
2993
|
|
2952
2994
|
Style/ImplicitRuntimeError:
|
2953
2995
|
Description: >-
|
@@ -3425,7 +3467,9 @@ Style/OptionalArguments:
|
|
3425
3467
|
of the argument list.
|
3426
3468
|
StyleGuide: '#optional-arguments'
|
3427
3469
|
Enabled: true
|
3470
|
+
Safe: false
|
3428
3471
|
VersionAdded: '0.33'
|
3472
|
+
VersionChanged: '0.83'
|
3429
3473
|
|
3430
3474
|
Style/OrAssignment:
|
3431
3475
|
Description: 'Recommend usage of double pipe equals (||=) where applicable.'
|
@@ -3574,6 +3618,16 @@ Style/RedundantPercentQ:
|
|
3574
3618
|
Enabled: true
|
3575
3619
|
VersionAdded: '0.76'
|
3576
3620
|
|
3621
|
+
Style/RedundantRegexpCharacterClass:
|
3622
|
+
Description: 'Checks for unnecessary single-element Regexp character classes.'
|
3623
|
+
Enabled: pending
|
3624
|
+
VersionAdded: '0.85'
|
3625
|
+
|
3626
|
+
Style/RedundantRegexpEscape:
|
3627
|
+
Description: 'Checks for redundant escapes in Regexps.'
|
3628
|
+
Enabled: pending
|
3629
|
+
VersionAdded: '0.85'
|
3630
|
+
|
3577
3631
|
Style/RedundantReturn:
|
3578
3632
|
Description: "Don't use return where it's not required."
|
3579
3633
|
StyleGuide: '#no-explicit-return'
|
@@ -3730,6 +3784,12 @@ Style/SingleLineMethods:
|
|
3730
3784
|
VersionChanged: '0.19'
|
3731
3785
|
AllowIfMethodIsEmpty: true
|
3732
3786
|
|
3787
|
+
Style/SlicingWithRange:
|
3788
|
+
Description: 'Checks array slicing is done with endless ranges when suitable.'
|
3789
|
+
Enabled: pending
|
3790
|
+
VersionAdded: '0.83'
|
3791
|
+
Safe: false
|
3792
|
+
|
3733
3793
|
Style/SpecialGlobalVars:
|
3734
3794
|
Description: 'Avoid Perl-style global variables.'
|
3735
3795
|
StyleGuide: '#no-cryptic-perlisms'
|
data/lib/cookstyle.rb
CHANGED
@@ -11,7 +11,7 @@ require 'rubocop/monkey_patches/comment_config.rb'
|
|
11
11
|
# monkey patches needed for the TargetChefVersion config option
|
12
12
|
require 'rubocop/monkey_patches/config.rb'
|
13
13
|
require 'rubocop/monkey_patches/cop.rb'
|
14
|
-
require 'rubocop/monkey_patches/
|
14
|
+
require 'rubocop/monkey_patches/team.rb'
|
15
15
|
|
16
16
|
module RuboCop
|
17
17
|
class ConfigLoader
|
data/lib/cookstyle/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: Copyright 2019-2020, Chef Software Inc.
|
3
3
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -32,6 +32,7 @@ module RuboCop
|
|
32
32
|
'mswin' => 'windows',
|
33
33
|
'opensuse' => 'suse',
|
34
34
|
'opensuseleap' => 'suse',
|
35
|
+
'oracle' => 'rhel',
|
35
36
|
'redhat' => 'rhel',
|
36
37
|
'scientific' => 'rhel',
|
37
38
|
'sles' => 'suse',
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# Use valid platform family values in case statements.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# case node['platform_family']
|
27
|
+
# when 'redhat'
|
28
|
+
# puts "I'm on a RHEL-like system"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
class InvalidPlatformFamilyInCase < Cop
|
32
|
+
include RangeHelp
|
33
|
+
include ::RuboCop::Chef::PlatformHelpers
|
34
|
+
|
35
|
+
MSG = 'Use valid platform family values in case statements.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :node_platform_family?, <<-PATTERN
|
38
|
+
(send (send nil? :node) :[] (str "platform_family") )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_case(node)
|
42
|
+
node_platform_family?(node.condition) do
|
43
|
+
node.each_when do |when_node|
|
44
|
+
when_node.each_condition do |con|
|
45
|
+
next unless con.str_type? # if the condition isn't a string we can't check so skip
|
46
|
+
|
47
|
+
if INVALID_PLATFORM_FAMILIES[con.str_content]
|
48
|
+
add_offense(con, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def autocorrect(node)
|
56
|
+
new_value = INVALID_PLATFORM_FAMILIES[node.str_content]
|
57
|
+
|
58
|
+
# some invalid platform families have no direct correction value and return nil instead
|
59
|
+
return unless new_value
|
60
|
+
|
61
|
+
# if the correct value already exists in the when statement then we just want to delete this node
|
62
|
+
if node.parent.conditions.any? { |x| x.str_content == new_value }
|
63
|
+
lambda do |corrector|
|
64
|
+
range = range_with_surrounding_comma(range_with_surrounding_space(range: node.loc.expression, side: :left), :both)
|
65
|
+
corrector.remove(range)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
lambda do |corrector|
|
69
|
+
corrector.replace(node.loc.expression, "'#{new_value}'")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|