cookstyle 7.17.0 → 7.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/config/cookstyle.yml +122 -3
  3. data/lib/cookstyle/version.rb +1 -1
  4. data/lib/rubocop/cop/chef/correctness/metadata_malformed_version.rb +1 -1
  5. data/lib/rubocop/cop/chef/correctness/powershell_file_exists.rb +50 -0
  6. data/lib/rubocop/cop/chef/deprecation/depends_chef_nginx_cookbook.rb +54 -0
  7. data/lib/rubocop/cop/chef/deprecation/depends_chef_reporting_cookbook.rb +51 -0
  8. data/lib/rubocop/cop/chef/deprecation/depends_omnibus_updater_cookbook.rb +54 -0
  9. data/lib/rubocop/cop/chef/deprecation/deprecated_sudo_actions.rb +65 -0
  10. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +2 -2
  11. data/lib/rubocop/cop/chef/modernize/chef_15_resources.rb +57 -0
  12. data/lib/rubocop/cop/chef/modernize/depends_chef_vault_cookbook.rb +54 -0
  13. data/lib/rubocop/cop/chef/modernize/depends_chocolatey_cookbooks.rb +55 -0
  14. data/lib/rubocop/cop/chef/modernize/depends_kernel_module_cookbook.rb +54 -0
  15. data/lib/rubocop/cop/chef/modernize/depends_locale_cookbook.rb +54 -0
  16. data/lib/rubocop/cop/chef/modernize/depends_openssl_cookbook.rb +54 -0
  17. data/lib/rubocop/cop/chef/modernize/depends_timezone_lwrp_cookbook.rb +54 -0
  18. data/lib/rubocop/cop/chef/modernize/depends_windows_firewall_cookbook.rb +54 -0
  19. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +4 -2
  20. data/lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb +86 -0
  21. data/lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb +66 -0
  22. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +3 -3
  23. metadata +22 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c717dffb3528a52a96f90cdfc26f3230a0b621314b1ede81ee2bc907f6e6afa
4
- data.tar.gz: 6ffb9d37305d351d6c0512dd070516ebb8d741ba178358cdf38c05ae4c470d4f
3
+ metadata.gz: 48e9eba9990f29d5ece83efea73a5ceba5c49ed781909b437c40c43da790210a
4
+ data.tar.gz: 9f177a0a2cadc3cb703ec87337bd4485e872ae748d9af95f53473dec22eebd7d
5
5
  SHA512:
6
- metadata.gz: 2eb06bb46004aa146557e2aae9b95065ad238820b5e832c2bad1fe7c13ce652d43adfd3a18073051b4a575ddfd54b719cd2c5af93e1557fac6e8b987d5801392
7
- data.tar.gz: ccf7386507af4bee4e860a40ecc82e0e5a916de30eb3cc2d3e1a4550736f541018546310779c347b0e18db6c9afca6294840d3ed9ee86ab19070d0bf423dbf2e
6
+ metadata.gz: fbeebdde748ba5abca797bf203ab8465c74e1b1714847d27e35576b3801daae3e962b9bfb3516c84f684e69a3088535d8811ea7df74005f6262005bb844295a7
7
+ data.tar.gz: 4e3c683249684fdae3717f88b9ea92c9eb26147d55eb90e43e024f7c0ce03870d03c66b4f2c7ad6eb9c057cf1eb687ce28ed44efea7b2a61e5a9002b3b143628
data/config/cookstyle.yml CHANGED
@@ -482,13 +482,22 @@ Chef/Correctness/OctalModeAsString:
482
482
  - '**/Berksfile'
483
483
 
484
484
  Chef/Correctness/MetadataMalformedDepends:
485
- Description: Don't represent file modes as strings containing octal values. Use standard base 10 file modes instead.
485
+ Description: metadata.rb cookbook dependencies and version constraints should be comma separated.
486
486
  StyleGuide: 'chef_correctness_metadatamalformeddepends'
487
487
  Enabled: true
488
488
  VersionAdded: '7.16'
489
489
  Include:
490
490
  - '**/metadata.rb'
491
491
 
