cookstyle 5.4.13 → 5.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/cookstyle.yml +231 -129
- data/lib/cookstyle.rb +1 -0
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/chef/cookbook_helpers.rb +67 -0
- data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +34 -31
- data/lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb +16 -14
- data/lib/rubocop/cop/chef/correctness/default_maintainer_metadata.rb +22 -20
- data/lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb +32 -30
- data/lib/rubocop/cop/chef/correctness/invalid_license_string.rb +454 -453
- data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +57 -57
- data/lib/rubocop/cop/chef/correctness/metadata_missing_name.rb +18 -16
- data/lib/rubocop/cop/chef/correctness/name_property_and_required.rb +61 -59
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +29 -27
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +29 -27
- data/lib/rubocop/cop/chef/correctness/node_save.rb +46 -0
- data/lib/rubocop/cop/chef/correctness/ohai_default_recipe.rb +47 -0
- data/lib/rubocop/cop/chef/correctness/property_with_default_and_required.rb +35 -33
- data/lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb +29 -27
- data/lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb +52 -0
- data/lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb +51 -0
- data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +52 -0
- data/lib/rubocop/cop/chef/correctness/service_resource.rb +26 -24
- data/lib/rubocop/cop/chef/correctness/tmp_path.rb +30 -28
- data/lib/rubocop/cop/chef/deprecation/attribute_metadata.rb +22 -21
- data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +56 -0
- data/lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb +58 -0
- data/lib/rubocop/cop/chef/deprecation/conflicts_metadata.rb +18 -16
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +21 -19
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +17 -15
- data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +17 -15
- data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +39 -37
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +15 -13
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +24 -22
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +15 -13
- data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +55 -0
- data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +24 -22
- data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +45 -0
- data/lib/rubocop/cop/chef/deprecation/long_description_metadata.rb +21 -19
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +55 -53
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +27 -25
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +27 -25
- data/lib/rubocop/cop/chef/deprecation/provides_metadata.rb +18 -16
- data/lib/rubocop/cop/chef/deprecation/replaces_metadata.rb +18 -16
- data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +23 -21
- data/lib/rubocop/cop/chef/deprecation/suggests_metadata.rb +18 -16
- data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +56 -0
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +53 -0
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +51 -0
- data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +51 -0
- data/lib/rubocop/cop/chef/effortless/data_bags.rb +13 -11
- data/lib/rubocop/cop/chef/effortless/search_used.rb +13 -11
- data/lib/rubocop/cop/chef/modernize/apt_default_recipe.rb +22 -20
- data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +31 -29
- data/lib/rubocop/cop/chef/modernize/build_essential.rb +25 -23
- data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +27 -25
- data/lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb +25 -23
- data/lib/rubocop/cop/chef/modernize/execute_apt_update.rb +19 -17
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +27 -25
- data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +41 -0
- data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +21 -19
- data/lib/rubocop/cop/chef/modernize/powershell_expand_archive.rb +48 -0
- data/lib/rubocop/cop/chef/modernize/powershell_install_package.rb +51 -0
- data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +54 -0
- data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +25 -23
- data/lib/rubocop/cop/chef/modernize/resource_with_allowed_actions.rb +77 -0
- data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +37 -35
- data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +54 -0
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +25 -23
- data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +26 -24
- data/lib/rubocop/cop/chef/{effortless/node_save.rb → modernize/seven_zip_archive.rb} +16 -16
- data/lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb +59 -0
- data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +20 -18
- data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +23 -21
- data/lib/rubocop/cop/chef/modernize/windows_version_helper.rb +20 -18
- data/lib/rubocop/cop/chef/modernize/windows_zipfile.rb +15 -13
- data/lib/rubocop/cop/chef/style/attribute_keys.rb +59 -57
- data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +14 -12
- data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +65 -63
- data/lib/rubocop/cop/chef/style/comments_format.rb +48 -45
- data/lib/rubocop/cop/chef/style/file_mode.rb +32 -30
- metadata +24 -9
- data/lib/rubocop/cop/chef/deprecation/respond_to_metadata.rb +0 -53
- data/lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb +0 -45
- data/lib/rubocop/cop/chef/modernize/resource_with_allowed_action.rb +0 -75
- data/lib/rubocop/cop/chef/modernize/use_inline_resources.rb +0 -54
- data/lib/rubocop/cop/chef/modernize/xml_ruby_recipe.rb +0 -49
- data/lib/rubocop/cop/chef/modernize/yum_dnf_compat_recipe.rb +0 -49
|
@@ -17,18 +17,20 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
module ChefEffortless
|
|
21
|
+
# Data bags cannot be used with the Effortless Infra pattern
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
#
|
|
25
|
+
# # bad
|
|
26
|
+
# data_bag_item('admins', login)
|
|
27
|
+
# data_bag(data_bag_name)
|
|
28
|
+
class CookbookUsesDatabags < Cop
|
|
29
|
+
MSG = 'Cookbook uses data bags, which cannot be used in the Effortless Infra pattern'.freeze
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
def on_send(node)
|
|
32
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if %i(data_bag data_bag_item).include?(node.method_name)
|
|
33
|
+
end
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
end
|
|
@@ -17,18 +17,20 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
module ChefEffortless
|
|
21
|
+
# Search is not compatible with the Effortless Infra pattern
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
#
|
|
25
|
+
# # bad
|
|
26
|
+
# search(:node, 'run_list:recipe\[bacula\:\:server\]')
|
|
27
|
+
#
|
|
28
|
+
class CookbookUsesSearch < Cop
|
|
29
|
+
MSG = 'Cookbook uses search, which cannot be used in the Effortless Infra pattern'.freeze
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
def on_send(node)
|
|
32
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :search
|
|
33
|
+
end
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
end
|
|
@@ -17,28 +17,30 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
module ChefModernize
|
|
21
|
+
# Don't include the apt default recipe to update apt's package cache when you can
|
|
22
|
+
# use the apt_update resource built into Chef Infra Client 12.7 and later.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
#
|
|
26
|
+
# # bad
|
|
27
|
+
# include_recipe 'apt::default'
|
|
28
|
+
# include_recipe 'apt'
|
|
29
|
+
#
|
|
30
|
+
# # good
|
|
31
|
+
# apt_update
|
|
32
|
+
#
|
|
33
|
+
class IncludingAptDefaultRecipe < Cop
|
|
34
|
+
MSG = 'Do not include the Apt default recipe to update package cache. Instead use the apt_update resource, which is built into Chef Infra Client 12.7 and later.'.freeze
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
def_node_matcher :apt_recipe_usage?, <<-PATTERN
|
|
37
|
+
(send nil? :include_recipe (str {"apt" "apt::default"}))
|
|
38
|
+
PATTERN
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
def on_send(node)
|
|
41
|
+
apt_recipe_usage?(node) do
|
|
42
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
43
|
+
end
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
end
|
|
@@ -17,40 +17,42 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
module ChefModernize
|
|
21
|
+
# Over the course of years there have been many different valid community site / Supermarket
|
|
22
|
+
# URLs to use in a cookbook's Berksfile. These old URLs continue to function via redirects,
|
|
23
|
+
# but should be updated to point to the latest Supermarket URL.
|
|
24
|
+
#
|
|
25
|
+
# @example
|
|
26
|
+
#
|
|
27
|
+
# # bad
|
|
28
|
+
# source 'http://community.opscode.com/api/v3'
|
|
29
|
+
# source 'https://supermarket.getchef.com'
|
|
30
|
+
# source 'https://api.berkshelf.com'
|
|
31
|
+
#
|
|
32
|
+
# # good
|
|
33
|
+
# source 'https://supermarket.chef.io'
|
|
34
|
+
#
|
|
35
|
+
class LegacyBerksfileSource < Cop
|
|
36
|
+
MSG = 'Do not use legacy Berksfile community sources. Use Chef Supermarket instead.'.freeze
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
def_node_matcher :berksfile_source?, <<-PATTERN
|
|
39
|
+
(send nil? :source (str #old_berkshelf_url?))
|
|
40
|
+
PATTERN
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
def old_berkshelf_url?(url)
|
|
43
|
+
%w(http://community.opscode.com/api/v3 https://supermarket.getchef.com https://api.berkshelf.com).include?(url)
|
|
44
|
+
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
def on_send(node)
|
|
47
|
+
berksfile_source?(node) do
|
|
48
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
49
|
+
end
|
|
48
50
|
end
|
|
49
|
-
end
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
def autocorrect(node)
|
|
53
|
+
lambda do |corrector|
|
|
54
|
+
corrector.replace(node.loc.expression, "source 'https://supermarket.chef.io'")
|
|
55
|
+
end
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
end
|
|
@@ -17,33 +17,35 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
module ChefModernize
|
|
21
|
+
# Use secure Github and Gitlab URLs for source_url and issues_url
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
#
|
|
25
|
+
# # bad
|
|
26
|
+
# depends 'build-essential'
|
|
27
|
+
# include_recipe 'build-essential::default'
|
|
28
|
+
# include_recipe 'build-essential'
|
|
29
|
+
#
|
|
30
|
+
# # good
|
|
31
|
+
# build_essential 'install compilation tools'
|
|
32
|
+
class UseBuildEssentialResource < Cop
|
|
33
|
+
MSG = 'Use the build_essential resource instead of the legacy build-essential recipe. This resource ships in the build-essential cookbook v5.0+ and is built into Chef Infra Client 14+'.freeze
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
def_node_matcher :build_essential_recipe_usage?, <<-PATTERN
|
|
36
|
+
(send nil? :include_recipe (str {"build-essential" "build-essential::default"}))
|
|
37
|
+
PATTERN
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
def on_send(node)
|
|
40
|
+
build_essential_recipe_usage?(node) do
|
|
41
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
42
|
+
end
|
|
41
43
|
end
|
|
42
|
-
end
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
def autocorrect(node)
|
|
46
|
+
lambda do |corrector|
|
|
47
|
+
corrector.replace(node.loc.expression, "build_essential 'install compilation tools'")
|
|
48
|
+
end
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
end
|
|
@@ -17,35 +17,37 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
module ChefModernize
|
|
21
|
+
# Don't depend on cookbooks made obsolete by Chef 14
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
#
|
|
25
|
+
# # bad
|
|
26
|
+
# depends 'build-essential'
|
|
27
|
+
# depends 'chef_handler'
|
|
28
|
+
# depends 'chef_hostname'
|
|
29
|
+
# depends 'dmg'
|
|
30
|
+
# depends 'mac_os_x'
|
|
31
|
+
# depends 'swap'
|
|
32
|
+
# depends 'sysctl'
|
|
33
|
+
#
|
|
34
|
+
class UnnecessaryDependsChef14 < Cop
|
|
35
|
+
MSG = "Don't depend on cookbooks made obsolete by Chef 14".freeze
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
def_node_matcher :legacy_depends?, <<-PATTERN
|
|
38
|
+
(send nil? :depends (str {"build-essential" "chef_handler" "chef_hostname" "dmg" "mac_os_x" "swap" "sysctl"}))
|
|
39
|
+
PATTERN
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
def on_send(node)
|
|
42
|
+
legacy_depends?(node) do
|
|
43
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
44
|
+
end
|
|
43
45
|
end
|
|
44
|
-
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
def autocorrect(node)
|
|
48
|
+
lambda do |corrector|
|
|
49
|
+
corrector.remove(node.loc.expression)
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
end
|
|
@@ -17,33 +17,35 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
module ChefModernize
|
|
21
|
+
# ChefSpec 7.1 and later auto generate ChefSpec matchers. Matchers in cookbooks can now be removed.
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
#
|
|
25
|
+
# # bad
|
|
26
|
+
# if defined?(ChefSpec)
|
|
27
|
+
# def create_yum_repository(resource_name)
|
|
28
|
+
# ChefSpec::Matchers::ResourceMatcher.new(:yum_repository, :create, resource_name)
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
class DefinesChefSpecMatchers < Cop
|
|
33
|
+
MSG = 'ChefSpec matchers are now auto generated by ChefSpec 7.1+ and do not need to be defined in a cookbook'.freeze
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
def_node_matcher :chefspec_matcher?, <<-PATTERN
|
|
36
|
+
(if ( :defined? (const nil? :ChefSpec)) ... )
|
|
37
|
+
PATTERN
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
def on_if(node)
|
|
40
|
+
chefspec_matcher?(node) do
|
|
41
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
42
|
+
end
|
|
41
43
|
end
|
|
42
|
-
end
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
def autocorrect(node)
|
|
46
|
+
lambda do |corrector|
|
|
47
|
+
corrector.remove(node.loc.expression)
|
|
48
|
+
end
|
|
47
49
|
end
|
|
48
50
|
end
|
|
49
51
|
end
|
|
@@ -17,25 +17,27 @@
|
|
|
17
17
|
module RuboCop
|
|
18
18
|
module Cop
|
|
19
19
|
module Chef
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
module ChefModernize
|
|
21
|
+
# Instead of using the execute resource to to run the `apt-get update` use Chef Infra Client's built-n
|
|
22
|
+
# apt_update resource which is available in Chef Infra Client 12.7 and later.
|
|
23
|
+
#
|
|
24
|
+
# # bad
|
|
25
|
+
# execute 'apt-get update'
|
|
26
|
+
#
|
|
27
|
+
# # good
|
|
28
|
+
# apt_update
|
|
29
|
+
#
|
|
30
|
+
class ExecuteAptUpdate < Cop
|
|
31
|
+
MSG = 'Use the apt_update resource instead of the execute resource to run an apt-get update package cache update'.freeze
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
def_node_matcher :execute_apt_update?, <<-PATTERN
|
|
34
|
+
(send nil? :execute (str "apt-get update"))
|
|
35
|
+
PATTERN
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
def on_send(node)
|
|
38
|
+
execute_apt_update?(node) do
|
|
39
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
40
|
+
end
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
end
|
|
@@ -18,38 +18,40 @@
|
|
|
18
18
|
module RuboCop
|
|
19
19
|
module Cop
|
|
20
20
|
module Chef
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
module ChefModernize
|
|
22
|
+
# There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
#
|
|
26
|
+
# # bad
|
|
27
|
+
# require 'chef/mixin/shell_out'
|
|
28
|
+
# include Chef::Mixin::ShellOut
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
class IncludingMixinShelloutInResources < Cop
|
|
31
|
+
MSG = 'There is no need to include Chef::Mixin::ShellOut in resources or providers as this is already done by Chef Infra Client.'.freeze
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
def_node_matcher :include_shellout?, <<-PATTERN
|
|
34
|
+
(send nil? :include (const (const (const nil? :Chef) :Mixin) :ShellOut))
|
|
35
|
+
PATTERN
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
def_node_matcher :require_shellout?, <<-PATTERN
|
|
38
|
+
(send nil? :require ( str "chef/mixin/shell_out"))
|
|
39
|
+
PATTERN
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
def on_send(node)
|
|
42
|
+
require_shellout?(node) do
|
|
43
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
44
|
+
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
include_shellout?(node) do
|
|
47
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
|
48
|
+
end
|
|
47
49
|
end
|
|
48
|
-
end
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
def autocorrect(node)
|
|
52
|
+
lambda do |corrector|
|
|
53
|
+
corrector.remove(node.loc.expression)
|
|
54
|
+
end
|
|
53
55
|
end
|
|
54
56
|
end
|
|
55
57
|
end
|