cookstyle 7.10.0 → 7.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/cookstyle.yml +24 -7
- data/config/disable_all.yml +6 -0
- data/config/upstream.yml +31 -2
- data/cookstyle.gemspec +1 -1
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/invalid_default_action.rb +10 -11
- data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +0 -1
- data/lib/rubocop/cop/chef/correctness/metadata_missing_name.rb +9 -10
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +2 -6
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +2 -6
- data/lib/rubocop/cop/chef/correctness/node_save.rb +1 -3
- data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +1 -2
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb +1 -3
- data/lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb +0 -1
- data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +0 -1
- data/lib/rubocop/cop/chef/correctness/scoped_file_exist.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/service_resource.rb +0 -1
- data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +0 -1
- data/lib/rubocop/cop/chef/correctness/tmp_path.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/cb_depends_on_self.rb +11 -12
- data/lib/rubocop/cop/chef/deprecation/chef_handler_recipe.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +2 -5
- data/lib/rubocop/cop/chef/deprecation/chef_sugar_helpers.rb +22 -23
- data/lib/rubocop/cop/chef/deprecation/chefdk_generators.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/cheffile.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_actions.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_unified_mode_true.rb +86 -0
- data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/log_resource_notifications.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/macos_userdefaults_global_property.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb +84 -0
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +0 -1
- data/lib/rubocop/cop/chef/deprecation/{ use_automatic_resource_name.rb → use_automatic_resource_name.rb} +0 -0
- data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +0 -1
- data/lib/rubocop/cop/chef/effortless/berksfile.rb +0 -1
- data/lib/rubocop/cop/chef/effortless/chef_vault_used.rb +0 -2
- data/lib/rubocop/cop/chef/effortless/depends_chef_vault.rb +0 -2
- data/lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/foodcritic_comments.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/seven_zip_archive.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb +0 -1
- data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +31 -12
- data/lib/rubocop/cop/chef/modernize/zipfile_resource.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/attribute_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/conflicts_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/long_description_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/provides_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/recipe_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/replaces_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/suggests_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/sharing/empty_metadata_field.rb +0 -1
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +0 -1
- data/lib/rubocop/cop/chef/style/attribute_keys.rb +0 -1
- data/lib/rubocop/cop/chef/style/chef_whaaat.rb +0 -1
- data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +0 -1
- data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +0 -1
- data/lib/rubocop/cop/chef/style/comments_default_copyright.rb +0 -1
- data/lib/rubocop/cop/chef/style/comments_format.rb +0 -1
- data/lib/rubocop/cop/chef/style/file_mode.rb +0 -1
- data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +0 -1
- metadata +8 -6
@@ -15,12 +15,11 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
19
18
|
module RuboCop
|
20
19
|
module Cop
|
21
20
|
module Chef
|
22
21
|
module Deprecations
|
23
|
-
#
|
22
|
+
# Use `ignore_failure` in resources to continue when failures occur instead of the deprecated `epic_fail` property.
|
24
23
|
#
|
25
24
|
# @example
|
26
25
|
#
|
@@ -37,7 +36,7 @@ module RuboCop
|
|
37
36
|
class EpicFail < Base
|
38
37
|
extend AutoCorrector
|
39
38
|
|
40
|
-
MSG = 'Use ignore_failure
|
39
|
+
MSG = 'Use `ignore_failure` in resources to continue when failures occur instead of the deprecated `epic_fail` property'
|
41
40
|
RESTRICT_ON_SEND = [:epic_fail].freeze
|
42
41
|
|
43
42
|
def on_send(node)
|
@@ -15,12 +15,11 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
19
18
|
module RuboCop
|
20
19
|
module Cop
|
21
20
|
module Chef
|
22
21
|
module Deprecations
|
23
|
-
# Don't use the deprecated erl_call resource
|
22
|
+
# Don't use the deprecated `erl_call` resource removed in Chef Infra Client 13."
|
24
23
|
#
|
25
24
|
# @example
|
26
25
|
#
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 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
|
+
# 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.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# #### incorrect
|
27
|
+
# class Chef
|
28
|
+
# class Resource
|
29
|
+
# class UlimitRule < Chef::Resource
|
30
|
+
# provides :ulimit_rule
|
31
|
+
#
|
32
|
+
# property :type, [Symbol, String], required: true
|
33
|
+
# property :item, [Symbol, String], required: true
|
34
|
+
#
|
35
|
+
# # additional resource code
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# #### correct
|
41
|
+
# class Chef
|
42
|
+
# class Resource
|
43
|
+
# class UlimitRule < Chef::Resource
|
44
|
+
# provides :ulimit_rule
|
45
|
+
# unified_mode true
|
46
|
+
#
|
47
|
+
# property :type, [Symbol, String], required: true
|
48
|
+
# property :item, [Symbol, String], required: true
|
49
|
+
#
|
50
|
+
# # additional resource code
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
class HWRPWithoutUnifiedTrue < Base
|
56
|
+
extend TargetChefVersion
|
57
|
+
|
58
|
+
minimum_target_chef_version '15.3'
|
59
|
+
|
60
|
+
MSG = 'Set `unified_mode true` in Chef Infra Client 15.3+ HWRP style custom resources to ensure they work correctly in Chef Infra Client 18 (April 2022) when Unified Mode becomes the default.'
|
61
|
+
|
62
|
+
def_node_matcher :HWRP?, <<-PATTERN
|
63
|
+
(class
|
64
|
+
(const nil? :Chef) nil?
|
65
|
+
(class
|
66
|
+
(const nil? :Resource) nil?
|
67
|
+
$(class
|
68
|
+
(const nil? ... )
|
69
|
+
(const
|
70
|
+
(const nil? :Chef) :Resource)
|
71
|
+
(begin ... ))))
|
72
|
+
PATTERN
|
73
|
+
|
74
|
+
def_node_search :unified_mode?, '(send nil? :unified_mode ...)'
|
75
|
+
|
76
|
+
def on_class(node)
|
77
|
+
return if unified_mode?(processed_source.ast)
|
78
|
+
HWRP?(node) do |inherit|
|
79
|
+
add_offense(inherit, message: MSG, severity: :warning)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 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
|
+
# 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.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# #### incorrect
|
27
|
+
# resource_name :foo
|
28
|
+
# provides :foo
|
29
|
+
#
|
30
|
+
# action :create do
|
31
|
+
# # some action code
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# #### correct
|
35
|
+
# resource_name :foo
|
36
|
+
# provides :foo
|
37
|
+
# unified_mode true
|
38
|
+
#
|
39
|
+
# action :create do
|
40
|
+
# # some action code
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
class ResourceWithoutUnifiedTrue < Base
|
44
|
+
include RangeHelp
|
45
|
+
extend AutoCorrector
|
46
|
+
extend TargetChefVersion
|
47
|
+
|
48
|
+
minimum_target_chef_version '15.3'
|
49
|
+
|
50
|
+
MSG = 'Set `unified_mode true` in Chef Infra Client 15.3+ custom resources to ensure they work correctly in Chef Infra Client 18 (April 2022) when Unified Mode becomes the default.'
|
51
|
+
|
52
|
+
def_node_search :unified_mode?, '(send nil? :unified_mode ...)'
|
53
|
+
def_node_search :resource_name, '(send nil? :resource_name ...)'
|
54
|
+
def_node_search :provides, '(send nil? :provides ...)'
|
55
|
+
|
56
|
+
def on_new_investigation
|
57
|
+
# Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
|
58
|
+
return if unified_mode?(processed_source.ast)
|
59
|
+
range = source_range(processed_source.buffer, 1, 0)
|
60
|
+
add_offense(range, message: MSG, severity: :refactor) do |corrector|
|
61
|
+
insert_below_provides(corrector) || insert_below_resource_name(corrector)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def insert_below_provides(corrector)
|
66
|
+
provides_ast = provides(processed_source.ast).first
|
67
|
+
if provides_ast
|
68
|
+
corrector.insert_after(provides_ast, "\nunified_mode true")
|
69
|
+
true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def insert_below_resource_name(corrector)
|
74
|
+
resource_name_ast = resource_name(processed_source.ast).first
|
75
|
+
if resource_name_ast
|
76
|
+
corrector.insert_after(resource_name_ast, "\nunified_mode true")
|
77
|
+
true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
File without changes
|
@@ -15,7 +15,6 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
19
18
|
module RuboCop
|
20
19
|
module Cop
|
21
20
|
module Chef
|
@@ -42,7 +41,6 @@ module RuboCop
|
|
42
41
|
# #### incorrect
|
43
42
|
# chef_vault_item(arg, arg1)
|
44
43
|
#
|
45
|
-
|
46
44
|
class ChefVaultUsed < Base
|
47
45
|
MSG = 'Chef Vault usage is not supported in the Effortless pattern'
|
48
46
|
RESTRICT_ON_SEND = [:chef_vault_item,
|
@@ -15,7 +15,6 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
19
18
|
module RuboCop
|
20
19
|
module Cop
|
21
20
|
module Chef
|
@@ -27,7 +26,6 @@ module RuboCop
|
|
27
26
|
# #### incorrect
|
28
27
|
# depends 'chef-vault'
|
29
28
|
#
|
30
|
-
|
31
29
|
class DependsChefVault < Base
|
32
30
|
MSG = 'Chef Vault usage is not supported in the Effortless pattern'
|
33
31
|
RESTRICT_ON_SEND = [:depends].freeze
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright:: 2020, Chef Software, Inc.
|
3
|
+
# Copyright:: 2020-2021, Chef Software, Inc.
|
4
4
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -47,24 +47,43 @@ module RuboCop
|
|
47
47
|
|
48
48
|
MSG = 'Chef Infra Client 15.0 and later includes a windows_uac resource that should be used to set Windows UAC values instead of setting registry keys directly.'
|
49
49
|
RESTRICT_ON_SEND = [:registry_key].freeze
|
50
|
+
VALID_VALUES = %w(EnableLUA ValidateAdminCodeSignatures PromptOnSecureDesktop ConsentPromptBehaviorAdmin ConsentPromptBehaviorUser EnableInstallerDetection).freeze
|
50
51
|
|
51
|
-
#
|
52
|
-
def
|
53
|
-
return unless node
|
54
|
-
|
55
|
-
|
56
|
-
# use source instead of .value in case there's string interpolation which adds a complex dstr type
|
57
|
-
# with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
|
52
|
+
# block registry_key resources
|
53
|
+
def on_block(node)
|
54
|
+
return unless node.method_name == :registry_key
|
55
|
+
return unless correct_key?(node)
|
56
|
+
return unless uac_supported_values?(node)
|
58
57
|
add_offense(node, message: MSG, severity: :refactor)
|
59
58
|
end
|
60
59
|
|
61
|
-
#
|
62
|
-
|
60
|
+
# make sure the values passed are all the ones in the uac resource
|
61
|
+
# this key has other values we don't support in the windows_uac resource
|
62
|
+
def uac_supported_values?(node)
|
63
|
+
match_property_in_resource?(:registry_key, 'values', node) do |val_prop|
|
64
|
+
return false unless val_prop&.arguments[0].array_type? # make sure values isn't being passed a variable or method
|
65
|
+
val_prop.arguments[0].each_value do |array|
|
66
|
+
array.each_pair do |key, value|
|
67
|
+
if key == s(:sym, :name)
|
68
|
+
return false unless value.str_type? # make sure it isn't being a variable or method that we can't parse
|
69
|
+
return false unless VALID_VALUES.include?(value.value)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
# make sure the registry_key resource is running against the correct key
|
78
|
+
# check the block name and the key property (registry_key's name property)
|
79
|
+
def correct_key?(node)
|
80
|
+
return true if node.send_node.arguments.first.source.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i)
|
81
|
+
|
63
82
|
match_property_in_resource?(:registry_key, 'key', node) do |key_prop|
|
64
83
|
property_data = method_arg_ast_to_string(key_prop)
|
65
|
-
return
|
66
|
-
add_offense(node, message: MSG, severity: :refactor)
|
84
|
+
return true if property_data && property_data.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i)
|
67
85
|
end
|
86
|
+
false
|
68
87
|
end
|
69
88
|
end
|
70
89
|
end
|