492
+ Chef/Correctness/PowershellFileExists:
493
+ Description: Use Ruby's built-in `File.exist?('C:\somefile')` method instead of executing PowerShell's `Test-Path` cmdlet, which takes longer to load.
494
+ StyleGuide: 'chef_correctness_powershellfileexists'
495
+ Enabled: true
496
+ VersionAdded: '7.19'
497
+ Exclude:
498
+ - '**/metadata.rb'
499
+ - '**/Berksfile'
500
+
492
501
  ###############################
493
502
  # Chef/Sharing: Issues that prevent sharing code with other teams or with the Chef community in general
494
503
  ###############################
@@ -1225,6 +1234,42 @@ Chef/Deprecations/PolicyfileCommunitySource:
1225
1234
  Include:
1226
1235
  - '**/Policyfile.rb'
1227
1236
 
1237
+ Chef/Deprecations/DeprecatedSudoActions:
1238
+ Description: The `sudo` resource in the sudo cookbook 5.0 (2018) or Chef Infra Client 14 and later have replaced the existing `:install` and `:remove` actions with `:create` and `:delete` actions to better match other resources in Chef Infra.
1239
+ StyleGuide: 'chef_deprecations_deprecatedsudoactions'
1240
+ Enabled: true
1241
+ VersionAdded: '7.18.0'
1242
+ Exclude:
1243
+ - '**/spec/**/*.rb'
1244
+ - '**/metadata.rb'
1245
+ - '**/attributes/*.rb'
1246
+ - '**/Berksfile'
1247
+ - '**/Rakefile'
1248
+
1249
+ Chef/Deprecations/DependsOnChefNginxCookbook:
1250
+ Description: Don't depend on the deprecated `chef_nginx` cookbook that was replaced by the `nginx` cookbook. The legacy chef_nginx cookbook may not be compatible with newer Chef Infra Client releases.
1251
+ StyleGuide: 'chef_deprecations_dependsonchefnginxcookbook'
1252
+ Enabled: true
1253
+ VersionAdded: '7.20.0'
1254
+ Include:
1255
+ - '**/metadata.rb'
1256
+
1257
+ Chef/Deprecations/DependsOnChefReportingCookbook:
1258
+ Description: Don't depend on the chef-reporting cookbook made obsolete by Chef Infra Client 11.6. This cookbook installs a gem that is not compatible with newer Chef Infra Client releases.
1259
+ StyleGuide: 'chef_deprecations_dependsonchefreportingcookbook'
1260
+ Enabled: true
1261
+ VersionAdded: '7.20.0'
1262
+ Include:
1263
+ - '**/metadata.rb'
1264
+
1265
+ Chef/Deprecations/DependsOnOmnibusUpdaterCookbook:
1266
+ Description: Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced with the more reliable `chef_client_updater` cookbook.
1267
+ StyleGuide: 'chef_deprecations_dependsonomnibusupdatercookbook'
1268
+ Enabled: true
1269
+ VersionAdded: '7.20.0'
1270
+ Include:
1271
+ - '**/metadata.rb'
1272
+
1228
1273
  ###############################
1229
1274
  # Chef/Modernize: Cleaning up legacy code and using new built-in resources
1230
1275
  ###############################
@@ -1251,7 +1296,7 @@ Chef/Modernize/WhyRunSupportedTrue:
1251
1296
  - '**/libraries/*.rb'
1252
1297
 
1253
1298
  Chef/Modernize/UnnecessaryDependsChef14:
1254
- Description: Don't depend on cookbooks made obsolete by Chef Infra Client 14+. These community cookbooks contain resources that are now included in Chef Infra Client itself.
1299
+ Description: Don't depend on cookbooks made obsolete by Chef Infra Client 14.0+. These community cookbooks contain resources that are now included in Chef Infra Client itself.
1255
1300
  StyleGuide: 'chef_modernize_unnecessarydependschef14'
1256
1301
  Enabled: true
1257
1302
  VersionAdded: '5.1.0'
@@ -1377,7 +1422,7 @@ Chef/Modernize/SevenZipArchiveResource:
1377
1422
  - '**/metadata.rb'
1378
1423
 
1379
1424
  Chef/Modernize/LibarchiveFileResource:
1380
- Description: Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource
1425
+ Description: Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource from the libarchive cookbook
1381
1426
  StyleGuide: 'chef_modernize_libarchivefileresource'
1382
1427
  Enabled: true
1383
1428
  VersionAdded: '5.5.0'
