cookstyle 7.18.0 → 7.22.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/config/cookstyle.yml +122 -5
  3. data/config/disable_all.yml +2 -0
  4. data/config/upstream.yml +24 -2
  5. data/cookstyle.gemspec +1 -1
  6. data/lib/cookstyle/version.rb +2 -2
  7. data/lib/rubocop/cop/chef/correctness/metadata_malformed_version.rb +1 -1
  8. data/lib/rubocop/cop/chef/correctness/powershell_file_exists.rb +50 -0
  9. data/lib/rubocop/cop/chef/deprecation/chef_sugar_helpers.rb +2 -2
  10. data/lib/rubocop/cop/chef/deprecation/depends_chef_nginx_cookbook.rb +54 -0
  11. data/lib/rubocop/cop/chef/deprecation/depends_chef_reporting_cookbook.rb +51 -0
  12. data/lib/rubocop/cop/chef/deprecation/depends_omnibus_updater_cookbook.rb +54 -0
  13. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +2 -2
  14. data/lib/rubocop/cop/chef/deprecation/hwrp_without_unified_mode_true.rb +1 -1
  15. data/lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb +1 -1
  16. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +2 -2
  17. data/lib/rubocop/cop/chef/modernize/chef_15_resources.rb +57 -0
  18. data/lib/rubocop/cop/chef/modernize/depends_chef_vault_cookbook.rb +54 -0
  19. data/lib/rubocop/cop/chef/modernize/depends_chocolatey_cookbooks.rb +55 -0
  20. data/lib/rubocop/cop/chef/modernize/depends_kernel_module_cookbook.rb +54 -0
  21. data/lib/rubocop/cop/chef/modernize/depends_locale_cookbook.rb +54 -0
  22. data/lib/rubocop/cop/chef/modernize/depends_openssl_cookbook.rb +54 -0
  23. data/lib/rubocop/cop/chef/modernize/depends_timezone_lwrp_cookbook.rb +54 -0
  24. data/lib/rubocop/cop/chef/modernize/depends_windows_firewall_cookbook.rb +54 -0
  25. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +4 -2
  26. data/lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb +90 -0
  27. data/lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb +66 -0
  28. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +3 -3
  29. metadata +19 -5
@@ -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
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Deprecations
22
- # Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version values so it's always best to be less specific ie. 10 instead of 10.3
22
+ # Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version values so it's always best to be less specific ie. 10 instead of 10.3
23
23
  #
24
24
  # @example
25
25
  #
@@ -29,7 +29,7 @@ module RuboCop
29
29
  include RuboCop::Chef::CookbookHelpers
30
30
  extend AutoCorrector
31
31
 
32
- MSG = "Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version so it's always best to be less specific ie. 10 instead of 10.3"
32
+ MSG = "Use currently supported platforms in ChefSpec listed at https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version so it's always best to be less specific ie. 10 instead of 10.3"
33
33
 
34
34
  DEPRECATED_MAPPING = {
35
35
  'amazon' => {
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Deprecations
22
- # Chef Infra Client 15.3 and later include a new Unified Mode that simplies the execution of resoures by replace the traditional compile and converge phases with a single phase. Unified mode simplies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will beging warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
22
+ # Chef Infra Client 15.3 and later include a new Unified Mode that simplifies the execution of resources by replace the traditional compile and converge phases with a single phase. Unified mode simplifies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will begin warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
23
23
  #
24
24
  # @example
25
25
  #
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Deprecations
22
- # Chef Infra Client 15.3 and later include a new Unified Mode that simplies the execution of resoures by replace the traditional compile and converge phases with a single phase. Unified mode simplies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will beging warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
22
+ # Chef Infra Client 15.3 and later include a new Unified Mode that simplifies the execution of resources by replace the traditional compile and converge phases with a single phase. Unified mode simplies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will begin warning that `unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.
23
23
  #
24
24
  # @example
25
25
  #
@@ -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