cookstyle 6.15.9 → 6.16.4
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 +9 -8
- data/config/disable_all.yml +20 -0
- data/config/upstream.yml +79 -11
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +7 -9
- data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +5 -9
- data/lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb +5 -9
- data/lib/rubocop/cop/chef/correctness/dnf_package_allow_downgrades.rb +5 -8
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +11 -9
- data/lib/rubocop/cop/chef/correctness/invalid_default_action.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb +15 -21
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +15 -23
- data/lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +12 -14
- data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +13 -22
- data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb +4 -3
- data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb +4 -3
- data/lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb +3 -4
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +5 -8
- data/lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb +2 -3
- data/lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb +4 -5
- data/lib/rubocop/cop/chef/correctness/metadata_missing_name.rb +5 -12
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/node_save.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +7 -7
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/powershell_delete_file.rb +4 -4
- data/lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +6 -2
- data/lib/rubocop/cop/chef/correctness/scoped_file_exist.rb +6 -8
- data/lib/rubocop/cop/chef/correctness/service_resource.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/tmp_path.rb +3 -4
- data/lib/rubocop/cop/chef/{correctness → deprecation}/cb_depends_on_self.rb +6 -11
- data/lib/rubocop/cop/chef/deprecation/chef_handler_recipe.rb +5 -8
- data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +7 -10
- data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +15 -28
- data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +5 -8
- data/lib/rubocop/cop/chef/deprecation/chefdk_generators.rb +3 -6
- data/lib/rubocop/cop/chef/deprecation/cheffile.rb +3 -5
- data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +5 -8
- data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +5 -8
- data/lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +5 -8
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +5 -9
- data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +11 -10
- data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +8 -8
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +5 -6
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +11 -12
- data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +6 -9
- data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +5 -9
- data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/name_property_and_default.rb +4 -9
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb +6 -4
- data/lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +5 -9
- data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +7 -7
- data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +5 -9
- data/lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/run_command_helper.rb +4 -4
- data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +5 -7
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +11 -14
- data/lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +11 -16
- data/lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb +4 -9
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +6 -8
- data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +5 -8
- data/lib/rubocop/cop/chef/effortless/berksfile.rb +3 -5
- data/lib/rubocop/cop/chef/effortless/data_bags.rb +2 -2
- data/lib/rubocop/cop/chef/effortless/node_environment.rb +6 -3
- data/lib/rubocop/cop/chef/effortless/node_policygroup.rb +6 -3
- data/lib/rubocop/cop/chef/effortless/node_roles.rb +6 -3
- data/lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb +4 -3
- data/lib/rubocop/cop/chef/effortless/search_used.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/allowed_actions_initializer.rb +16 -16
- data/lib/rubocop/cop/chef/modernize/apt_default_recipe.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +9 -9
- data/lib/rubocop/cop/chef/modernize/build_essential.rb +6 -8
- data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb +11 -10
- data/lib/rubocop/cop/chef/modernize/compile_time_resources.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/cron_d_file_or_template.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +4 -6
- data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +7 -8
- data/lib/rubocop/cop/chef/modernize/default_action_initializer.rb +11 -13
- data/lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/definitions.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/empty_resource_initialize.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/execute_apt_update.rb +6 -4
- data/lib/rubocop/cop/chef/modernize/execute_sc_exe.rb +6 -9
- data/lib/rubocop/cop/chef/modernize/execute_sleep.rb +6 -11
- data/lib/rubocop/cop/chef/modernize/execute_sysctl.rb +5 -9
- data/lib/rubocop/cop/chef/modernize/execute_tzutil.rb +7 -4
- data/lib/rubocop/cop/chef/modernize/foodcritic_comments.rb +7 -12
- data/lib/rubocop/cop/chef/modernize/if_provides_default_action.rb +4 -6
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +12 -9
- data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +4 -6
- data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/node_roles_include.rb +5 -9
- data/lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +4 -6
- data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +4 -6
- data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +5 -6
- data/lib/rubocop/cop/chef/modernize/powershell_expand_archive.rb +3 -4
- data/lib/rubocop/cop/chef/modernize/powershell_guard_interpreter.rb +5 -9
- data/lib/rubocop/cop/chef/modernize/powershell_install_package.rb +3 -4
- data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +3 -4
- data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +5 -9
- data/lib/rubocop/cop/chef/modernize/provides_initializer.rb +13 -15
- data/lib/rubocop/cop/chef/modernize/resource_name_initializer.rb +10 -14
- data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +3 -4
- data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +7 -8
- data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +4 -9
- data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +20 -16
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +6 -8
- data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +6 -8
- data/lib/rubocop/cop/chef/modernize/sc_windows_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/seven_zip_archive.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +3 -8
- data/lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb +5 -7
- data/lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb +6 -10
- data/lib/rubocop/cop/chef/modernize/systctl_param_resource.rb +4 -6
- data/lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +11 -10
- data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +6 -9
- data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +5 -8
- data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +6 -7
- data/lib/rubocop/cop/chef/modernize/windows_zipfile.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/zipfile_resource.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +4 -6
- data/lib/rubocop/cop/chef/redundant/apt_repository_distribution_default.rb +5 -8
- data/lib/rubocop/cop/chef/redundant/apt_repository_notifies_apt_update.rb +6 -8
- data/lib/rubocop/cop/chef/redundant/attribute_metadata.rb +4 -6
- data/lib/rubocop/cop/chef/redundant/conflicts_metadata.rb +4 -6
- data/lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb +6 -9
- data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +4 -5
- data/lib/rubocop/cop/chef/redundant/long_description_metadata.rb +4 -5
- data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +7 -9
- data/lib/rubocop/cop/chef/redundant/name_property_and_required.rb +2 -2
- data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +4 -8
- data/lib/rubocop/cop/chef/redundant/property_splat_regex.rb +8 -9
- data/lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb +4 -9
- data/lib/rubocop/cop/chef/redundant/provides_metadata.rb +4 -5
- data/lib/rubocop/cop/chef/redundant/recipe_metadata.rb +4 -5
- data/lib/rubocop/cop/chef/redundant/replaces_metadata.rb +4 -5
- data/lib/rubocop/cop/chef/redundant/resource_with_nothing_action.rb +5 -8
- data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +5 -7
- data/lib/rubocop/cop/chef/redundant/string_property_with_nil_default.rb +6 -9
- data/lib/rubocop/cop/chef/redundant/suggests_metadata.rb +4 -5
- data/lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb +9 -9
- data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +7 -9
- data/lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb +2 -2
- data/lib/rubocop/cop/chef/sharing/empty_metadata_field.rb +3 -2
- data/lib/rubocop/cop/chef/sharing/include_resource_descriptions.rb +4 -4
- data/lib/rubocop/cop/chef/sharing/include_resource_examples.rb +4 -4
- data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +6 -8
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +7 -12
- data/lib/rubocop/cop/chef/style/chef_whaaat.rb +3 -4
- data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +5 -7
- data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +5 -9
- data/lib/rubocop/cop/chef/style/comments_default_copyright.rb +5 -7
- data/lib/rubocop/cop/chef/style/comments_format.rb +13 -16
- data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +6 -8
- data/lib/rubocop/cop/chef/style/negating_only_if.rb +5 -9
- data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +5 -9
- data/lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb +6 -8
- data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +4 -9
- data/lib/rubocop/cop/chef/style/unnecessary_os_check.rb +17 -28
- data/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +5 -9
- data/lib/rubocop/cop/chef/style/use_platform_helpers.rb +11 -19
- metadata +5 -5
@@ -25,7 +25,8 @@ module RuboCop
|
|
25
25
|
# include Chef::DSL::Recipe
|
26
26
|
# include Chef::DSL::IncludeRecipe
|
27
27
|
#
|
28
|
-
class DslIncludeInResource <
|
28
|
+
class DslIncludeInResource < Base
|
29
|
+
extend AutoCorrector
|
29
30
|
include RangeHelp
|
30
31
|
|
31
32
|
MSG = 'Chef Infra Client 12.4+ includes the Chef::DSL::Recipe in the resource and provider classed by default so there is no need to include this DSL in your resources or providers.'
|
@@ -39,13 +40,9 @@ module RuboCop
|
|
39
40
|
|
40
41
|
def on_send(node)
|
41
42
|
dsl_include?(node) do
|
42
|
-
add_offense(node,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def autocorrect(node)
|
47
|
-
lambda do |corrector|
|
48
|
-
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
43
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
44
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
45
|
+
end
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -28,7 +28,8 @@ module RuboCop
|
|
28
28
|
# super
|
29
29
|
# end
|
30
30
|
#
|
31
|
-
class EmptyResourceInitializeMethod <
|
31
|
+
class EmptyResourceInitializeMethod < Base
|
32
|
+
extend AutoCorrector
|
32
33
|
include RangeHelp
|
33
34
|
|
34
35
|
MSG = 'There is no need for an empty initialize method in a resource'
|
@@ -39,13 +40,9 @@ module RuboCop
|
|
39
40
|
|
40
41
|
def on_def(node)
|
41
42
|
empty_initialize?(node) do
|
42
|
-
add_offense(node,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def autocorrect(node)
|
47
|
-
lambda do |corrector|
|
48
|
-
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
43
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
44
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
45
|
+
end
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -42,7 +42,9 @@ module RuboCop
|
|
42
42
|
# notifies :update, 'apt_update[update apt cache]', :immediately
|
43
43
|
# end
|
44
44
|
#
|
45
|
-
class ExecuteAptUpdate <
|
45
|
+
class ExecuteAptUpdate < Base
|
46
|
+
extend AutoCorrector
|
47
|
+
|
46
48
|
MSG = 'Use the apt_update resource instead of the execute resource to run an apt-get update package cache update'
|
47
49
|
|
48
50
|
def_node_matcher :execute_apt_update?, <<-PATTERN
|
@@ -59,15 +61,15 @@ module RuboCop
|
|
59
61
|
|
60
62
|
def on_send(node)
|
61
63
|
execute_apt_update?(node) do
|
62
|
-
add_offense(node,
|
64
|
+
add_offense(node, message: MSG, severity: :refactor)
|
63
65
|
end
|
64
66
|
|
65
67
|
notification_property?(node) do |val|
|
66
|
-
add_offense(val,
|
68
|
+
add_offense(val, message: MSG, severity: :refactor) if val.str_content&.start_with?('execute[apt-get update]')
|
67
69
|
end
|
68
70
|
|
69
71
|
execute_command?(node) do |val|
|
70
|
-
add_offense(node,
|
72
|
+
add_offense(node, message: MSG, severity: :refactor) if val.str_content == 'apt-get update'
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
# action :delete
|
33
33
|
# end
|
34
34
|
#
|
35
|
-
class ExecuteScExe <
|
35
|
+
class ExecuteScExe < Base
|
36
36
|
include RuboCop::Chef::CookbookHelpers
|
37
37
|
extend TargetChefVersion
|
38
38
|
|
@@ -42,22 +42,19 @@ module RuboCop
|
|
42
42
|
|
43
43
|
# non block execute resources
|
44
44
|
def on_send(node)
|
45
|
-
return unless node.method_name == :execute
|
46
|
-
|
47
45
|
# use a regex on source instead of .value in case there's string interpolation which adds a complex dstr type
|
48
46
|
# with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
return unless node&.arguments.first&.source&.match?(/^("|')sc.exe/) && node.method_name == :execute
|
48
|
+
|
49
|
+
add_offense(node, message: MSG, severity: :refactor)
|
52
50
|
end
|
53
51
|
|
54
52
|
# block execute resources
|
55
53
|
def on_block(node)
|
56
54
|
match_property_in_resource?(:execute, 'command', node) do |code_property|
|
57
55
|
property_data = method_arg_ast_to_string(code_property)
|
58
|
-
|
59
|
-
|
60
|
-
end
|
56
|
+
return unless property_data && property_data.match?(/^sc.exe/i)
|
57
|
+
add_offense(node, message: MSG, severity: :refactor)
|
61
58
|
end
|
62
59
|
end
|
63
60
|
end
|
@@ -46,29 +46,24 @@ module RuboCop
|
|
46
46
|
|
47
47
|
# non block execute resources
|
48
48
|
def on_send(node)
|
49
|
-
return unless node.method_name == :execute
|
50
|
-
|
51
49
|
# use a regex on source instead of .value in case there's string interpolation which adds a complex dstr type
|
52
50
|
# with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
|
53
|
-
|
54
|
-
|
55
|
-
end
|
51
|
+
return unless node.method_name == :execute && node&.arguments.first&.source&.match?(/^("|')sleep/)
|
52
|
+
add_offense(node, message: MSG, severity: :refactor)
|
56
53
|
end
|
57
54
|
|
58
55
|
# block execute resources
|
59
56
|
def on_block(node)
|
60
57
|
match_property_in_resource?(:execute, 'command', node) do |code_property|
|
61
58
|
property_data = method_arg_ast_to_string(code_property)
|
62
|
-
|
63
|
-
|
64
|
-
end
|
59
|
+
next unless property_data && property_data.match?(/^sleep/i)
|
60
|
+
add_offense(node, message: MSG, severity: :refactor)
|
65
61
|
end
|
66
62
|
|
67
63
|
match_property_in_resource?(:bash, 'code', node) do |code_property|
|
68
64
|
property_data = method_arg_ast_to_string(code_property)
|
69
|
-
|
70
|
-
|
71
|
-
end
|
65
|
+
next unless property_data && property_data.match?(/^sleep/i)
|
66
|
+
add_offense(node, message: MSG, severity: :refactor)
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
# value '9000 65500'
|
37
37
|
# end
|
38
38
|
#
|
39
|
-
class ExecuteSysctl <
|
39
|
+
class ExecuteSysctl < Base
|
40
40
|
include RuboCop::Chef::CookbookHelpers
|
41
41
|
extend TargetChefVersion
|
42
42
|
|
@@ -46,22 +46,18 @@ module RuboCop
|
|
46
46
|
|
47
47
|
# non block execute resources
|
48
48
|
def on_send(node)
|
49
|
-
return unless node.method_name == :execute
|
50
|
-
|
51
49
|
# use a regex on source instead of .value in case there's string interpolation which adds a complex dstr type
|
52
50
|
# with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
|
53
|
-
|
54
|
-
|
55
|
-
end
|
51
|
+
return unless node.method_name == :execute && node&.arguments.first&.source&.match?(/^("|')sysctl -p/)
|
52
|
+
add_offense(node, message: MSG, severity: :refactor)
|
56
53
|
end
|
57
54
|
|
58
55
|
# block execute resources
|
59
56
|
def on_block(node)
|
60
57
|
match_property_in_resource?(:execute, 'command', node) do |code_property|
|
61
58
|
property_data = method_arg_ast_to_string(code_property)
|
62
|
-
|
63
|
-
|
64
|
-
end
|
59
|
+
return unless property_data && property_data.match?(%r{^(/sbin/)?sysctl -p}i)
|
60
|
+
add_offense(node, message: MSG, severity: :refactor)
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
# # good
|
38
38
|
# timezone 'UTC'
|
39
39
|
#
|
40
|
-
class ExecuteTzUtil <
|
40
|
+
class ExecuteTzUtil < Base
|
41
41
|
include RuboCop::Chef::CookbookHelpers
|
42
42
|
extend TargetChefVersion
|
43
43
|
|
@@ -51,17 +51,20 @@ module RuboCop
|
|
51
51
|
|
52
52
|
def on_send(node)
|
53
53
|
execute_resource?(node) do
|
54
|
-
|
54
|
+
return unless node.arguments.first.value.match?(/^tzutil/i)
|
55
|
+
add_offense(node, message: MSG, severity: :refactor)
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
59
|
def on_block(node)
|
59
60
|
match_property_in_resource?(:execute, 'command', node) do |code_property|
|
60
|
-
|
61
|
+
next unless calls_tzutil?(code_property)
|
62
|
+
add_offense(node, message: MSG, severity: :refactor)
|
61
63
|
end
|
62
64
|
|
63
65
|
match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
|
64
|
-
|
66
|
+
next unless calls_tzutil?(code_property)
|
67
|
+
add_offense(node, message: MSG, severity: :refactor)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
@@ -27,24 +27,19 @@ module RuboCop
|
|
27
27
|
# # bad
|
28
28
|
# # ~FC013
|
29
29
|
#
|
30
|
-
class FoodcriticComments <
|
31
|
-
|
30
|
+
class FoodcriticComments < Base
|
31
|
+
extend AutoCorrector
|
32
32
|
|
33
|
-
|
34
|
-
return unless processed_source.ast
|
33
|
+
MSG = 'Remove legacy code comments that disable Foodcritic rules'
|
35
34
|
|
35
|
+
def on_new_investigation
|
36
36
|
processed_source.comments.each do |comment|
|
37
|
-
|
38
|
-
|
37
|
+
next unless comment.text.match?(/#\s*~FC\d{3}.*/)
|
38
|
+
add_offense(comment, message: MSG, severity: :refactor) do |corrector|
|
39
|
+
corrector.remove(comment.loc.expression)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
42
|
-
|
43
|
-
def autocorrect(node)
|
44
|
-
lambda do |corrector|
|
45
|
-
corrector.remove(node.loc.expression)
|
46
|
-
end
|
47
|
-
end
|
48
43
|
end
|
49
44
|
end
|
50
45
|
end
|
@@ -29,17 +29,15 @@ module RuboCop
|
|
29
29
|
# # good
|
30
30
|
# default_action :foo
|
31
31
|
#
|
32
|
-
class IfProvidesDefaultAction <
|
32
|
+
class IfProvidesDefaultAction < Base
|
33
|
+
extend AutoCorrector
|
34
|
+
|
33
35
|
MSG = 'if defined?(default_action) is no longer necessary in Chef Resources as default_action shipped in Chef 10.8.'
|
34
36
|
|
35
37
|
def on_defined?(node)
|
36
38
|
return unless node.arguments.first == s(:send, nil, :default_action)
|
37
39
|
node = node.parent if node.parent.respond_to?(:if?) && node.parent.if? # we want the whole if statement
|
38
|
-
add_offense(node,
|
39
|
-
end
|
40
|
-
|
41
|
-
def autocorrect(node)
|
42
|
-
lambda do |corrector|
|
40
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
43
41
|
corrector.replace(node.loc.expression, node.children[1].source)
|
44
42
|
end
|
45
43
|
end
|
@@ -30,7 +30,8 @@ module RuboCop
|
|
30
30
|
# require 'chef/mixin/powershell_out'
|
31
31
|
# include Chef::Mixin::PowershellOut
|
32
32
|
#
|
33
|
-
class IncludingMixinShelloutInResources <
|
33
|
+
class IncludingMixinShelloutInResources < Base
|
34
|
+
extend AutoCorrector
|
34
35
|
include RangeHelp
|
35
36
|
|
36
37
|
MSG = 'There is no need to include Chef::Mixin::ShellOut or Chef::Mixin::PowershellOut in resources or providers as this is already done by Chef Infra Client 12.4+.'
|
@@ -60,7 +61,9 @@ module RuboCop
|
|
60
61
|
|
61
62
|
# only add offenses when we're in a custom resource or HWRP, but not a plain old library
|
62
63
|
if containing_dir == 'resources' || hwrp_classes?(processed_source.ast)
|
63
|
-
add_offense(node,
|
64
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
65
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
66
|
+
end
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
@@ -73,12 +76,6 @@ module RuboCop
|
|
73
76
|
check_for_offenses(node)
|
74
77
|
end
|
75
78
|
end
|
76
|
-
|
77
|
-
def autocorrect(node)
|
78
|
-
lambda do |corrector|
|
79
|
-
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
80
|
-
end
|
81
|
-
end
|
82
79
|
end
|
83
80
|
end
|
84
81
|
end
|
@@ -34,8 +34,9 @@ module RuboCop
|
|
34
34
|
# path 'C:\expand_here'
|
35
35
|
# end
|
36
36
|
#
|
37
|
-
class LibarchiveFileResource <
|
37
|
+
class LibarchiveFileResource < Base
|
38
38
|
extend TargetChefVersion
|
39
|
+
extend AutoCorrector
|
39
40
|
|
40
41
|
minimum_target_chef_version '15.0'
|
41
42
|
|
@@ -46,16 +47,18 @@ module RuboCop
|
|
46
47
|
PATTERN
|
47
48
|
|
48
49
|
def on_send(node)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# The need for this goes away once https://github.com/rubocop-hq/rubocop/pull/8365 is pulled into Cookstyle
|
51
|
+
if node.method_name == :libarchive_file
|
52
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
53
|
+
corrector.replace(node.loc.expression, node.source.gsub('libarchive_file', 'archive_file'))
|
54
|
+
end
|
53
55
|
end
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
notification_property?(node) do |val|
|
58
|
+
next unless val.str_content&.start_with?('libarchive_file')
|
59
|
+
add_offense(val, message: MSG, severity: :refactor) do |corrector|
|
60
|
+
corrector.replace(node.loc.expression, node.source.gsub('libarchive_file', 'archive_file'))
|
61
|
+
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
end
|
@@ -36,19 +36,17 @@ module RuboCop
|
|
36
36
|
# value '2'
|
37
37
|
# end
|
38
38
|
#
|
39
|
-
class MacOsXUserdefaults <
|
39
|
+
class MacOsXUserdefaults < Base
|
40
40
|
extend TargetChefVersion
|
41
|
+
extend AutoCorrector
|
41
42
|
|
42
43
|
minimum_target_chef_version '14.0'
|
43
44
|
|
44
45
|
MSG = 'The mac_os_x_userdefaults resource was renamed to macos_userdefaults when it was added to Chef Infra Client 14.0. The new resource name should be used.'
|
45
46
|
|
46
47
|
def on_send(node)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def autocorrect(node)
|
51
|
-
lambda do |corrector|
|
48
|
+
return unless node.method_name == :mac_os_x_userdefaults
|
49
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
52
50
|
corrector.replace(node.loc.expression, node.source.gsub(/^mac_os_x_userdefaults/, 'macos_userdefaults'))
|
53
51
|
end
|
54
52
|
end
|
@@ -26,7 +26,8 @@ module RuboCop
|
|
26
26
|
# # bad
|
27
27
|
# depends 'minitest-handler'
|
28
28
|
#
|
29
|
-
class MinitestHandlerUsage <
|
29
|
+
class MinitestHandlerUsage < Base
|
30
|
+
extend AutoCorrector
|
30
31
|
include RangeHelp
|
31
32
|
|
32
33
|
MSG = 'Use Chef InSpec for testing instead of the Minitest Handler cookbook pattern.'
|
@@ -37,13 +38,9 @@ module RuboCop
|
|
37
38
|
|
38
39
|
def on_send(node)
|
39
40
|
minitest_depends?(node) do
|
40
|
-
add_offense(node,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def autocorrect(node)
|
45
|
-
lambda do |corrector|
|
46
|
-
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
41
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
42
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
43
|
+
end
|
47
44
|
end
|
48
45
|
end
|
49
46
|
end
|
@@ -29,7 +29,9 @@ module RuboCop
|
|
29
29
|
# # good
|
30
30
|
# node.role?('foo')
|
31
31
|
#
|
32
|
-
class NodeRolesInclude <
|
32
|
+
class NodeRolesInclude < Base
|
33
|
+
extend AutoCorrector
|
34
|
+
|
33
35
|
MSG = "Use `node.role?('foo')` to check if a node includes a role instead of `node['roles'].include?('foo')`."
|
34
36
|
|
35
37
|
def_node_matcher :node_role_include?, <<-PATTERN
|
@@ -41,14 +43,8 @@ module RuboCop
|
|
41
43
|
PATTERN
|
42
44
|
|
43
45
|
def on_send(node)
|
44
|
-
node_role_include?(node) do
|
45
|
-
add_offense(node,
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def autocorrect(node)
|
50
|
-
lambda do |corrector|
|
51
|
-
node_role_include?(node) do |val|
|
46
|
+
node_role_include?(node) do |val|
|
47
|
+
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
52
48
|
corrector.replace(node.loc.expression, "node.role?(#{val.source})")
|
53
49
|
end
|
54
50
|
end
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
# include_recipe 'ohai::default'
|
30
30
|
# include_recipe 'ohai'
|
31
31
|
#
|
32
|
-
class IncludingOhaiDefaultRecipe <
|
32
|
+
class IncludingOhaiDefaultRecipe < Base
|
33
33
|
MSG = "Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely"
|
34
34
|
|
35
35
|
def_node_matcher :ohai_recipe_usage?, <<-PATTERN
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
|
39
39
|
def on_send(node)
|
40
40
|
ohai_recipe_usage?(node) do
|
41
|
-
add_offense(node,
|
41
|
+
add_offense(node, message: MSG, severity: :refactor)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|