@@ -1787,6 +1832,80 @@ Chef/Modernize/ActionMethodInResource:
1787
1832
  - '**/resources/*.rb'
1788
1833
  - '**/providers/*.rb'
1789
1834
 
1835
+ Chef/Modernize/UnnecessaryDependsChef15:
1836
+ Description: Don't depend on cookbooks made obsolete by Chef Infra Client 15.0+. These community cookbooks contain resources that are now included in Chef Infra Client itself.
1837
+ StyleGuide: 'chef_modernize_unnecessarydependschef15'
1838
+ Enabled: true
1839
+ VersionAdded: '7.19.0'
1840
+ Include:
1841
+ - '**/metadata.rb'
1842
+
1843
+ Chef/Modernize/DependsOnLocaleCookbook:
1844
+ Description: Don't depend on the locale cookbook made obsolete by Chef Infra Client 14.5. The locale resource is now included in Chef Infra Client itself.
1845
+ StyleGuide: 'chef_modernize_dependsonlocalecookbook'
1846
+ Enabled: true
1847
+ VersionAdded: '7.19.0'
1848
+ Include:
1849
+ - '**/metadata.rb'
1850
+
1851
+ Chef/Modernize/DependsOnTimezoneLwrpCookbook:
1852
+ Description: Don't depend on the timezone_lwrp cookbook made obsolete by Chef Infra Client 14.6. The timezone resource is now included in Chef Infra Client itself.
1853
+ StyleGuide: 'chef_modernize_dependsontimezonelwrpcookbook'
1854
+ Enabled: true
1855
+ VersionAdded: '7.19.0'
1856
+ Include:
1857
+ - '**/metadata.rb'
1858
+
1859
+ Chef/Modernize/DependsOnWindowsFirewallCookbook:
1860
+ Description: Don't depend on the windows_firewall cookbook made obsolete by Chef Infra Client 14.7. The windows_firewall resource is now included in Chef Infra Client itself.
1861
+ StyleGuide: 'chef_modernize_dependsonwindowsfirewallcookbook'
1862
+ Enabled: true
1863
+ VersionAdded: '7.19.0'
1864
+ Include:
1865
+ - '**/metadata.rb'
1866
+
1867
+ Chef/Modernize/DependsOnKernelModuleCookbook:
1868
+ Description: Don't depend on the kernel_module cookbook made obsolete by Chef Infra Client 14.3. The kernel_module resource is now included in Chef Infra Client itself.
1869
+ StyleGuide: 'chef_modernize_dependsonkernelmodulecookbook'
1870
+ Enabled: true
1871
+ VersionAdded: '7.19.0'
1872
+ Include:
1873
+ - '**/metadata.rb'
1874
+
1875
+ Chef/Modernize/DependsOnChefVaultCookbook:
1876
+ Description: Don't depend on the chef-vault cookbook made obsolete by Chef Infra Client 16.0. The chef-vault gem and helpers are now included in Chef Infra Client itself.
1877
+ StyleGuide: 'chef_modernize_dependsonchefvaultcookbook'
1878
+ Enabled: true
1879
+ VersionAdded: '7.20.0'
1880
+ Include:
1881
+ - '**/metadata.rb'
1882
+
1883
+ Chef/Modernize/DependsOnChocolateyCookbooks:
1884
+ Description: Don't depend on the chocolatey_source or chocolatey_config cookbooks made obsolete by Chef Infra Client 14.3. The chocolatey_source and chocolatey_config resources are now included in Chef Infra Client itself.
1885
+ StyleGuide: 'chef_modernize_dependsonchocolateycookbooks'
1886
+ Enabled: true
1887
+ VersionAdded: '7.20.0'
1888
+ Include:
1889
+ - '**/metadata.rb'
1890
+
1891
+ Chef/Modernize/DependsOnOpensslCookbook:
1892
+ Description: Don't depend on the `openssl` cookbook which was made obsolete by Chef Infra Client 14.4. All `openssl_*` resources are now included directly in Chef Infra Client.
1893
+ StyleGuide: 'chef_modernize_dependsonopensslcookbook'
1894
+ Enabled: true
1895
+ VersionAdded: '7.20.0'
1896
+ Include:
1897
+ - '**/metadata.rb'
1898
+
1899
+ Chef/Modernize/UseChefLanguageEnvHelpers:
1900
+ Description: Chef Infra Client 15.5 and later include a large number of new helpers in the Chef Infra Language to simplify checking the system configuration in recipes and resources. These should be used when possible over more complex attribute or ENV var comparisons.
1901
+ StyleGuide: 'chef_modernize_usecheflanguageenvhelpers'
1902
+ Enabled: true
1903
+ VersionAdded: '7.21.0'
1904
+ Include:
1905
+ - '**/resources/*.rb'
1906
+ - '**/providers/*.rb'
1907
+ - '**/recipes/*.rb'
1908
+
1790
1909
  ###############################
