cookstyle 6.1.6 → 6.2.5
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/config/cookstyle.yml +22 -2
- data/config/disable_all.yml +6 -2
- data/config/upstream.yml +63 -16
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +5 -11
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +4 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +3 -0
- data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +3 -0
- data/lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb +3 -0
- data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +3 -0
- data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +77 -0
- data/lib/rubocop/cop/chef/style/negating_only_if.rb +67 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1707e36ea2cbbcb24bf4fa6c8e4f79fed7ea64fdce34b7776c1888f6ee0871
|
4
|
+
data.tar.gz: faa3b6376f8d0022291709084b240ab98ec86f18106a6bb3f2271c5291064635
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 886ec87ae9bc65b2ddcbc061fda82c55755fe48ca5131574a3291ecf518a273b051a4977642feb8802051aa3e1def3c85e79fc6df4af8756e9e16fa5eccaa51d
|
7
|
+
data.tar.gz: 1089873dec1ec43f88eb2b8e9d0a4a059a80a26757b1f6a97b92619aad25f7a3761bdd7e01dd5a389534778ad4c9a03140e83d3828c2643e5c4ff13869f0edc9
|
data/config/cookstyle.yml
CHANGED
@@ -131,6 +131,17 @@ ChefStyle/UnnecessaryOSCheck:
|
|
131
131
|
Description: Use the platform_family?() helpers instead of node['os] == 'foo' for platform_families that match 1:1 with OS values. These helpers are easier to read and can accept multiple platform arguments, which greatly simplifies complex platform logic.
|
132
132
|
Enabled: true
|
133
133
|
VersionAdded: '5.21.0'
|
134
|
+
Exclude:
|
135
|
+
- '**/metadata.rb'
|
136
|
+
- '**/Berksfile'
|
137
|
+
|
138
|
+
ChefStyle/NegatingOnlyIf:
|
139
|
+
Description: Use not_if instead of only_if that negates the Ruby statement with a !
|
140
|
+
VersionAdded: '6.2.0'
|
141
|
+
Enabled: true
|
142
|
+
Exclude:
|
143
|
+
- '**/metadata.rb'
|
144
|
+
- '**/Berksfile'
|
134
145
|
|
135
146
|
###############################
|
136
147
|
# ChefCorrectness: Avoiding potential problems
|
@@ -1412,7 +1423,7 @@ ChefRedundantCode/GroupingMetadata:
|
|
1412
1423
|
- '**/metadata.rb'
|
1413
1424
|
|
1414
1425
|
ChefRedundantCode/StringPropertyWithNilDefault:
|
1415
|
-
Description:
|
1426
|
+
Description: Properties have a nil value by default so there is no need to set the default value to nil.
|
1416
1427
|
Enabled: true
|
1417
1428
|
VersionAdded: '5.21.0'
|
1418
1429
|
Include:
|
@@ -1420,13 +1431,22 @@ ChefRedundantCode/StringPropertyWithNilDefault:
|
|
1420
1431
|
- '**/libraries/*.rb'
|
1421
1432
|
|
1422
1433
|
ChefRedundantCode/PropertySplatRegex:
|
1423
|
-
Description:
|
1434
|
+
Description: There is no need to validate the input of properties in resources using a regex value that will always pass.
|
1424
1435
|
Enabled: true
|
1425
1436
|
VersionAdded: '5.21.0'
|
1426
1437
|
Include:
|
1427
1438
|
- '**/resources/*.rb'
|
1428
1439
|
- '**/libraries/*.rb'
|
1429
1440
|
|
1441
|
+
ChefRedundantCode/UseCreateIfMissing:
|
1442
|
+
Description: Use the :create_if_missing action instead of not_if with a ::File.exist(FOO) check.
|
1443
|
+
Enabled: true
|
1444
|
+
VersionAdded: '6.2.0'
|
1445
|
+
Exclude:
|
1446
|
+
- '**/metadata.rb'
|
1447
|
+
- '**/attributes/*.rb'
|
1448
|
+
- '**/Berksfile'
|
1449
|
+
|
1430
1450
|
###############################
|
1431
1451
|
# Migrating to new patterns
|
1432
1452
|
###############################
|
data/config/disable_all.yml
CHANGED
@@ -231,8 +231,6 @@ Lint/EmptyInterpolation:
|
|
231
231
|
Enabled: false
|
232
232
|
Lint/EmptyWhen:
|
233
233
|
Enabled: false
|
234
|
-
Lint/EndInMethod:
|
235
|
-
Enabled: false
|
236
234
|
Lint/EnsureReturn:
|
237
235
|
Enabled: false
|
238
236
|
Lint/ErbNewArguments:
|
@@ -283,6 +281,8 @@ Lint/PercentStringArray:
|
|
283
281
|
Enabled: false
|
284
282
|
Lint/PercentSymbolArray:
|
285
283
|
Enabled: false
|
284
|
+
Lint/RaiseException:
|
285
|
+
Enabled: false
|
286
286
|
Lint/RandOne:
|
287
287
|
Enabled: false
|
288
288
|
Lint/RedundantCopDisableDirective:
|
@@ -325,6 +325,8 @@ Lint/ShadowedException:
|
|
325
325
|
Enabled: false
|
326
326
|
Lint/ShadowingOuterLocalVariable:
|
327
327
|
Enabled: false
|
328
|
+
Lint/StructNewOverride:
|
329
|
+
Enabled: false
|
328
330
|
Lint/SuppressedException:
|
329
331
|
Enabled: false
|
330
332
|
Lint/Syntax:
|
@@ -725,6 +727,8 @@ Style/TrailingCommaInArguments:
|
|
725
727
|
Enabled: false
|
726
728
|
Style/TrailingCommaInArrayLiteral:
|
727
729
|
Enabled: false
|
730
|
+
Style/TrailingCommaInBlockArgs:
|
731
|
+
Enabled: false
|
728
732
|
Style/TrailingCommaInHashLiteral:
|
729
733
|
Enabled: false
|
730
734
|
Style/TrailingMethodEndStatement:
|
data/config/upstream.yml
CHANGED
@@ -255,10 +255,30 @@ Layout/ArrayAlignment:
|
|
255
255
|
Description: >-
|
256
256
|
Align the elements of an array literal if they span more than
|
257
257
|
one line.
|
258
|
-
StyleGuide: '#
|
258
|
+
StyleGuide: '#no-double-indent'
|
259
259
|
Enabled: true
|
260
260
|
VersionAdded: '0.49'
|
261
261
|
VersionChanged: '0.77'
|
262
|
+
# Alignment of elements of a multi-line array.
|
263
|
+
#
|
264
|
+
# The `with_first_parameter` style aligns the following lines along the same
|
265
|
+
# column as the first element.
|
266
|
+
#
|
267
|
+
# array = [1, 2, 3,
|
268
|
+
# 4, 5, 6]
|
269
|
+
#
|
270
|
+
# The `with_fixed_indentation` style aligns the following lines with one
|
271
|
+
# level of indentation relative to the start of the line with start of array.
|
272
|
+
#
|
273
|
+
# array = [1, 2, 3,
|
274
|
+
# 4, 5, 6]
|
275
|
+
EnforcedStyle: with_first_element
|
276
|
+
SupportedStyles:
|
277
|
+
- with_first_element
|
278
|
+
- with_fixed_indentation
|
279
|
+
# By default, the indentation width from Layout/IndentationWidth is used
|
280
|
+
# But it can be overridden by setting this parameter
|
281
|
+
IndentationWidth: ~
|
262
282
|
|
263
283
|
Layout/AssignmentIndentation:
|
264
284
|
Description: >-
|
@@ -1303,6 +1323,7 @@ Lint/BooleanSymbol:
|
|
1303
1323
|
Description: 'Check for `:true` and `:false` symbols.'
|
1304
1324
|
Enabled: true
|
1305
1325
|
VersionAdded: '0.50'
|
1326
|
+
VersionChanged: '0.81'
|
1306
1327
|
|
1307
1328
|
Lint/CircularArgumentReference:
|
1308
1329
|
Description: "Default values in optional keyword arguments and optional ordinal arguments should not refer back to the name of the argument."
|
@@ -1375,11 +1396,6 @@ Lint/EmptyWhen:
|
|
1375
1396
|
Enabled: true
|
1376
1397
|
VersionAdded: '0.45'
|
1377
1398
|
|
1378
|
-
Lint/EndInMethod:
|
1379
|
-
Description: 'END blocks should not be placed inside method definitions.'
|
1380
|
-
Enabled: true
|
1381
|
-
VersionAdded: '0.9'
|
1382
|
-
|
1383
1399
|
Lint/EnsureReturn:
|
1384
1400
|
Description: 'Do not use return in an ensure block.'
|
1385
1401
|
StyleGuide: '#no-return-ensure'
|
@@ -1546,6 +1562,12 @@ Lint/PercentSymbolArray:
|
|
1546
1562
|
Enabled: true
|
1547
1563
|
VersionAdded: '0.41'
|
1548
1564
|
|
1565
|
+
Lint/RaiseException:
|
1566
|
+
Description: Checks for `raise` or `fail` statements which are raising `Exception` class.
|
1567
|
+
StyleGuide: '#raise-exception'
|
1568
|
+
Enabled: pending
|
1569
|
+
VersionAdded: '0.81'
|
1570
|
+
|
1549
1571
|
Lint/RandOne:
|
1550
1572
|
Description: >-
|
1551
1573
|
Checks for `rand(1)` calls. Such calls always return `0`
|
@@ -1574,7 +1596,7 @@ Lint/RedundantRequireStatement:
|
|
1574
1596
|
Lint/RedundantSplatExpansion:
|
1575
1597
|
Description: 'Checks for splat unnecessarily being called on literals.'
|
1576
1598
|
Enabled: true
|
1577
|
-
|
1599
|
+
VersionAdded: '0.76'
|
1578
1600
|
|
1579
1601
|
Lint/RedundantStringCoercion:
|
1580
1602
|
Description: 'Checks for Object#to_s usage in string interpolation.'
|
@@ -1688,13 +1710,18 @@ Lint/ShadowingOuterLocalVariable:
|
|
1688
1710
|
Enabled: true
|
1689
1711
|
VersionAdded: '0.9'
|
1690
1712
|
|
1713
|
+
Lint/StructNewOverride:
|
1714
|
+
Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
|
1715
|
+
Enabled: pending
|
1716
|
+
VersionAdded: '0.81'
|
1717
|
+
|
1691
1718
|
Lint/SuppressedException:
|
1692
1719
|
Description: "Don't suppress exceptions."
|
1693
1720
|
StyleGuide: '#dont-hide-exceptions'
|
1694
1721
|
Enabled: true
|
1695
|
-
AllowComments:
|
1722
|
+
AllowComments: true
|
1696
1723
|
VersionAdded: '0.9'
|
1697
|
-
VersionChanged: '0.
|
1724
|
+
VersionChanged: '0.81'
|
1698
1725
|
|
1699
1726
|
Lint/Syntax:
|
1700
1727
|
Description: 'Checks syntax error.'
|
@@ -1705,6 +1732,7 @@ Lint/Syntax:
|
|
1705
1732
|
Lint/ToJSON:
|
1706
1733
|
Description: 'Ensure #to_json includes an optional argument.'
|
1707
1734
|
Enabled: true
|
1735
|
+
VersionAdded: '0.66'
|
1708
1736
|
|
1709
1737
|
Lint/UnderscorePrefixedVariableName:
|
1710
1738
|
Description: 'Do not use prefix `_` for a variable that is used.'
|
@@ -1736,9 +1764,10 @@ Lint/UnusedMethodArgument:
|
|
1736
1764
|
StyleGuide: '#underscore-unused-vars'
|
1737
1765
|
Enabled: true
|
1738
1766
|
VersionAdded: '0.21'
|
1739
|
-
VersionChanged: '0.
|
1767
|
+
VersionChanged: '0.81'
|
1740
1768
|
AllowUnusedKeywordArguments: false
|
1741
1769
|
IgnoreEmptyMethods: true
|
1770
|
+
IgnoreNotImplementedMethods: true
|
1742
1771
|
|
1743
1772
|
Lint/UriEscapeUnescape:
|
1744
1773
|
Description: >-
|
@@ -1804,9 +1833,10 @@ Metrics/AbcSize:
|
|
1804
1833
|
- https://en.wikipedia.org/wiki/ABC_Software_Metric
|
1805
1834
|
Enabled: true
|
1806
1835
|
VersionAdded: '0.27'
|
1807
|
-
VersionChanged: '0.
|
1836
|
+
VersionChanged: '0.81'
|
1808
1837
|
# The ABC size is a calculated magnitude, so this number can be an Integer or
|
1809
1838
|
# a Float.
|
1839
|
+
IgnoredMethods: []
|
1810
1840
|
Max: 15
|
1811
1841
|
|
1812
1842
|
Metrics/BlockLength:
|
@@ -1846,6 +1876,8 @@ Metrics/CyclomaticComplexity:
|
|
1846
1876
|
of test cases needed to validate a method.
|
1847
1877
|
Enabled: true
|
1848
1878
|
VersionAdded: '0.25'
|
1879
|
+
VersionChanged: '0.81'
|
1880
|
+
IgnoredMethods: []
|
1849
1881
|
Max: 6
|
1850
1882
|
|
1851
1883
|
Metrics/MethodLength:
|
@@ -1879,6 +1911,8 @@ Metrics/PerceivedComplexity:
|
|
1879
1911
|
human reader.
|
1880
1912
|
Enabled: true
|
1881
1913
|
VersionAdded: '0.25'
|
1914
|
+
VersionChanged: '0.81'
|
1915
|
+
IgnoredMethods: []
|
1882
1916
|
Max: 7
|
1883
1917
|
|
1884
1918
|
################## Migration #############################
|
@@ -1888,6 +1922,7 @@ Migration/DepartmentName:
|
|
1888
1922
|
Check that cop names in rubocop:disable (etc) comments are
|
1889
1923
|
given with department name.
|
1890
1924
|
Enabled: true
|
1925
|
+
VersionAdded: '0.75'
|
1891
1926
|
|
1892
1927
|
#################### Naming ##############################
|
1893
1928
|
|
@@ -2178,10 +2213,12 @@ Style/AccessModifierDeclarations:
|
|
2178
2213
|
Description: 'Checks style of how access modifiers are used.'
|
2179
2214
|
Enabled: true
|
2180
2215
|
VersionAdded: '0.57'
|
2216
|
+
VersionChanged: '0.81'
|
2181
2217
|
EnforcedStyle: group
|
2182
2218
|
SupportedStyles:
|
2183
2219
|
- inline
|
2184
2220
|
- group
|
2221
|
+
AllowModifiersOnSymbols: true
|
2185
2222
|
|
2186
2223
|
Style/Alias:
|
2187
2224
|
Description: 'Use alias instead of alias_method.'
|
@@ -2384,7 +2421,7 @@ Style/ClassAndModuleChildren:
|
|
2384
2421
|
StyleGuide: '#namespace-definition'
|
2385
2422
|
# Moving from compact to nested children requires knowledge of whether the
|
2386
2423
|
# outer parent is a module or a class. Moving from nested to compact requires
|
2387
|
-
# verification that the outer parent is defined elsewhere.
|
2424
|
+
# verification that the outer parent is defined elsewhere. Rubocop does not
|
2388
2425
|
# have the knowledge to perform either operation safely and thus requires
|
2389
2426
|
# manual oversight.
|
2390
2427
|
SafeAutoCorrect: false
|
@@ -2435,7 +2472,7 @@ Style/ClassVars:
|
|
2435
2472
|
# Align with the style guide.
|
2436
2473
|
Style/CollectionMethods:
|
2437
2474
|
Description: 'Preferred collection methods.'
|
2438
|
-
StyleGuide: '#map-find-select-reduce-size'
|
2475
|
+
StyleGuide: '#map-find-select-reduce-include-size'
|
2439
2476
|
Enabled: false
|
2440
2477
|
VersionAdded: '0.9'
|
2441
2478
|
VersionChanged: '0.27'
|
@@ -2452,6 +2489,7 @@ Style/CollectionMethods:
|
|
2452
2489
|
inject: 'reduce'
|
2453
2490
|
detect: 'find'
|
2454
2491
|
find_all: 'select'
|
2492
|
+
member?: 'include?'
|
2455
2493
|
|
2456
2494
|
Style/ColonMethodCall:
|
2457
2495
|
Description: 'Do not use :: for method call.'
|
@@ -2677,6 +2715,7 @@ Style/EndBlock:
|
|
2677
2715
|
StyleGuide: '#no-END-blocks'
|
2678
2716
|
Enabled: true
|
2679
2717
|
VersionAdded: '0.9'
|
2718
|
+
VersionChanged: '0.81'
|
2680
2719
|
|
2681
2720
|
Style/EvalWithLocation:
|
2682
2721
|
Description: 'Pass `__FILE__` and `__LINE__` to `eval` method, as they are used by backtraces.'
|
@@ -2937,7 +2976,7 @@ Style/LambdaCall:
|
|
2937
2976
|
Description: 'Use lambda.call(...) instead of lambda.(...).'
|
2938
2977
|
StyleGuide: '#proc-call'
|
2939
2978
|
Enabled: true
|
2940
|
-
VersionAdded: '0.13
|
2979
|
+
VersionAdded: '0.13'
|
2941
2980
|
VersionChanged: '0.14'
|
2942
2981
|
EnforcedStyle: call
|
2943
2982
|
SupportedStyles:
|
@@ -3067,6 +3106,7 @@ Style/ModuleFunction:
|
|
3067
3106
|
SupportedStyles:
|
3068
3107
|
- module_function
|
3069
3108
|
- extend_self
|
3109
|
+
- forbidden
|
3070
3110
|
Autocorrect: false
|
3071
3111
|
SafeAutoCorrect: false
|
3072
3112
|
|
@@ -3806,22 +3846,29 @@ Style/TrailingCommaInArrayLiteral:
|
|
3806
3846
|
StyleGuide: '#no-trailing-array-commas'
|
3807
3847
|
Enabled: true
|
3808
3848
|
VersionAdded: '0.53'
|
3849
|
+
# If `comma`, the cop requires a comma after the last item in an array,
|
3809
3850
|
# but only when each item is on its own line.
|
3810
3851
|
# If `consistent_comma`, the cop requires a comma after the last item of all
|
3811
|
-
# non-empty array literals.
|
3852
|
+
# non-empty, multiline array literals.
|
3812
3853
|
EnforcedStyleForMultiline: no_comma
|
3813
3854
|
SupportedStylesForMultiline:
|
3814
3855
|
- comma
|
3815
3856
|
- consistent_comma
|
3816
3857
|
- no_comma
|
3817
3858
|
|
3859
|
+
Style/TrailingCommaInBlockArgs:
|
3860
|
+
Description: 'Checks for useless trailing commas in block arguments.'
|
3861
|
+
Enabled: false
|
3862
|
+
Safe: false
|
3863
|
+
VersionAdded: '0.81'
|
3864
|
+
|
3818
3865
|
Style/TrailingCommaInHashLiteral:
|
3819
3866
|
Description: 'Checks for trailing comma in hash literals.'
|
3820
3867
|
Enabled: true
|
3821
3868
|
# If `comma`, the cop requires a comma after the last item in a hash,
|
3822
3869
|
# but only when each item is on its own line.
|
3823
3870
|
# If `consistent_comma`, the cop requires a comma after the last item of all
|
3824
|
-
# non-empty hash literals.
|
3871
|
+
# non-empty, multiline hash literals.
|
3825
3872
|
EnforcedStyleForMultiline: no_comma
|
3826
3873
|
SupportedStylesForMultiline:
|
3827
3874
|
- comma
|
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");
|
@@ -18,24 +18,22 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefCorrectness
|
21
|
-
# Libraries should be injected into the Chef::DSL::Recipe
|
21
|
+
# Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
25
25
|
# # bad
|
26
26
|
# ::Chef::Recipe.send(:include, Filebeat::Helpers)
|
27
27
|
# ::Chef::Provider.send(:include, Filebeat::Helpers)
|
28
|
-
# ::Chef::Resource.send(:include, Filebeat::Helpers)
|
29
28
|
#
|
30
29
|
# # good
|
31
30
|
# ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
|
32
|
-
# ::Chef::DSL::Resource.send(:include, Filebeat::Helpers)
|
33
31
|
#
|
34
32
|
class IncorrectLibraryInjection < Cop
|
35
|
-
MSG = 'Libraries should be injected into the Chef::DSL::Recipe
|
33
|
+
MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'.freeze
|
36
34
|
|
37
35
|
def_node_matcher :legacy_class_sends?, <<-PATTERN
|
38
|
-
(send (const (const (cbase) :Chef) {:Recipe :Provider
|
36
|
+
(send (const (const (cbase) :Chef) {:Recipe :Provider}) :send (sym :include) ... )
|
39
37
|
PATTERN
|
40
38
|
|
41
39
|
def on_send(node)
|
@@ -46,11 +44,7 @@ module RuboCop
|
|
46
44
|
|
47
45
|
def autocorrect(node)
|
48
46
|
lambda do |corrector|
|
49
|
-
|
50
|
-
new_val.gsub!(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe')
|
51
|
-
new_val.gsub!(/Chef::Resource/, 'Chef::DSL::Resource')
|
52
|
-
|
53
|
-
corrector.replace(node.loc.expression, new_val)
|
47
|
+
corrector.replace(node.loc.expression, node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
@@ -26,6 +26,10 @@ module RuboCop
|
|
26
26
|
# depends 'partial_search'
|
27
27
|
#
|
28
28
|
class CookbookDependsOnPartialSearch < Cop
|
29
|
+
extend TargetChefVersion
|
30
|
+
|
31
|
+
minimum_target_chef_version '13.0'
|
32
|
+
|
29
33
|
MSG = "Don't depend on the deprecated partial_search cookbook made obsolete by Chef 13".freeze
|
30
34
|
|
31
35
|
def_node_matcher :depends_partial_search?, <<-PATTERN
|
@@ -42,6 +42,9 @@ module RuboCop
|
|
42
42
|
#
|
43
43
|
class DeprecatedYumRepositoryProperties < Cop
|
44
44
|
include RuboCop::Chef::CookbookHelpers
|
45
|
+
extend TargetChefVersion
|
46
|
+
|
47
|
+
minimum_target_chef_version '12.14'
|
45
48
|
|
46
49
|
MSG = 'With the release of Chef Infra Client 12.14 and the yum cookbook 3.0 several properties in the yum_repository resource were renamed. url -> baseurl, keyurl -> gpgkey, and mirrorexpire -> mirror_expire.'.freeze
|
47
50
|
|
@@ -34,6 +34,9 @@ module RuboCop
|
|
34
34
|
#
|
35
35
|
class LaunchdDeprecatedHashProperty < Cop
|
36
36
|
include RuboCop::Chef::CookbookHelpers
|
37
|
+
extend TargetChefVersion
|
38
|
+
|
39
|
+
minimum_target_chef_version '12.19'
|
37
40
|
|
38
41
|
MSG = "The launchd resource's hash property was renamed to plist_hash in Chef Infra Client 13+ to avoid conflicts with Ruby's hash class.".freeze
|
39
42
|
|
@@ -34,6 +34,9 @@ module RuboCop
|
|
34
34
|
#
|
35
35
|
class VerifyPropertyUsesFileExpansion < Cop
|
36
36
|
include RuboCop::Chef::CookbookHelpers
|
37
|
+
extend TargetChefVersion
|
38
|
+
|
39
|
+
minimum_target_chef_version '12.5'
|
37
40
|
|
38
41
|
MSG = "Use the 'path' variable in the verify property and not the 'file' variable which was removed in Chef Infra Client 13.".freeze
|
39
42
|
|
@@ -41,6 +41,9 @@ module RuboCop
|
|
41
41
|
#
|
42
42
|
class WindowsTaskChangeAction < Cop
|
43
43
|
include RuboCop::Chef::CookbookHelpers
|
44
|
+
extend TargetChefVersion
|
45
|
+
|
46
|
+
minimum_target_chef_version '13.0'
|
44
47
|
|
45
48
|
MSG = 'The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+. The default action of :create should can now be used to create an update tasks.'.freeze
|
46
49
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# 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 ChefRedundantCode
|
21
|
+
# Use the :create_if_missing action instead of not_if with a ::File.exist(FOO) check.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# cookbook_file '/logs/foo/error.log' do
|
27
|
+
# source 'error.log'
|
28
|
+
# owner 'root'
|
29
|
+
# group 'root'
|
30
|
+
# mode '0644'
|
31
|
+
# not_if { ::File.exists?('/logs/foo/error.log') }
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# cookbook_file '/logs/foo/error.log' do
|
36
|
+
# source 'error.log'
|
37
|
+
# owner 'root'
|
38
|
+
# group 'root'
|
39
|
+
# mode '0644'
|
40
|
+
# action :create_if_missing
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
class UseCreateIfMissing < Cop
|
44
|
+
include RuboCop::Chef::CookbookHelpers
|
45
|
+
MSG = 'Use the :create_if_missing action instead of not_if with a ::File.exist(FOO) check.'.freeze
|
46
|
+
|
47
|
+
def_node_matcher :not_if_file_exist?, <<-PATTERN
|
48
|
+
(block (send nil? :not_if) (args) (send (const {nil? (cbase)} :File) {:exist? :exists?} $(str ...)))
|
49
|
+
PATTERN
|
50
|
+
|
51
|
+
def_node_matcher :file_like_resource?, <<-PATTERN
|
52
|
+
(block (send nil? {:cookbook_file :file :remote_directory :cron_d :remote_file :template} $str) ... )
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
def_node_search :create_action?, '(send nil? :action $sym)'
|
56
|
+
|
57
|
+
def on_block(node)
|
58
|
+
not_if_file_exist?(node) do |props|
|
59
|
+
file_like_resource?(node.parent.parent) do |resource_blk_name|
|
60
|
+
# the not_if file name is the same as the resource name and there's no action defined (it's the default)
|
61
|
+
if props == resource_blk_name && create_action?(node.parent.parent).nil?
|
62
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def autocorrect(node)
|
69
|
+
lambda do |corrector|
|
70
|
+
corrector.replace(node.loc.expression, 'action :create_if_missing')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# 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 ChefStyle
|
21
|
+
# Use not_if instead of only_if that negates the Ruby statement with a !
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# package 'legacy-sysv-deps' do
|
27
|
+
# only_if { !systemd }
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# package 'legacy-sysv-deps' do
|
32
|
+
# not_if { systemd }
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
class NegatingOnlyIf < Cop
|
36
|
+
MSG = 'Use not_if instead of only_if that negates the Ruby statement with a !'.freeze
|
37
|
+
|
38
|
+
def_node_matcher :negated_only_if?, <<-PATTERN
|
39
|
+
(block
|
40
|
+
$(send nil? :only_if)
|
41
|
+
(args)
|
42
|
+
$(send
|
43
|
+
$(...) :!))
|
44
|
+
PATTERN
|
45
|
+
|
46
|
+
def on_block(node)
|
47
|
+
negated_only_if?(node) do |_only_if, code|
|
48
|
+
# the value was double negated to work around types: ex: !!systemd?
|
49
|
+
return if code.descendants.first.negation_method?
|
50
|
+
|
51
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def autocorrect(node)
|
56
|
+
negated_only_if?(node) do |only_if, code|
|
57
|
+
lambda do |corrector|
|
58
|
+
corrector.replace(code.loc.expression, code.source.gsub(/^!/, ''))
|
59
|
+
corrector.replace(only_if.source_range, 'not_if')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookstyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom May
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03
|
12
|
+
date: 2020-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.81.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.81.0
|
28
28
|
description:
|
29
29
|
email:
|
30
30
|
- thom@chef.io
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/rubocop/cop/chef/redundant/suggests_metadata.rb
|
213
213
|
- lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb
|
214
214
|
- lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb
|
215
|
+
- lib/rubocop/cop/chef/redundant/use_create_if_missing.rb
|
215
216
|
- lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb
|
216
217
|
- lib/rubocop/cop/chef/sharing/empty_metadata_field.rb
|
217
218
|
- lib/rubocop/cop/chef/sharing/include_property_descriptions.rb
|
@@ -226,6 +227,7 @@ files:
|
|
226
227
|
- lib/rubocop/cop/chef/style/comments_format.rb
|
227
228
|
- lib/rubocop/cop/chef/style/file_mode.rb
|
228
229
|
- lib/rubocop/cop/chef/style/immediate_notification_timing.rb
|
230
|
+
- lib/rubocop/cop/chef/style/negating_only_if.rb
|
229
231
|
- lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb
|
230
232
|
- lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb
|
231
233
|
- lib/rubocop/cop/chef/style/true_false_resource_properties.rb
|