cookstyle 6.18.8 → 6.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -1
- data/config/cookstyle.yml +39 -0
- data/config/disable_all.yml +6 -0
- data/config/upstream.yml +44 -3
- data/cookstyle.gemspec +1 -1
- data/lib/cookstyle.rb +0 -3
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +2 -1
- data/lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +19 -37
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +2 -1
- data/lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/lazy_in_resource_guard.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/node_save.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/octal_mode_as_string.rb +48 -0
- data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/scoped_file_exist.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/chefdk_generators.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/deprecated_chefspec_platform.rb +1 -3
- data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb +2 -0
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +22 -27
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/use_yaml_dump.rb +47 -0
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb +5 -4
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -1
- data/lib/rubocop/cop/chef/effortless/chef_vault_used.rb +89 -0
- data/lib/rubocop/cop/chef/effortless/depends_chef_vault.rb +49 -0
- data/lib/rubocop/cop/chef/modernize/action_method_in_resource.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/compile_time_resources.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/foodcritic_comments.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/if_provides_default_action.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/node_init_package.rb +5 -4
- data/lib/rubocop/cop/chef/modernize/node_roles_include.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +6 -6
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +10 -10
- data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
- data/lib/rubocop/cop/chef/redundant/double_compile_time.rb +2 -1
- data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +1 -1
- data/lib/rubocop/cop/chef/redundant/name_property_and_required.rb +1 -0
- data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +2 -1
- data/lib/rubocop/cop/chef/redundant/property_splat_regex.rb +1 -0
- data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +1 -1
- data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -1
- data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -1
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
- data/lib/rubocop/cop/chef/style/attribute_keys.rb +2 -1
- data/lib/rubocop/cop/chef/style/chef_whaaat.rb +1 -1
- data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +2 -2
- data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +2 -2
- data/lib/rubocop/cop/chef/style/comments_default_copyright.rb +1 -1
- data/lib/rubocop/cop/chef/style/comments_format.rb +6 -13
- data/lib/rubocop/cop/chef/style/file_mode.rb +2 -2
- data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +2 -2
- data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +2 -2
- data/lib/rubocop/cop/chef/style/negating_only_if.rb +2 -2
- data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +2 -2
- data/lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb +2 -1
- data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -2
- data/lib/rubocop/cop/chef/style/unnecessary_os_check.rb +5 -4
- data/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +2 -2
- data/lib/rubocop/cop/chef/style/use_platform_helpers.rb +7 -6
- metadata +9 -6
- data/lib/rubocop/monkey_patches/rescue_ensure_alignment.rb +0 -22
@@ -39,6 +39,7 @@ module RuboCop
|
|
39
39
|
#
|
40
40
|
class NodeNormal < Base
|
41
41
|
MSG = 'Do not use node.normal. Replace with default/override/force_default/force_override attribute levels.'
|
42
|
+
RESTRICT_ON_SEND = [:normal].freeze
|
42
43
|
|
43
44
|
def_node_matcher :node_normal?, <<-PATTERN
|
44
45
|
(send (send _ :node) :normal)
|
@@ -39,6 +39,7 @@ module RuboCop
|
|
39
39
|
#
|
40
40
|
class NodeNormalUnless < Base
|
41
41
|
MSG = 'Do not use node.normal_unless. Replace with default/override/force_default/force_override attribute levels.'
|
42
|
+
RESTRICT_ON_SEND = [:normal_unless].freeze
|
42
43
|
|
43
44
|
def_node_matcher :node_normal_unless?, <<-PATTERN
|
44
45
|
(send (send _ :node) :normal_unless)
|
@@ -30,6 +30,7 @@ module RuboCop
|
|
30
30
|
#
|
31
31
|
class CookbookUsesNodeSave < Base
|
32
32
|
MSG = "Don't use node.save to save partial node data to the Chef Infra Server mid-run unless it's absolutely necessary. Node.save can result in failed Chef Infra runs appearing in search and increases load on the Chef Infra Server."
|
33
|
+
RESTRICT_ON_SEND = [:save].freeze
|
33
34
|
|
34
35
|
def_node_matcher :node_save?, <<-PATTERN
|
35
36
|
(send (send nil? :node) :save)
|
@@ -53,7 +53,7 @@ module RuboCop
|
|
53
53
|
return unless notifies_property.node_parts[2].str_type?
|
54
54
|
|
55
55
|
add_offense(notifies_property, message: MSG, severity: :refactor) do |corrector|
|
56
|
-
corrector.replace(notifies_property.first_argument
|
56
|
+
corrector.replace(notifies_property.first_argument,
|
57
57
|
":#{notifies_property.node_parts[2].value}")
|
58
58
|
end
|
59
59
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2020, 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 ChefCorrectness
|
22
|
+
# Don't represent file modes as Strings containing octal values.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# file '/etc/some_file' do
|
28
|
+
# mode '0o755'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# file '/etc/some_file' do
|
33
|
+
# mode '0755'
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
class OctalModeAsString < Base
|
37
|
+
MSG = "Don't represent file modes as strings containing octal values. Use standard base 10 file modes instead. For example: '0755'."
|
38
|
+
RESTRICT_ON_SEND = [:mode].freeze
|
39
|
+
|
40
|
+
def on_send(node)
|
41
|
+
return unless node.arguments.first&.str_type? && node.arguments.first.value.match?(/^0o/)
|
42
|
+
add_offense(node, message: MSG, severity: :refactor)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
action_node.arguments.each do |action|
|
46
46
|
next unless action.source == ':none'
|
47
47
|
add_offense(action, message: MSG, severity: :refactor) do |corrector|
|
48
|
-
corrector.replace(action
|
48
|
+
corrector.replace(action, ':nothing')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -41,8 +41,8 @@ module RuboCop
|
|
41
41
|
def on_send(node)
|
42
42
|
supports_with_constraint?(node) do |ver|
|
43
43
|
return if ver.source.include?('.')
|
44
|
-
add_offense(ver
|
45
|
-
corrector.replace(ver
|
44
|
+
add_offense(ver, message: MSG, severity: :refactor) do |corrector|
|
45
|
+
corrector.replace(ver, ver.source.gsub(ver.value, (ver.value + '.0')))
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
add_offense(prop_node, message: MSG, severity: :warning) do |corrector|
|
46
46
|
# make sure to delete leading and trailing {}s that would create invalid ruby syntax
|
47
47
|
extracted_val = prop_node.arguments.first.source.gsub(/{|}/, '')
|
48
|
-
corrector.replace(prop_node
|
48
|
+
corrector.replace(prop_node, "type #{extracted_val}")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -79,7 +79,7 @@ module RuboCop
|
|
79
79
|
|
80
80
|
rewind_resources?(node) do |string|
|
81
81
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
82
|
-
corrector.replace(node
|
82
|
+
corrector.replace(node, node.source.gsub(string.to_s, MAPPING[string]))
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -88,7 +88,7 @@ module RuboCop
|
|
88
88
|
match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name|
|
89
89
|
next unless pkg_name.arguments&.first&.str_content == 'chef-rewind'
|
90
90
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
91
|
-
corrector.remove(node
|
91
|
+
corrector.remove(node) if pkg_name.arguments&.first&.str_content == 'chef-rewind'
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
extend AutoCorrector
|
42
42
|
|
43
43
|
MSG = "Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically."
|
44
|
-
|
44
|
+
RESTRICT_ON_SEND = [:new, :require, :include].freeze
|
45
45
|
|
46
46
|
def_node_matcher :include_shellout?, <<-PATTERN
|
47
47
|
(send nil? :include
|
@@ -75,7 +75,7 @@ module RuboCop
|
|
75
75
|
|
76
76
|
shellout_new?(node) do
|
77
77
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
78
|
-
corrector.replace(node
|
78
|
+
corrector.replace(node, node.source.gsub('Chef::ShellOut', 'Mixlib::ShellOut'))
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -33,6 +33,7 @@ module RuboCop
|
|
33
33
|
class ChefWindowsPlatformHelper < Base
|
34
34
|
extend AutoCorrector
|
35
35
|
MSG = "Use `platform?('windows')` instead of the legacy `Chef::Platform.windows?` helper."
|
36
|
+
RESTRICT_ON_SEND = [:windows?].freeze
|
36
37
|
|
37
38
|
def_node_matcher :chef_platform_windows?, <<-PATTERN
|
38
39
|
(send
|
@@ -43,7 +44,7 @@ module RuboCop
|
|
43
44
|
def on_send(node)
|
44
45
|
chef_platform_windows?(node) do
|
45
46
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
46
|
-
corrector.replace(node
|
47
|
+
corrector.replace(node, "platform?('windows')")
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
return unless node.const_name == 'ChefDK' && (node.parent&.module_type? || node.parent&.const_type?)
|
48
48
|
|
49
49
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
50
|
-
corrector.replace(node
|
50
|
+
corrector.replace(node, node.source.gsub('ChefDK', 'ChefCLI'))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
def on_const(node)
|
52
52
|
chefspec_runner?(node) do
|
53
53
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
54
|
-
corrector.replace(node
|
54
|
+
corrector.replace(node, 'ChefSpec::ServerRunner')
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -32,8 +32,6 @@ module RuboCop
|
|
32
32
|
|
33
33
|
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"
|
34
34
|
|
35
|
-
Gem::Dependency.new('', ['~> 1.4.5', '>= 1.4.6']).match?('', '1.4.6')
|
36
|
-
|
37
35
|
DEPRECATED_MAPPING = {
|
38
36
|
'amazon' => {
|
39
37
|
'2017.12' => '2',
|
@@ -120,7 +118,7 @@ module RuboCop
|
|
120
118
|
next unless legacy_chefspec_platform(plat.value, ver.value)
|
121
119
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
122
120
|
if replacement = replacement_string(plat.value, ver.value) # rubocop: disable Lint/AssignmentInCondition
|
123
|
-
corrector.replace(ver
|
121
|
+
corrector.replace(ver, "'#{replacement}'")
|
124
122
|
end
|
125
123
|
end
|
126
124
|
end
|
@@ -44,6 +44,7 @@ module RuboCop
|
|
44
44
|
|
45
45
|
class DeprecatedPlatformMethods < Base
|
46
46
|
MSG = 'Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
|
47
|
+
RESTRICT_ON_SEND = [:provider_for_resource, :find_provider, :find_provider_for_node, :set].freeze
|
47
48
|
|
48
49
|
def_node_matcher :platform_method?, <<-PATTERN
|
49
50
|
(send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node :set} ... )
|
@@ -54,7 +54,7 @@ module RuboCop
|
|
54
54
|
%w(url keyurl mirrorexpire).each do |prop|
|
55
55
|
match_property_in_resource?(:yum_repository, prop, node) do |prop_node|
|
56
56
|
add_offense(prop_node, message: MSG, severity: :warning) do |corrector|
|
57
|
-
corrector.replace(prop_node
|
57
|
+
corrector.replace(prop_node, prop_node.source
|
58
58
|
.gsub(/^url/, 'baseurl')
|
59
59
|
.gsub(/^keyurl/, 'gpgkey')
|
60
60
|
.gsub(/^mirrorexpire/, 'mirror_expire'))
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
|
42
42
|
def on_block(node)
|
43
43
|
match_property_in_resource?(:execute, 'path', node) do |offense|
|
44
|
-
add_offense(offense
|
44
|
+
add_offense(offense, message: MSG, severity: :warning) # @todo: we could probably autocorrect this with some work
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
def on_class(node)
|
50
50
|
inherits_from_compat_resource?(node) do
|
51
51
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
52
|
-
corrector.replace(node
|
52
|
+
corrector.replace(node, node.source.gsub('ChefCompat', 'Chef'))
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -78,9 +78,9 @@ module RuboCop
|
|
78
78
|
else
|
79
79
|
"\"#{type.source}[\#{#{name.source}}]\""
|
80
80
|
end
|
81
|
-
new_val = "#{notify_type} #{action.source}, #{service_value}"
|
81
|
+
new_val = +"#{notify_type} #{action.source}, #{service_value}"
|
82
82
|
new_val << ", #{timing.first.source}" unless timing.empty?
|
83
|
-
corrector.replace(node
|
83
|
+
corrector.replace(node, new_val)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -37,6 +37,8 @@ module RuboCop
|
|
37
37
|
class NodeDeepFetch < Base
|
38
38
|
extend RuboCop::Cop::AutoCorrector
|
39
39
|
|
40
|
+
RESTRICT_ON_SEND = [:deep_fetch, :deep_fetch!].freeze
|
41
|
+
|
40
42
|
def_node_matcher :node_deep_fetch?, <<-PATTERN
|
41
43
|
(send (send _ :node) ${:deep_fetch :deep_fetch!} _)
|
42
44
|
PATTERN
|
@@ -41,43 +41,38 @@ module RuboCop
|
|
41
41
|
extend AutoCorrector
|
42
42
|
|
43
43
|
MSG = 'Use node attributes to access Ohai data instead of node methods, which were deprecated in Chef Infra Client 13.'
|
44
|
+
RESTRICT_ON_SEND = %i(
|
45
|
+
current_user
|
46
|
+
domain
|
47
|
+
fqdn
|
48
|
+
hostname
|
49
|
+
ip6address
|
50
|
+
ipaddress
|
51
|
+
macaddress
|
52
|
+
machinename
|
53
|
+
ohai_time
|
54
|
+
os
|
55
|
+
os_version
|
56
|
+
platform
|
57
|
+
platform_build
|
58
|
+
platform_family
|
59
|
+
platform_version
|
60
|
+
root_group
|
61
|
+
shard_seed
|
62
|
+
uptime
|
63
|
+
uptime_seconds).freeze
|
44
64
|
|
45
65
|
def_node_matcher :node_ohai_methods?, <<-PATTERN
|
46
|
-
(send (send nil? :node)
|
66
|
+
(send (send nil? :node) _)
|
47
67
|
PATTERN
|
48
68
|
|
49
69
|
def on_send(node)
|
50
70
|
node_ohai_methods?(node) do
|
51
71
|
add_offense(node.loc.selector, message: MSG, severity: :warning) do |corrector|
|
52
|
-
corrector.replace(node
|
72
|
+
corrector.replace(node, "node['#{node.method_name}']")
|
53
73
|
end
|
54
74
|
end
|
55
75
|
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def non_nested_ohai_attribute?(attribute)
|
60
|
-
%i(
|
61
|
-
current_user
|
62
|
-
domain
|
63
|
-
fqdn
|
64
|
-
hostname
|
65
|
-
ip6address
|
66
|
-
ipaddress
|
67
|
-
macaddress
|
68
|
-
machinename
|
69
|
-
ohai_time
|
70
|
-
os
|
71
|
-
os_version
|
72
|
-
platform
|
73
|
-
platform_build
|
74
|
-
platform_family
|
75
|
-
platform_version
|
76
|
-
root_group
|
77
|
-
shard_seed
|
78
|
-
uptime
|
79
|
-
uptime_seconds).include?(attribute)
|
80
|
-
end
|
81
76
|
end
|
82
77
|
end
|
83
78
|
end
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
extend AutoCorrector
|
35
35
|
|
36
36
|
MSG = 'Do not use node.set_unless. Replace with node.normal_unless to keep identical behavior.'
|
37
|
+
RESTRICT_ON_SEND = [:set_unless].freeze
|
37
38
|
|
38
39
|
def_node_matcher :node_set_unless?, <<-PATTERN
|
39
40
|
(send (send _ :node) $:set_unless)
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
#
|
37
37
|
class NodeSetWithoutLevel < Base
|
38
38
|
MSG = 'When setting a node attribute in Chef Infra Client 11 and later you must specify the precedence level.'
|
39
|
+
RESTRICT_ON_SEND = [:[]=, :<<].freeze
|
39
40
|
|
40
41
|
def on_op_asgn(node)
|
41
42
|
# make sure it was a += or -=
|
@@ -49,6 +49,7 @@ module RuboCop
|
|
49
49
|
#
|
50
50
|
class PartialSearchClassUsage < Base
|
51
51
|
MSG = 'Legacy Chef::PartialSearch class usage should be updated to use the search helper instead with the filter_result key.'
|
52
|
+
RESTRICT_ON_SEND = [:new].freeze
|
52
53
|
|
53
54
|
def_node_matcher :partial_search_class?, <<-PATTERN
|
54
55
|
(send (const (const ... :Chef) :PartialSearch) :new)
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
extend AutoCorrector
|
37
37
|
|
38
38
|
MSG = "Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client 15.8+ instead of the deprecated PowerShell cookbook helpers."
|
39
|
+
RESTRICT_ON_SEND = [:powershell_version?].freeze
|
39
40
|
|
40
41
|
def_node_matcher :ps_cb_helper?, <<-PATTERN
|
41
42
|
(send
|
@@ -47,7 +48,7 @@ module RuboCop
|
|
47
48
|
def on_send(node)
|
48
49
|
ps_cb_helper?(node) do |ver|
|
49
50
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
50
|
-
corrector.replace(node
|
51
|
+
corrector.replace(node, "node['powershell']['version'].to_f == #{ver.source}")
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -34,12 +34,12 @@ module RuboCop
|
|
34
34
|
class ResourceOverridesProvidesMethod < Base
|
35
35
|
MSG = "Don't override the provides? method in a resource provider. Use provides :SOME_PROVIDER_NAME instead. This will cause failures in Chef Infra Client 13 and later."
|
36
36
|
|
37
|
-
def_node_search :
|
37
|
+
def_node_search :calls_provides?, '(send nil? :provides ...)'
|
38
38
|
|
39
39
|
def on_def(node)
|
40
40
|
return unless node.method_name == :provides?
|
41
41
|
|
42
|
-
add_offense(node, message: MSG, severity: :warning)
|
42
|
+
add_offense(node, message: MSG, severity: :warning) unless calls_provides?(processed_source.ast)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -45,8 +45,8 @@ module RuboCop
|
|
45
45
|
def on_send(node)
|
46
46
|
positional_shellout?(node) do |h|
|
47
47
|
next unless h.braces?
|
48
|
-
add_offense(h
|
49
|
-
corrector.replace(h
|
48
|
+
add_offense(h, message: MSG, severity: :refactor) do |corrector|
|
49
|
+
corrector.replace(h, h.source[1..-2])
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|