1791
1910
  # Chef/RedundantCode: Cleanup unnecessary code in your cookbooks regardless of Chef Infra Client release
1792
1911
  ###############################
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "7.17.0" # rubocop: disable Style/StringLiterals
3
+ VERSION = "7.21.0" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '1.19.0'
5
5
  end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Correctness
22
- # metadata.rb cookbook dependencies and version constraints should be comma separated
22
+ # metadata.rb cookbook dependencies and version constraints should be comma separated.
23
23
  #
24
24
  # @example
25
25
  #
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Correctness
22
+ # Use Ruby's built-in `File.exist?('C:\somefile')` method instead of executing PowerShell's `Test-Path` cmdlet, which takes longer to load.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # powershell_out('Test-Path "C:\\Program Files\\LAPS\\CSE\\AdmPwd.dll"').stdout.strip == 'True'
28
+ #
29
+ # #### correct
30
+ # ::File.exist?('C:\Program Files\LAPS\CSE\AdmPwd.dll')
31
+ #
32
+ class PowershellFileExists < Base
33
+ RESTRICT_ON_SEND = [:powershell_out, :powershell_out!].freeze
34
+ MSG = "Use Ruby's built-in `File.exist?('C:\\somefile')` method instead of executing PowerShell's `Test-Path` cmdlet, which takes longer to load."
35
+
36
+ def_node_matcher :powershell_out_exists?, <<-PATTERN
37
+ (send nil? {:powershell_out :powershell_out!} (str $_))
38
+ PATTERN
39
+
40
+ def on_send(node)
41
+ powershell_out_exists?(node) do |exists_string|
42
+ return unless exists_string.match?(/^Test-Path/)
43
+ add_offense(node, message: MSG, severity: :refactor)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Deprecations
22
+ # Don't depend on the deprecated `chef_nginx` cookbook that was replaced by the `nginx` cookbook. The legacy chef_nginx cookbook may not be compatible with newer Chef Infra Client releases.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'chef_nginx'
28
+ #
29
+ # #### correct
30
+ # depends 'nginx'
31
+ #
32
+ class DependsOnChefNginxCookbook < Base
33
+ include RangeHelp
34
+ extend AutoCorrector
35
+
36
+ MSG = "Don't depend on the deprecated `chef_nginx` cookbook that was replaced by the `nginx` cookbook."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :depends_compat_resource?, <<-PATTERN
40
+ (send nil? :depends (str {"chef_nginx"}))
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ depends_compat_resource?(node) do
45
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Deprecations
22
+ # Don't depend on the chef-reporting cookbook made obsolete by Chef Infra Client 11.6. This cookbook installs a gem that is not compatible with newer Chef Infra Client releases.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'chef-reporting'
28
+ #
29
+ class DependsOnChefReportingCookbook < Base
30
+ extend AutoCorrector
31
+ include RangeHelp
32
+
33
+ MSG = "Don't depend on the chef-reporting cookbook made obsolete by Chef Infra Client 11.6. This cookbook installs a gem that is not compatible with newer Chef Infra Client releases."
34
+ RESTRICT_ON_SEND = [:depends].freeze
35
+
36
+ def_node_matcher :legacy_depends?, <<-PATTERN
37
+ (send nil? :depends (str "chef-reporting") ... )
38
+ PATTERN
39
+
40
+ def on_send(node)
41
+ legacy_depends?(node) do
42
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
43
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Deprecations
22
+ # Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced with the more reliable `chef_client_updater` cookbook.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'omnibus_updater'
28
+ #
29
+ # #### correct
30
+ # depends 'chef_client_updater'
31
+ #
32
+ class DependsOnOmnibusUpdaterCookbook < Base
33
+ extend AutoCorrector
34
+ include RangeHelp
35
+
36
+ MSG = "Don't depend on the EOL `omnibus_updater` cookbook. This cookbook no longer works with newer Chef Infra Client releases and has been replaced with the more reliable `chef_client_updater` cookbook."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "omnibus_updater") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Deprecations
22
+ # The `sudo` resource in the sudo cookbook 5.0 (2018) or Chef Infra Client 14 and later have replaced the existing `:install` and `:remove` actions with `:create` and `:delete` actions to better match other resources in Chef Infra.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # sudo 'admins' do
28
+ # users 'bob'
29
+ # groups 'sysadmins, superusers'
30
+ # action :remove
31
+ # end
32
+ #
33
+ # #### correct
34
+ # sudo 'admins' do
35
+ # users 'bob'
36
+ # groups 'sysadmins, superusers'
37
+ # action :delete
38
+ # end
39
+ #
40
+ class DeprecatedSudoActions < Base
41
+ include RuboCop::Chef::CookbookHelpers
42
+ extend TargetChefVersion
43
+ extend AutoCorrector
44
+
45
+ minimum_target_chef_version '14.0'
46
+
47
+ MSG = 'The `sudo` resource in the sudo cookbook 5.0 (2018) or Chef Infra Client 14 and later have replaced the existing `:install` and `:remove` actions with `:create` and `:delete` actions to better match other resources in Chef Infra.'
48
+
49
+ def on_block(node)
50
+ match_property_in_resource?(:sudo, 'action', node) do |prop_node|
51
+ next unless prop_node.arguments.first.sym_type?
52
+ next unless [s(:sym, :install), s(:sym, :remove)].include?(prop_node.arguments.first)
53
+
54
+ add_offense(prop_node, message: MSG, severity: :warning) do |corrector|
55
+ corrector.replace(prop_node, prop_node.source
56
+ .gsub('install', 'create')
57
+ .gsub('remove', 'delete'))
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Modernize
22
- # Don't depend on cookbooks made obsolete by Chef Infra Client 14+. These community cookbooks contain resources that are now included in Chef Infra Client itself.
22
+ # Don't depend on cookbooks made obsolete by Chef Infra Client 14.0+ These community cookbooks contain resources that are now included in Chef Infra Client itself.
23
23
  #
