cookstyle 5.23.0 → 6.0.19
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 +86 -4
- data/config/disable_all.yml +58 -52
- data/config/upstream.yml +377 -336
- data/lib/cookstyle.rb +0 -1
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/chef/cookbook_helpers.rb +3 -3
- data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +58 -0
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +11 -5
- data/lib/rubocop/cop/chef/correctness/powershell_delete_file.rb +53 -0
- data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +4 -4
- data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +56 -0
- data/lib/rubocop/cop/chef/deprecation/cheffile.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -5
- data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +40 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -4
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +1 -4
- data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/log_resource_notifications.rb +60 -0
- data/lib/rubocop/cop/chef/deprecation/name_property_and_default.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +81 -0
- data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/run_command_helper.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb +1 -4
- data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +1 -4
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +58 -0
- data/lib/rubocop/cop/chef/modernize/powershell_guard_interpreter.rb +17 -8
- data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/provides_initializer.rb +69 -0
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +5 -15
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +103 -0
- data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +2 -9
- data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +2 -2
- data/lib/rubocop/cop/chef/redundant/apt_repository_distribution_default.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +3 -3
- data/lib/rubocop/monkey_patches/comment_config.rb +1 -1
- data/lib/rubocop/monkey_patches/config.rb +1 -1
- metadata +13 -5
- data/lib/rubocop/monkey_patches/json_formatter.rb +0 -20
@@ -42,16 +42,13 @@ 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'
|
48
45
|
|
49
46
|
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
|
50
47
|
|
51
48
|
def on_block(node)
|
52
49
|
%w(url keyurl mirrorexpire).each do |prop|
|
53
50
|
match_property_in_resource?(:yum_repository, prop, node) do |prop_node|
|
54
|
-
add_offense(prop_node, location: :expression, message: MSG, severity: :
|
51
|
+
add_offense(prop_node, location: :expression, message: MSG, severity: :warning)
|
55
52
|
end
|
56
53
|
end
|
57
54
|
end
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
MSG = "Don't use the deprecated easy_install resource removed in Chef 13".freeze
|
33
33
|
|
34
34
|
def on_send(node)
|
35
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
35
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :easy_install
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
MSG = 'Use ignore_failure method instead of the deprecated epic_fail method'.freeze
|
38
38
|
|
39
39
|
def on_send(node)
|
40
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
40
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :epic_fail
|
41
41
|
end
|
42
42
|
|
43
43
|
def autocorrect(node)
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
MSG = "Don't use the deprecated erl_call resource removed in Chef 13".freeze
|
33
33
|
|
34
34
|
def on_send(node)
|
35
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
35
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :erl_call
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -34,15 +34,12 @@ 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'
|
40
37
|
|
41
38
|
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
|
42
39
|
|
43
40
|
def on_block(node)
|
44
41
|
match_property_in_resource?(:launchd, 'hash', node) do |hash_prop|
|
45
|
-
add_offense(hash_prop, location: :expression, message: MSG, severity: :
|
42
|
+
add_offense(hash_prop, location: :expression, message: MSG, severity: :warning)
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
def on_block(node)
|
37
37
|
match_property_in_resource?(:locale, 'lc_all', node) do |property|
|
38
|
-
add_offense(property, location: :expression, message: MSG, severity: :
|
38
|
+
add_offense(property, location: :expression, message: MSG, severity: :warning)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefDeprecations
|
22
|
+
# In Chef Infra Client 16 the log resource no longer notifies when logging so notifications should not be triggered from log resources. See the notify_group functionality for a potential replacement.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# template '/etc/foo' do
|
28
|
+
# source 'bar.erb'
|
29
|
+
# notifies :write, 'log[Aggregate notifications using a single log resource]', :immediately
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# log 'Aggregate notifications using a single log resource' do
|
33
|
+
# notifies :restart, 'service[foo]', :delayed
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# template '/etc/foo' do
|
38
|
+
# source 'bar.erb'
|
39
|
+
# notifies :run, 'notify_group[Aggregate notifications using a single notify_group resource]', :immediately
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# notify_group 'Aggregate notifications using a single notify_group resource' do
|
43
|
+
# notifies :restart, 'service[foo]', :delayed
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
class LogResourceNotifications < Cop
|
47
|
+
include RuboCop::Chef::CookbookHelpers
|
48
|
+
|
49
|
+
MSG = 'In Chef Infra Client 16 the log resource no longer notifies when logging so notifications should not be triggered from log resources. Use the notify_group resource instead to aggregate notifications.'.freeze
|
50
|
+
|
51
|
+
def on_block(node)
|
52
|
+
match_property_in_resource?(:log, 'notifies', node) do |prop_node|
|
53
|
+
add_offense(prop_node, location: :expression, message: MSG, severity: :warning)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -48,11 +48,11 @@ module RuboCop
|
|
48
48
|
|
49
49
|
def on_send(node)
|
50
50
|
node_deep_fetch?(node) do
|
51
|
-
add_offense(node, location: :selector, message: MSG, severity: :
|
51
|
+
add_offense(node, location: :selector, message: MSG, severity: :warning)
|
52
52
|
end
|
53
53
|
|
54
54
|
node_deep_fetch_bang?(node) do
|
55
|
-
add_offense(node, location: :selector, message: MSG2, severity: :
|
55
|
+
add_offense(node, location: :selector, message: MSG2, severity: :warning)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -54,9 +54,9 @@ module RuboCop
|
|
54
54
|
|
55
55
|
def add_offense_for_bare_assignment(sub_node)
|
56
56
|
if sub_node.receiver == s(:send, nil, :node) # node['foo'] scenario
|
57
|
-
add_offense(sub_node.receiver, location: :selector, message: MSG, severity: :
|
57
|
+
add_offense(sub_node.receiver, location: :selector, message: MSG, severity: :warning)
|
58
58
|
elsif sub_node.receiver && sub_node.receiver&.node_parts[0] == s(:send, nil, :node) && sub_node.receiver&.node_parts[1] == :[] # node['foo']['bar'] scenario
|
59
|
-
add_offense(sub_node.receiver.node_parts.first, location: :selector, message: MSG, severity: :
|
59
|
+
add_offense(sub_node.receiver.node_parts.first, location: :selector, message: MSG, severity: :warning)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
50
50
|
MSG = 'Legacy partial_search usage should be updated to use :filter_result in the search helper instead'.freeze
|
51
51
|
|
52
52
|
def on_send(node)
|
53
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
53
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :partial_search
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -43,13 +43,13 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def on_send(node)
|
45
45
|
depends_poise_archive?(node) do
|
46
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def on_block(node)
|
51
51
|
match_resource_type?(:poise_archive, node) do
|
52
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
52
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
PATTERN
|
38
38
|
|
39
39
|
def on_send(node)
|
40
|
-
require_recipe?(node) { add_offense(node, location: :selector, message: MSG, severity: :
|
40
|
+
require_recipe?(node) { add_offense(node, location: :selector, message: MSG, severity: :warning) }
|
41
41
|
end
|
42
42
|
|
43
43
|
def autocorrect(node)
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
|
38
38
|
def on_def(node)
|
39
39
|
if node.method_name == :provides?
|
40
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
40
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if provides(processed_source.ast).count == 0
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
MSG = 'Use resource_name instead of the dsl_name method in resources. This will cause failures in Chef Infra Client 13 and later.'.freeze
|
33
33
|
|
34
34
|
def on_send(node)
|
35
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
35
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :dsl_name
|
36
36
|
end
|
37
37
|
|
38
38
|
# potential autocorrect is new_resource.updated_by_last_action true, but we need to actually see what class we were called from
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
MSG = "Don't use the deprecated provider_base method in a resource to specify the provider module to use. Instead, the provider should call provides to register itself, or the resource should call provider to specify the provider to use. This will cause failures in Chef Infra Client 13 and later.".freeze
|
30
30
|
|
31
31
|
def on_send(node)
|
32
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
32
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :provider_base
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
MSG = "Don't use updated = true/false to update resource state. This will cause failures in Chef Infra Client 13 and later.".freeze
|
38
38
|
|
39
39
|
def on_lvasgn(node)
|
40
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
40
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.node_parts.first == :updated
|
41
41
|
end
|
42
42
|
|
43
43
|
# potential autocorrect is new_resource.updated_by_last_action true, but we need to actually see what class we were called from
|
@@ -0,0 +1,81 @@
|
|
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
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefDeprecations
|
22
|
+
# In Chef Infra Client 16 and later a legacy HWRP resource must use either `resource_name` or `provides` to define the resource name.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# class Chef
|
28
|
+
# class Resource
|
29
|
+
# class UlimitRule < Chef::Resource
|
30
|
+
# property :type, [Symbol, String], required: true
|
31
|
+
# property :item, [Symbol, String], required: true
|
32
|
+
#
|
33
|
+
# # additional resource code
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # good
|
39
|
+
# class Chef
|
40
|
+
# class Resource
|
41
|
+
# class UlimitRule < Chef::Resource
|
42
|
+
# resource_name :ulimit_rule
|
43
|
+
#
|
44
|
+
# property :type, [Symbol, String], required: true
|
45
|
+
# property :item, [Symbol, String], required: true
|
46
|
+
#
|
47
|
+
# # additional resource code
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# # better
|
53
|
+
# Convert your legacy HWRPs to custom resources
|
54
|
+
#
|
55
|
+
class ResourceWithoutNameOrProvides < Cop
|
56
|
+
MSG = 'In Chef Infra Client 16 and later legacy HWRP resources must use either `resource_name` or `provides` to define the resource name.'.freeze
|
57
|
+
|
58
|
+
def_node_matcher :HWRP?, <<-PATTERN
|
59
|
+
(class
|
60
|
+
(const nil? :Chef) nil?
|
61
|
+
(class
|
62
|
+
(const nil? :Resource) nil?
|
63
|
+
$(class
|
64
|
+
(const nil? ... )
|
65
|
+
(const
|
66
|
+
(const nil? :Chef) :Resource)
|
67
|
+
(begin ... ))))
|
68
|
+
PATTERN
|
69
|
+
|
70
|
+
def_node_search :provides_or_resource_name?, '(send nil? {:provides :resource_name} ...)'
|
71
|
+
|
72
|
+
def on_class(node)
|
73
|
+
HWRP?(node) do |inherit|
|
74
|
+
add_offense(inherit, location: :expression, message: MSG, severity: :warning) if provides_or_resource_name?(processed_source.ast).nil?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
def on_block(node)
|
48
48
|
match_property_in_resource?(:ruby_block, 'action', node) do |ruby_action|
|
49
49
|
ruby_action.arguments.each do |action|
|
50
|
-
add_offense(action, location: :expression, message: MSG, severity: :
|
50
|
+
add_offense(action, location: :expression, message: MSG, severity: :warning) if action.source == ':create'
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -43,15 +43,15 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def on_send(node)
|
45
45
|
calls_run_command?(node) do
|
46
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) unless defines_run_command?(processed_source.ast)
|
47
47
|
end
|
48
48
|
|
49
49
|
require_mixin_command?(node) do
|
50
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
50
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
51
51
|
end
|
52
52
|
|
53
53
|
include_mixin_command?(node) do
|
54
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
54
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|