cookstyle 6.17.5 → 6.19.11
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/bin/cookstyle +0 -1
- data/config/cookstyle.yml +85 -15
- data/config/disable_all.yml +8 -0
- data/config/upstream.yml +50 -3
- data/cookstyle.gemspec +1 -2
- data/lib/cookstyle.rb +5 -5
- 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 +24 -14
- 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 +67 -0
- 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/property_without_type.rb +59 -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/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 +7 -4
- 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 +8 -4
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
|
41
41
|
def on_send(node)
|
42
42
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
43
|
-
corrector.replace(node
|
43
|
+
corrector.replace(node, node.source.gsub(/^cron_manage/, 'cron_access'))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
extend AutoCorrector
|
36
36
|
|
37
37
|
MSG = 'Use the `data_bag_item` helper instead of `Chef::DataBagItem.load` or `Chef::EncryptedDataBagItem.load`.'
|
38
|
+
RESTRICT_ON_SEND = [:load].freeze
|
38
39
|
|
39
40
|
def_node_matcher :data_bag_class_load?, <<-PATTERN
|
40
41
|
(send
|
@@ -46,7 +47,7 @@ module RuboCop
|
|
46
47
|
def on_send(node)
|
47
48
|
data_bag_class_load?(node) do
|
48
49
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
49
|
-
corrector.replace(node
|
50
|
+
corrector.replace(node,
|
50
51
|
node.source.gsub(/Chef::(EncryptedDataBagItem|DataBagItem).load/, 'data_bag_item'))
|
51
52
|
end
|
52
53
|
end
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
processed_source.comments.each do |comment|
|
37
37
|
next unless comment.text.match?(/#\s*~FC\d{3}.*/)
|
38
38
|
add_offense(comment, message: MSG, severity: :refactor) do |corrector|
|
39
|
-
corrector.remove(comment
|
39
|
+
corrector.remove(comment)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
return unless node.arguments.first == s(:send, nil, :default_action)
|
39
39
|
node = node.parent if node.parent.respond_to?(:if?) && node.parent.if? # we want the whole if statement
|
40
40
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
41
|
-
corrector.replace(node
|
41
|
+
corrector.replace(node, node.children[1].source)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -51,14 +51,14 @@ module RuboCop
|
|
51
51
|
# The need for this goes away once https://github.com/rubocop-hq/rubocop/pull/8365 is pulled into Cookstyle
|
52
52
|
if node.method_name == :libarchive_file
|
53
53
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
54
|
-
corrector.replace(node
|
54
|
+
corrector.replace(node, node.source.gsub('libarchive_file', 'archive_file'))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
notification_property?(node) do |val|
|
59
59
|
next unless val.str_content&.start_with?('libarchive_file')
|
60
60
|
add_offense(val, message: MSG, severity: :refactor) do |corrector|
|
61
|
-
corrector.replace(node
|
61
|
+
corrector.replace(node, node.source.gsub('libarchive_file', 'archive_file'))
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
|
48
48
|
def on_send(node)
|
49
49
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
50
|
-
corrector.replace(node
|
50
|
+
corrector.replace(node, node.source.gsub(/^mac_os_x_userdefaults/, 'macos_userdefaults'))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -43,6 +43,7 @@ module RuboCop
|
|
43
43
|
extend RuboCop::Cop::AutoCorrector
|
44
44
|
|
45
45
|
MSG = "Use node['init_package'] to check for systemd instead of reading the contents of '/proc/1/comm'"
|
46
|
+
RESTRICT_ON_SEND = [:open, :read, :exist?, :==, :not_if, :only_if].freeze
|
46
47
|
|
47
48
|
def_node_matcher :file_reads_proc_1_comm?, <<-PATTERN
|
48
49
|
(send (const {(cbase) nil?} {:File :IO}) {:open :read} (str "/proc/1/comm"))
|
@@ -62,7 +63,7 @@ module RuboCop
|
|
62
63
|
PATTERN
|
63
64
|
|
64
65
|
def_node_matcher :file_systemd_conditional?, <<~PATTERN
|
65
|
-
|
66
|
+
(send nil? {:not_if :only_if} $(str "test -f /bin/systemctl && /bin/systemctl"))
|
66
67
|
PATTERN
|
67
68
|
|
68
69
|
def on_send(node)
|
@@ -70,14 +71,14 @@ module RuboCop
|
|
70
71
|
# if there's a ::File.exist?('/proc/1/comm') check first we want to match that as well
|
71
72
|
node = node.parent if node.parent&.and_type? && proc_1_comm_exists?(node.parent.conditions.first)
|
72
73
|
|
73
|
-
add_offense(node
|
74
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
74
75
|
corrector.replace(node, "node['init_package'] == 'systemd'")
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
79
|
file_systemd_conditional?(node) do |conditional|
|
79
|
-
add_offense(node
|
80
|
-
corrector.replace(conditional
|
80
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
81
|
+
corrector.replace(conditional, "{ node['init_package'] == 'systemd' }")
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
@@ -33,6 +33,7 @@ module RuboCop
|
|
33
33
|
extend AutoCorrector
|
34
34
|
|
35
35
|
MSG = "Use `node.role?('foo')` to check if a node includes a role instead of `node['roles'].include?('foo')`."
|
36
|
+
RESTRICT_ON_SEND = [:include?].freeze
|
36
37
|
|
37
38
|
def_node_matcher :node_role_include?, <<-PATTERN
|
38
39
|
(send
|
@@ -45,7 +46,7 @@ module RuboCop
|
|
45
46
|
def on_send(node)
|
46
47
|
node_role_include?(node) do |val|
|
47
48
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
48
|
-
corrector.replace(node
|
49
|
+
corrector.replace(node, "node.role?(#{val.source})")
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def on_send(node)
|
45
45
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
46
|
-
corrector.replace(node
|
46
|
+
corrector.replace(node, node.source.gsub(/^openssl_rsa_key/, 'openssl_rsa_private_key'))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
|
50
50
|
def on_send(node)
|
51
51
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
52
|
-
corrector.replace(node
|
52
|
+
corrector.replace(node, node.source.gsub(/^openssl_x509/, 'openssl_x509_certificate'))
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
|
41
41
|
def on_send(node)
|
42
42
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
43
|
-
corrector.replace(node
|
43
|
+
corrector.replace(node, node.source.gsub(/^osx_config_profile/, 'osx_profile'))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
def on_send(node)
|
46
46
|
property_with_name_attribute?(node) do |name_attribute|
|
47
47
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
48
|
-
corrector.replace(name_attribute
|
48
|
+
corrector.replace(name_attribute, 'name_property: true')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -44,6 +44,7 @@ module RuboCop
|
|
44
44
|
# end
|
45
45
|
#
|
46
46
|
class RespondToCompileTime < Base
|
47
|
+
include RuboCop::Chef::CookbookHelpers
|
47
48
|
extend TargetChefVersion
|
48
49
|
extend AutoCorrector
|
49
50
|
|
@@ -75,10 +76,12 @@ module RuboCop
|
|
75
76
|
$(_)) nil?)
|
76
77
|
PATTERN
|
77
78
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
def on_block(node)
|
80
|
+
match_property_in_resource?(:chef_gem, 'compile_time', node) do |compile_time_property|
|
81
|
+
compile_time_method_defined?(compile_time_property.parent) do |val|
|
82
|
+
add_offense(compile_time_property.parent, message: MSG, severity: :refactor) do |corrector|
|
83
|
+
corrector.replace(compile_time_property.parent, "compile_time #{val.source}")
|
84
|
+
end
|
82
85
|
end
|
83
86
|
end
|
84
87
|
end
|
@@ -27,6 +27,7 @@ module RuboCop
|
|
27
27
|
# # bad
|
28
28
|
# chef_version '>= 13' if respond_to?(:chef_version)
|
29
29
|
# chef_version '>= 13' if defined?(chef_version)
|
30
|
+
# chef_version '>= 13' unless defined?(Ridley::Chef::Cookbook::Metadata)
|
30
31
|
# if defined(chef_version)
|
31
32
|
# chef_version '>= 13'
|
32
33
|
# end
|
@@ -40,7 +41,7 @@ module RuboCop
|
|
40
41
|
|
41
42
|
minimum_target_chef_version '12.15'
|
42
43
|
|
43
|
-
MSG = 'It is no longer necessary to use respond_to? or
|
44
|
+
MSG = 'It is no longer necessary to use respond_to? or defined? in metadata.rb in Chef Infra Client 12.15 and later'
|
44
45
|
|
45
46
|
def on_if(node)
|
46
47
|
if_respond_to?(node) do
|
@@ -51,7 +52,7 @@ module RuboCop
|
|
51
52
|
# is a block under the if statement and node.parent.if_branch can get us that block
|
52
53
|
node = node.parent unless node.if_type?
|
53
54
|
|
54
|
-
corrector.replace(node
|
55
|
+
corrector.replace(node, node.if_branch.source)
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -61,15 +62,14 @@ module RuboCop
|
|
61
62
|
# node.if_branch is the actual method call we want to extract.
|
62
63
|
# If a series of metadata methods are wrapped in an if statement then the content we want
|
63
64
|
# is a block under the if statement and node.parent.if_branch can get us that block
|
64
|
-
|
65
|
-
node = node.parent if node.parent.if? && !node.if_type? # we want the whole if statement
|
65
|
+
node = node.parent if node.parent.conditional? # we want the whole conditional statement
|
66
66
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
67
|
-
corrector.replace(node
|
67
|
+
corrector.replace(node, node.if_branch.source)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
def_node_matcher :if_respond_to?, <<~PATTERN
|
72
|
-
|
72
|
+
(if (send nil? :respond_to? _ ) ... )
|
73
73
|
PATTERN
|
74
74
|
end
|
75
75
|
end
|
@@ -39,22 +39,22 @@ module RuboCop
|
|
39
39
|
def on_if(node)
|
40
40
|
if_respond_to_provides?(node) do
|
41
41
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
42
|
-
corrector.replace(node
|
42
|
+
corrector.replace(node, node.children[1].source)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def_node_matcher :if_respond_to_provides?, <<~PATTERN
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
(if
|
49
|
+
{
|
50
|
+
(send nil? :respond_to?
|
51
|
+
(sym :provides))
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
(:defined?
|
54
|
+
(send nil? :provides))
|
55
|
+
}
|
56
|
+
(send nil? :provides
|
57
|
+
(sym _)) ... )
|
58
58
|
PATTERN
|
59
59
|
end
|
60
60
|
end
|
@@ -37,13 +37,13 @@ module RuboCop
|
|
37
37
|
def on_if(node)
|
38
38
|
if_respond_to_resource_name?(node) do
|
39
39
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
40
|
-
corrector.replace(node
|
40
|
+
corrector.replace(node, node.children[1].source)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def_node_matcher :if_respond_to_resource_name?, <<~PATTERN
|
46
|
-
|
46
|
+
(if (send nil? :respond_to? ( :sym :resource_name ) ) ... )
|
47
47
|
PATTERN
|
48
48
|
end
|
49
49
|
end
|
@@ -37,6 +37,7 @@ module RuboCop
|
|
37
37
|
minimum_target_chef_version '12.11'
|
38
38
|
|
39
39
|
MSG = "Use the built-in `shell_out` helper available in Chef Infra Client 12.11+ instead of calling `Mixlib::ShellOut.new('foo').run_command`."
|
40
|
+
RESTRICT_ON_SEND = [:run_command].freeze
|
40
41
|
|
41
42
|
def_node_matcher :mixlib_shellout_run_cmd?, <<-PATTERN
|
42
43
|
(send
|
@@ -49,7 +50,7 @@ module RuboCop
|
|
49
50
|
def on_send(node)
|
50
51
|
mixlib_shellout_run_cmd?(node) do |cmd|
|
51
52
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
52
|
-
corrector.replace(node
|
53
|
+
corrector.replace(node, "shell_out(#{cmd.source})")
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
52
52
|
if %r{http(s)*://ppa.launchpad.net/(.*)/ubuntu$}.match?(uri.arguments&.first&.str_content)
|
53
53
|
add_offense(uri, message: MSG, severity: :refactor) do |corrector|
|
54
54
|
next unless (replacement_val = %r{http(s)*://ppa.launchpad.net/(.*)/ubuntu}.match(node.source)[2])
|
55
|
-
corrector.replace(uri
|
55
|
+
corrector.replace(uri, "uri 'ppa:#{replacement_val}'")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def on_send(node)
|
45
45
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
46
|
-
corrector.replace(node
|
46
|
+
corrector.replace(node, node.source.gsub(/^sysctl_param/, 'sysctl'))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -98,7 +98,7 @@ module RuboCop
|
|
98
98
|
def check_offense(node)
|
99
99
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
100
100
|
package_array_install?(node) do |vals|
|
101
|
-
corrector.replace(node
|
101
|
+
corrector.replace(node, "package #{vals.source}")
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
50
50
|
corrected_value = file.value
|
51
51
|
corrected_value.slice!(%r{^../}) # take the first ../ off the path
|
52
|
-
corrector.replace(node
|
52
|
+
corrector.replace(node, "require_relative '#{corrected_value}'")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
50
50
|
|
51
51
|
def on_send(node)
|
52
52
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
53
|
-
corrector.replace(node
|
53
|
+
corrector.replace(node, node.source.gsub(/^zypper_repo/, 'zypper_repository'))
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -37,6 +37,7 @@ module RuboCop
|
|
37
37
|
extend RuboCop::Cop::AutoCorrector
|
38
38
|
|
39
39
|
MSG = "If a resource includes the `compile_time` property there's no need to also use `.run_action(:some_action)` on the resource block."
|
40
|
+
RESTRICT_ON_SEND = [:run_action].freeze
|
40
41
|
|
41
42
|
def_node_matcher :compile_time_and_run_action?, <<-PATTERN
|
42
43
|
(send
|
@@ -54,7 +55,7 @@ module RuboCop
|
|
54
55
|
def on_send(node)
|
55
56
|
compile_time_and_run_action?(node) do |resource, action, run_action|
|
56
57
|
add_offense(node.loc.selector, message: MSG, severity: :refactor) do |corrector|
|
57
|
-
corrector.replace(node
|
58
|
+
corrector.replace(node, resource.source.gsub(action.to_s, run_action.to_s))
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
|
49
49
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
50
50
|
new_string = "#{helpers.first}(#{plats.map(&:source).join(', ')})"
|
51
|
-
corrector.replace(node
|
51
|
+
corrector.replace(node, new_string)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -61,6 +61,7 @@ module RuboCop
|
|
61
61
|
#
|
62
62
|
class NamePropertyIsRequired < Base
|
63
63
|
MSG = 'Resource properties marked as name properties should not also be required properties'
|
64
|
+
RESTRICT_ON_SEND = [:property, :attribute].freeze
|
64
65
|
|
65
66
|
# match on a property or attribute that has any name and any type and a hash that
|
66
67
|
# contains name_property: true and required: true. These are wrapped in <> which means
|
@@ -46,6 +46,7 @@ module RuboCop
|
|
46
46
|
extend AutoCorrector
|
47
47
|
|
48
48
|
MSG = "This Ohai node attribute is already a string and doesn't need to be converted"
|
49
|
+
RESTRICT_ON_SEND = [:to_s].freeze
|
49
50
|
|
50
51
|
def_node_matcher :attribute_to_s?, <<-PATTERN
|
51
52
|
(send (send (send nil? :node) :[] $(str {"platform" "platform_family" "platform_version" "fqdn" "hostname" "os" "name"}) ) :to_s )
|
@@ -54,7 +55,7 @@ module RuboCop
|
|
54
55
|
def on_send(node)
|
55
56
|
attribute_to_s?(node) do |method|
|
56
57
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
57
|
-
corrector.replace(node
|
58
|
+
corrector.replace(node, "node['#{method.value}']")
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
extend AutoCorrector
|
37
37
|
|
38
38
|
MSG = 'There is no need to validate the input of properties in resources using a regex value that will always pass.'
|
39
|
+
RESTRICT_ON_SEND = [:property, :attribute].freeze
|
39
40
|
|
40
41
|
def_node_matcher :property_with_regex_splat?, <<-PATTERN
|
41
42
|
(send nil? {:property :attribute} (sym _) ... (hash <$(pair (sym :regex) (regexp (str ".*") (regopt))) ...>))
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
return unless props == resource_blk_name && create_action?(node.parent.parent).nil?
|
65
65
|
|
66
66
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
67
|
-
corrector.replace(node
|
67
|
+
corrector.replace(node, 'action :create_if_missing')
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
|
46
46
|
def on_send(node)
|
47
47
|
property?(node) do
|
48
|
-
add_offense(node
|
48
|
+
add_offense(node, message: MSG, severity: :refactor) unless description_hash?(node)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
def on_send(node)
|
52
52
|
insecure_cb_url?(node) do
|
53
53
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
54
|
-
corrector.replace(node
|
54
|
+
corrector.replace(node, node.source.gsub(%r{http://(www.)*}, 'https://'))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -467,7 +467,7 @@ module RuboCop
|
|
467
467
|
return if valid_license?(license.str_content)
|
468
468
|
add_offense(license, message: MSG, severity: :refactor) do |corrector|
|
469
469
|
correct_string = autocorrect_license_string(license.str_content)
|
470
|
-
corrector.replace(license
|
470
|
+
corrector.replace(license, "'#{correct_string}'") if correct_string
|
471
471
|
end
|
472
472
|
end
|
473
473
|
end
|