24
24
  # @example
25
25
  #
@@ -39,7 +39,7 @@ module RuboCop
39
39
 
40
40
  minimum_target_chef_version '14.0'
41
41
 
42
- MSG = "Don't depend on cookbooks made obsolete by Chef Infra Client 14+. These community cookbooks contain resources that are now included in Chef Infra Client itself."
42
+ MSG = "Don't depend on cookbooks made obsolete by Chef Infra Client 14.0+. These community cookbooks contain resources that are now included in Chef Infra Client itself."
43
43
  RESTRICT_ON_SEND = [:depends].freeze
44
44
 
45
45
  def_node_matcher :legacy_depends?, <<-PATTERN
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on cookbooks made obsolete by Chef Infra Client 15.0+. These community cookbooks contain resources that are now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'libarchive'
28
+ # depends 'windows_dns'
29
+ # depends 'windows_uac'
30
+ # depends 'windows_dfs'
31
+ #
32
+ class UnnecessaryDependsChef15 < Base
33
+ extend AutoCorrector
34
+ extend TargetChefVersion
35
+ include RangeHelp
36
+
37
+ minimum_target_chef_version '15.0'
38
+
39
+ MSG = "Don't depend on cookbooks made obsolete by Chef Infra Client 15.0+. These community cookbooks contain resources that are now included in Chef Infra Client itself."
40
+ RESTRICT_ON_SEND = [:depends].freeze
41
+
42
+ def_node_matcher :legacy_depends?, <<-PATTERN
43
+ (send nil? :depends (str {"libarchive" "windows_dns" "windows_uac" "windows_dfs"}) ... )
44
+ PATTERN
45
+
46
+ def on_send(node)
47
+ legacy_depends?(node) do
48
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
49
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the chef-vault cookbook made obsolete by Chef Infra Client 16.0. The chef-vault gem and helpers are now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'chef-vault'
28
+ #
29
+ class DependsOnChefVaultCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '16.0'
35
+
36
+ MSG = "Don't depend on the chef-vault cookbook made obsolete by Chef Infra Client 16.0. The chef-vault gem and helpers are now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "chef-vault") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the chocolatey_source or chocolatey_config cookbooks made obsolete by Chef Infra Client 14.3. The chocolatey_source and chocolatey_config resources are now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'chocolatey_source'
28
+ # depends 'chocolatey_config'
29
+ #
30
+ class DependsOnChocolateyCookbooks < Base
31
+ extend AutoCorrector
32
+ extend TargetChefVersion
33
+ include RangeHelp
34
+
35
+ minimum_target_chef_version '14.3'
36
+
37
+ MSG = "Don't depend on the chocolatey_source or chocolatey_config cookbooks made obsolete by Chef Infra Client 14.3. The chocolatey_source and chocolatey_config resources are now included in Chef Infra Client itself."
38
+ RESTRICT_ON_SEND = [:depends].freeze
39
+
40
+ def_node_matcher :legacy_depends?, <<-PATTERN
41
+ (send nil? :depends (str {"chocolatey_source" "chocolatey_config"}) ... )
42
+ PATTERN
43
+
44
+ def on_send(node)
45
+ legacy_depends?(node) do
46
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
47
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the kernel_module cookbook made obsolete by Chef Infra Client 14.3. The kernel_module resource is now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'kernel_module'
28
+ #
29
+ class DependsOnKernelModuleCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.3'
35
+
36
+ MSG = "Don't depend on the kernel_module cookbook made obsolete by Chef Infra Client 14.3. The kernel_module resource is now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "kernel_module") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the locale cookbook made obsolete by Chef Infra Client 14.5. The locale resource is now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'locale'
28
+ #
29
+ class DependsOnLocaleCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.5'
35
+
36
+ MSG = "Don't depend on the locale cookbook made obsolete by Chef Infra Client 14.5. The locale resource is now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "locale") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the `openssl` cookbook which was made obsolete by Chef Infra Client 14.4. All `openssl_*` resources are now included directly in Chef Infra Client.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'openssl'
28
+ #
29
+ class DependsOnOpensslCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.4'
35
+
36
+ MSG = "Don't depend on the `openssl` cookbook which was made obsolete by Chef Infra Client 14.4. All `openssl_*` resources are now included directly in Chef Infra Client."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "openssl") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the timezone_lwrp cookbook made obsolete by Chef Infra Client 14.6. The timezone resource is now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'timezone_lwrp'
28
+ #
29
+ class DependsOnTimezoneLwrpCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.6'
35
+
36
+ MSG = "Don't depend on the timezone_lwrp cookbook made obsolete by Chef Infra Client 14.6. The timezone resource is now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "timezone_lwrp") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the windows_firewall cookbook made obsolete by Chef Infra Client 14.7. The windows_firewall resource is now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'windows_firewall'
28
+ #
29
+ class DependsOnWindowsFirewallCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.7'
35
+
36
+ MSG = "Don't depend on the windows_firewall cookbook made obsolete by Chef Infra Client 14.7. The windows_firewall resource is now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "windows_firewall") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -19,11 +19,13 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Modernize
22
- # Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive_file resource.
22
+ # Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive_file resource from the libarchive cookbook.
23
23
  #
24
24
  # @example
25
25
  #
26
26
  # #### incorrect
27
+ # depends 'libarchive'
28
+ #
27
29
  # libarchive_file "C:\file.zip" do
28
30
  # path 'C:\expand_here'
29
31
  # end
@@ -39,7 +41,7 @@ module RuboCop
39
41
 
40
42
  minimum_target_chef_version '15.0'
41
43
 
42
- MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource'
44
+ MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource from the libarchive cookbook'
43
45
  RESTRICT_ON_SEND = [:libarchive_file, :notifies, :subscribes].freeze
44
46
 
45
47
  def_node_matcher :notification_property?, <<-PATTERN
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Chef Infra Client 15.5 and later include cloud helpers to make detecting instance that run on public and private clouds easier.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # ENV['CI']
28
+ # ENV['TEST_KITCHEN']
29
+ #
30
+ # #### correct
31
+ # ci?
32
+ # kitchen?
33
+ #
34
+ class UseChefLanguageCloudHelpers < Base
35
+ extend AutoCorrector
36
+
37
+ MSG = 'Chef Infra Client 15.5 and later include cloud helpers to make detecting instance that run on public and private clouds easier.'.freeze
38
+ RESTRICT_ON_SEND = [:==, :[]].freeze
39
+ VALID_CLOUDS = %w(alibaba ec2 gce rackspace eucalyptus linode openstack azure digital_ocean softlayer).freeze
40
+
41
+ def_node_matcher :provider_comparison?, <<-PATTERN
42
+ (send
43
+ (send
44
+ (send
45
+ (send nil? :node) :[]
46
+ (str "cloud")) :[]
47
+ (str "provider")) :==
48
+ (str $_))
49
+ PATTERN
50
+
51
+ def_node_matcher :node_check?, <<-PATTERN
52
+ (send
53
+ (send nil? :node) :[]
54
+ (str ${"ec2"}))
55
+ PATTERN
56
+
57
+ def_node_matcher :node_cloud?, <<-PATTERN
58
+ (send
59
+ (send nil? :node) :[]
60
+ (str "cloud"))
61
+ PATTERN
62
+
63
+ def on_send(node)
64
+ node_check?(node) do |cloud_name|
65
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
66
+ corrector.replace(node, "#{cloud_name}?")
67
+ end
68
+ end
69
+
70
+ provider_comparison?(node) do |cloud_name|
71
+ # skip it if someone was checking for a bogus cloud provider
72
+ next unless VALID_CLOUDS.include?(cloud_name)
73
+
74
+ # if they were checking for node['cloud'] and the provider replace it all
75
+ node = node.parent if node.parent.and_type? && node_cloud?(node.left_sibling)
76
+
77
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
78
+ corrector.replace(node, "#{cloud_name}?")
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Chef Infra Client 15.5 and later include a large number of new helpers in the Chef Infra Language to simplify checking the system configuration in recipes and resources. These should be used when possible over more complex attribute or ENV var comparisons.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # ENV['CI']
28
+ # ENV['TEST_KITCHEN']
29
+ #
30
+ # #### correct
31
+ # ci?
32
+ # kitchen?
33
+ #
34
+ class UseChefLanguageEnvHelpers < Base
35
+ extend AutoCorrector
36
+
37
+ RESTRICT_ON_SEND = [:[]].freeze
38
+
39
+ def_node_matcher :env?, <<-PATTERN
40
+ (send
41
+ (const nil? :ENV) :[]
42
+ (str ${"TEST_KITCHEN" "CI"}))
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ env?(node) do |env_value|
47
+ # we don't handle .nil? checks yet so just skip them
48
+ next if node.parent.send_type? && node.parent.method_name == :nil?
49
+
50
+ case env_value
51
+ when 'CI'
52
+ add_offense(node, message: 'Chef Infra Client 15.5 and later include a helper `ci?` that should be used to see if the `CI` env var is set.', severity: :refactor) do |corrector|
53
+ corrector.replace(node, 'ci?')
54
+ end
55
+ when 'TEST_KITCHEN'
56
+ add_offense(node, message: 'Chef Infra Client 15.5 and later include a helper `kitchen?` that should be used to see if the `TEST_KITCHEN` env var is set.', severity: :refactor) do |corrector|
57
+ corrector.replace(node, 'kitchen?')
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Style
22
- # Use :immediately instead of :immediate for resource notification timing
22
+ # Use :immediately instead of :immediate for resource notification timing.
23
23
  #
24
24
  # @example
25
25
  #
@@ -39,10 +39,10 @@ module RuboCop
39
39
  extend AutoCorrector
40
40
 
41
41
  MSG = 'Use :immediately instead of :immediate for resource notification timing'
42
- RESTRICT_ON_SEND = [:notifies].freeze
42
+ RESTRICT_ON_SEND = [:notifies, :subscribes].freeze
43
43
 
44
44
  def_node_matcher :immediate_notify?, <<-PATTERN
45
- (send nil? :notifies (sym _) (...) $(sym :immediate))
45
+ (send nil? {:notifies :subscribes} (sym _) (...) $(sym :immediate))
46
46
  PATTERN
47
47
 
48
48
  def on_send(node)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.17.0
4
+ version: 7.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
8
8
  - Tim Smith
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-12 00:00:00.000000000 Z
12
+ date: 2021-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -25,7 +25,7 @@ dependencies:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.19.0
28
- description:
28
+ description:
29
29
  email:
30
30
  - thom@chef.io
31
31
  - tsmith@chef.io
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rubocop/cop/chef/correctness/octal_mode_as_string.rb
79
79
  - lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb
80
80
  - lib/rubocop/cop/chef/correctness/powershell_delete_file.rb
81
+ - lib/rubocop/cop/chef/correctness/powershell_file_exists.rb
81
82
  - lib/rubocop/cop/chef/correctness/property_without_type.rb
82
83
  - lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
83
84
  - lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
@@ -99,13 +100,17 @@ files:
99
100
  - lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb
100
101
  - lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb
101
102
  - lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb
103
+ - lib/rubocop/cop/chef/deprecation/depends_chef_nginx_cookbook.rb
104
+ - lib/rubocop/cop/chef/deprecation/depends_chef_reporting_cookbook.rb
102
105
  - lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb
106
+ - lib/rubocop/cop/chef/deprecation/depends_omnibus_updater_cookbook.rb
103
107
  - lib/rubocop/cop/chef/deprecation/depends_partial_search.rb
104
108
  - lib/rubocop/cop/chef/deprecation/depends_poise.rb
105
109
  - lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb
106
110
  - lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb
107
111
  - lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb
108
112
  - lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb
113
+ - lib/rubocop/cop/chef/deprecation/deprecated_sudo_actions.rb
109
114
  - lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb
110
115
  - lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_actions.rb
111
116
  - lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb
@@ -174,6 +179,7 @@ files:
174
179
  - lib/rubocop/cop/chef/modernize/berksfile_source.rb
175
180
  - lib/rubocop/cop/chef/modernize/build_essential.rb
176
181
  - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
182
+ - lib/rubocop/cop/chef/modernize/chef_15_resources.rb
177
183
  - lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
178
184
  - lib/rubocop/cop/chef/modernize/compile_time_resources.rb
179
185
  - lib/rubocop/cop/chef/modernize/conditional_using_test.rb
@@ -183,6 +189,13 @@ files:
183
189
  - lib/rubocop/cop/chef/modernize/default_action_initializer.rb
184
190
  - lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
185
191
  - lib/rubocop/cop/chef/modernize/definitions.rb
192
+ - lib/rubocop/cop/chef/modernize/depends_chef_vault_cookbook.rb
193
+ - lib/rubocop/cop/chef/modernize/depends_chocolatey_cookbooks.rb
194
+ - lib/rubocop/cop/chef/modernize/depends_kernel_module_cookbook.rb
195
+ - lib/rubocop/cop/chef/modernize/depends_locale_cookbook.rb
196
+ - lib/rubocop/cop/chef/modernize/depends_openssl_cookbook.rb
197
+ - lib/rubocop/cop/chef/modernize/depends_timezone_lwrp_cookbook.rb
198
+ - lib/rubocop/cop/chef/modernize/depends_windows_firewall_cookbook.rb
186
199
  - lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
187
200
  - lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb
188
201
  - lib/rubocop/cop/chef/modernize/empty_resource_initialize.rb
@@ -223,6 +236,8 @@ files:
223
236
  - lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb
224
237
  - lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb
225
238
  - lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb
239
+ - lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb
240
+ - lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb
226
241
  - lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb
227
242
  - lib/rubocop/cop/chef/modernize/use_require_relative.rb
228
243
  - lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
@@ -294,7 +309,7 @@ metadata:
294
309
  source_code_uri: https://github.com/chef/cookstyle
295
310
  documentation_uri: https://docs.chef.io/workstation/cookstyle/
296
311
  bug_tracker_uri: https://github.com/chef/cookstyle/issues
297
- post_install_message:
312
+ post_install_message:
298
313
  rdoc_options: []
299
314
  require_paths:
300
315
  - lib
@@ -309,8 +324,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
324
  - !ruby/object:Gem::Version
310
325
  version: '0'
311
326
  requirements: []
312
- rubygems_version: 3.1.4
313
- signing_key:
327
+ rubygems_version: 3.2.22
328
+ signing_key:
314
329
  specification_version: 4
315
330
  summary: Cookstyle is a code linting tool that helps you to write better Chef Infra
316
331
  cookbooks by detecting and automatically correcting style, syntax, and logic mistakes