cookstyle 6.16.4 → 6.17.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cookstyle +1 -1
- data/config/cookstyle.yml +47 -2
- data/config/upstream.yml +0 -1
- data/lib/cookstyle.rb +2 -2
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/invalid_default_action.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/service_resource.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +1 -0
- data/lib/rubocop/cop/chef/correctness/tmp_path.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/ use_automatic_resource_name.rb +1 -2
- data/lib/rubocop/cop/chef/deprecation/cb_depends_on_self.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/chef_handler_recipe.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +86 -0
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +8 -4
- data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +10 -11
- data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +51 -0
- data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +67 -0
- data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/name_property_and_default.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/run_command_helper.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +5 -2
- data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +10 -11
- data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +61 -0
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -0
- data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +1 -0
- data/lib/rubocop/cop/chef/effortless/data_bags.rb +2 -1
- data/lib/rubocop/cop/chef/effortless/node_environment.rb +2 -2
- data/lib/rubocop/cop/chef/effortless/node_policygroup.rb +2 -2
- data/lib/rubocop/cop/chef/effortless/node_roles.rb +2 -2
- data/lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb +2 -2
- data/lib/rubocop/cop/chef/effortless/search_used.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/apt_default_recipe.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/execute_apt_update.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/execute_sc_exe.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/execute_sleep.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/execute_sysctl.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/execute_tzutil.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb +1 -0
- 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 -0
- data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +1 -1
- data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/sc_windows_resource.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/seven_zip_archive.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/{systctl_param_resource.rb → sysctl_param_resource.rb} +1 -1
- data/lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +2 -2
- data/lib/rubocop/cop/chef/modernize/windows_zipfile.rb +2 -1
- data/lib/rubocop/cop/chef/modernize/zipfile_resource.rb +1 -0
- data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
- data/lib/rubocop/cop/chef/redundant/attribute_metadata.rb +1 -1
- data/lib/rubocop/cop/chef/redundant/conflicts_metadata.rb +1 -1
- data/lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb +7 -9
- data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/redundant/long_description_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/redundant/property_with_default_and_required.rb +1 -0
- data/lib/rubocop/cop/chef/redundant/provides_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/redundant/recipe_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/redundant/replaces_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +1 -0
- data/lib/rubocop/cop/chef/redundant/string_property_with_nil_default.rb +1 -0
- data/lib/rubocop/cop/chef/redundant/suggests_metadata.rb +1 -2
- data/lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb +1 -0
- data/lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb +1 -0
- data/lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb +1 -0
- data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -0
- data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -0
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -0
- data/lib/rubocop/cop/chef/style/file_mode.rb +1 -0
- data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +1 -0
- data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +1 -0
- data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -0
- metadata +7 -3
@@ -44,20 +44,19 @@ module RuboCop
|
|
44
44
|
|
45
45
|
minimum_target_chef_version '14.3'
|
46
46
|
|
47
|
-
DEPRECATED_SHELLOUT_METHODS = %i( shell_out_compact
|
48
|
-
shell_out_compact!
|
49
|
-
shell_out_compact_timeout
|
50
|
-
shell_out_compact_timeout!
|
51
|
-
shell_out_with_timeout
|
52
|
-
shell_out_with_timeout!
|
53
|
-
shell_out_with_systems_locale
|
54
|
-
shell_out_with_systems_locale!
|
55
|
-
).freeze
|
56
|
-
|
57
47
|
MSG = 'Many legacy specialized shell_out methods were replaced in Chef Infra Client 14.3 and removed in Chef Infra Client 15. Use shell_out and any additional options if necessary.'
|
48
|
+
RESTRICT_ON_SEND = %i( shell_out_compact
|
49
|
+
shell_out_compact!
|
50
|
+
shell_out_compact_timeout
|
51
|
+
shell_out_compact_timeout!
|
52
|
+
shell_out_with_timeout
|
53
|
+
shell_out_with_timeout!
|
54
|
+
shell_out_with_systems_locale
|
55
|
+
shell_out_with_systems_locale!
|
56
|
+
).freeze
|
58
57
|
|
59
58
|
def on_send(node)
|
60
|
-
add_offense(node, message: MSG, severity: :warning)
|
59
|
+
add_offense(node, message: MSG, severity: :warning)
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
@@ -30,9 +30,10 @@ module RuboCop
|
|
30
30
|
#
|
31
31
|
class DeprecatedWindowsVersionCheck < Base
|
32
32
|
MSG = "Don't use the deprecated older_than_win_2012_or_8? helper. Windows versions before 2012 and 8 are now end of life and this helper will always return false."
|
33
|
+
RESTRICT_ON_SEND = [:older_than_win_2012_or_8?].freeze
|
33
34
|
|
34
35
|
def on_send(node)
|
35
|
-
add_offense(node, message: MSG, severity: :warning)
|
36
|
+
add_offense(node, message: MSG, severity: :warning)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
@@ -31,9 +31,10 @@ module RuboCop
|
|
31
31
|
#
|
32
32
|
class EasyInstallResource < Base
|
33
33
|
MSG = "Don't use the deprecated easy_install resource removed in Chef Infra Client 13"
|
34
|
+
RESTRICT_ON_SEND = [:easy_install].freeze
|
34
35
|
|
35
36
|
def on_send(node)
|
36
|
-
add_offense(node, message: MSG, severity: :warning)
|
37
|
+
add_offense(node, message: MSG, severity: :warning)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
|
35
35
|
class EOLAuditModeUsage < Base
|
36
36
|
MSG = 'The beta Audit Mode feature in Chef Infra Client was removed in Chef Infra Client 15.0. Users should instead use InSpec and the audit cookbook. See https://www.inspec.io/ for more information.'
|
37
|
+
RESTRICT_ON_SEND = [:control_group].freeze
|
37
38
|
|
38
39
|
def_node_matcher :control_group?, '(send nil? :control_group ...)'
|
39
40
|
|
@@ -38,9 +38,9 @@ module RuboCop
|
|
38
38
|
extend AutoCorrector
|
39
39
|
|
40
40
|
MSG = 'Use ignore_failure method instead of the deprecated epic_fail method'
|
41
|
+
RESTRICT_ON_SEND = [:epic_fail].freeze
|
41
42
|
|
42
43
|
def on_send(node)
|
43
|
-
return unless node.method_name == :epic_fail
|
44
44
|
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
45
45
|
corrector.replace(node.loc.expression, 'ignore_failure true')
|
46
46
|
end
|
@@ -31,9 +31,10 @@ module RuboCop
|
|
31
31
|
#
|
32
32
|
class ErlCallResource < Base
|
33
33
|
MSG = "Don't use the deprecated erl_call resource removed in Chef Infra Client 13"
|
34
|
+
RESTRICT_ON_SEND = [:erl_call].freeze
|
34
35
|
|
35
36
|
def on_send(node)
|
36
|
-
add_offense(node, message: MSG, severity: :warning)
|
37
|
+
add_offense(node, message: MSG, severity: :warning)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# 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
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# In Chef Infra Client 13 and later you must set path env vars in execute resources using the `environment` property not the legacy `path` property.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# execute 'some_cmd' do
|
29
|
+
# path '/foo/bar'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# execute 'some_cmd' do
|
34
|
+
# environment {path: '/foo/bar'}
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
class ExecutePathProperty < Base
|
38
|
+
include RuboCop::Chef::CookbookHelpers
|
39
|
+
|
40
|
+
MSG = 'In Chef Infra Client 13 and later you must set path env vars in execute resources using the `environment` property not the legacy `path` property.'
|
41
|
+
|
42
|
+
def on_block(node)
|
43
|
+
match_property_in_resource?(:execute, 'path', node) do |offense|
|
44
|
+
add_offense(offense.loc.expression, message: MSG, severity: :warning) # @todo: we could probably autocorrect this with some work
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# 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
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# execute 'some_cmd' do
|
29
|
+
# creates 'something'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# execute 'some_cmd' do
|
34
|
+
# creates '/tmp/something'
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# execute 'some_cmd' do
|
38
|
+
# creates 'something'
|
39
|
+
# cwd '/tmp/'
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
class ExecuteRelativeCreatesWithoutCwd < Base
|
43
|
+
include RuboCop::Chef::CookbookHelpers
|
44
|
+
|
45
|
+
MSG = "In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property."
|
46
|
+
|
47
|
+
def on_block(node)
|
48
|
+
match_property_in_resource?(:execute, 'creates', node) do |offense|
|
49
|
+
return unless offense.arguments.count == 1 # we can only analyze simple string args
|
50
|
+
return unless offense.arguments.first.str_type? # we can only analyze simple string args
|
51
|
+
|
52
|
+
# skip any creates that are abs paths https://rubular.com/r/3TbDsgcAa1EaIF
|
53
|
+
return if offense.arguments.first.value.match?(%r{^(/|[a-zA-Z]:)})
|
54
|
+
|
55
|
+
# return if we have a cwd property
|
56
|
+
match_property_in_resource?(:execute, 'cwd', node) do
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
add_offense(offense.loc.expression, message: MSG, severity: :warning)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -61,6 +61,7 @@ module RuboCop
|
|
61
61
|
extend AutoCorrector
|
62
62
|
|
63
63
|
MSG = 'Use the new-style notification syntax which allows you to notify resources defined later in a recipe or resource.'
|
64
|
+
RESTRICT_ON_SEND = [:notifies, :subscribes].freeze
|
64
65
|
|
65
66
|
def_node_matcher :legacy_notify?, <<-PATTERN
|
66
67
|
(send nil? ${:notifies :subscribes} $(sym _) (send nil? :resources (hash (pair $(sym _) $(...) ) ) ) $... )
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
#
|
36
36
|
class LegacyYumCookbookRecipes < Base
|
37
37
|
MSG = 'The elrepo, epel, ius, remi, and repoforge recipes were split into their own cookbooks and the yum recipe was renamed to be default with the release of yum cookbook 3.0 (Dec 2013).'
|
38
|
+
RESTRICT_ON_SEND = [:include_recipe].freeze
|
38
39
|
|
39
40
|
def_node_matcher :old_yum_recipe?, <<-PATTERN
|
40
41
|
(send nil? :include_recipe (str {"yum::elrepo" "yum::epel" "yum::ius" "yum::remi" "yum::repoforge" "yum::yum"}))
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
extend AutoCorrector
|
37
37
|
|
38
38
|
MSG = "A resource property can't be marked as a name_property and also have a default value. This will fail in Chef Infra Client 13 or later."
|
39
|
+
RESTRICT_ON_SEND = [:attribute, :property].freeze
|
39
40
|
|
40
41
|
# match on a property or attribute that has any name and any type and a hash that
|
41
42
|
# contains name_property/name_attribute true and any default value. These are wrapped in
|
@@ -49,9 +49,10 @@ module RuboCop
|
|
49
49
|
#
|
50
50
|
class PartialSearchHelperUsage < Base
|
51
51
|
MSG = 'Legacy partial_search usage should be updated to use :filter_result in the search helper instead'
|
52
|
+
RESTRICT_ON_SEND = [:partial_search].freeze
|
52
53
|
|
53
54
|
def on_send(node)
|
54
|
-
add_offense(node, message: MSG, severity: :warning)
|
55
|
+
add_offense(node, message: MSG, severity: :warning)
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -39,6 +39,7 @@ module RuboCop
|
|
39
39
|
minimum_target_chef_version '15.0'
|
40
40
|
|
41
41
|
MSG = 'The poise_archive resource in the deprecated poise-archive should be replaced with the archive_file resource found in Chef Infra Client 15+'
|
42
|
+
RESTRICT_ON_SEND = [:depends].freeze
|
42
43
|
|
43
44
|
def_node_matcher :depends_poise_archive?, <<-PATTERN
|
44
45
|
(send nil? :depends (str "poise-archive"))
|
@@ -37,9 +37,9 @@ module RuboCop
|
|
37
37
|
def_node_search :provides, '(send nil? :provides ...)'
|
38
38
|
|
39
39
|
def on_def(node)
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
return unless node.method_name == :provides?
|
41
|
+
|
42
|
+
add_offense(node, message: MSG, severity: :warning) if provides(processed_source.ast).count == 0
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -31,9 +31,10 @@ module RuboCop
|
|
31
31
|
#
|
32
32
|
class ResourceUsesDslNameMethod < Base
|
33
33
|
MSG = 'Use resource_name instead of the dsl_name method in resources. This will cause failures in Chef Infra Client 13 and later.'
|
34
|
+
RESTRICT_ON_SEND = [:dsl_name].freeze
|
34
35
|
|
35
36
|
def on_send(node)
|
36
|
-
add_offense(node, message: MSG, severity: :warning)
|
37
|
+
add_offense(node, message: MSG, severity: :warning)
|
37
38
|
end
|
38
39
|
|
39
40
|
# potential autocorrect is new_resource.updated_by_last_action true, but we need to actually see what class we were called from
|
@@ -33,6 +33,7 @@ module RuboCop
|
|
33
33
|
extend AutoCorrector
|
34
34
|
|
35
35
|
MSG = 'Starting with Chef Infra Client 16, using `resource_name` without also using `provides` will result in resource failures. Make sure to use both `resource_name` and `provides` to change the name of the resource. You can also omit `resource_name` entirely if the value set matches the name Chef Infra Client automatically assigns based on COOKBOOKNAME_FILENAME.'
|
36
|
+
RESTRICT_ON_SEND = [:resource_name].freeze
|
36
37
|
|
37
38
|
def_node_matcher :resource_name?, '(send nil? :resource_name (sym $_ ))'
|
38
39
|
|
@@ -28,9 +28,10 @@ module RuboCop
|
|
28
28
|
#
|
29
29
|
class ResourceUsesProviderBaseMethod < Base
|
30
30
|
MSG = "Don't use the deprecated provider_base method in a resource to specify the provider module to use. Instead, the provider should call provides to register itself, or the resource should call provider to specify the provider to use. This will cause failures in Chef Infra Client 13 and later."
|
31
|
+
RESTRICT_ON_SEND = [:provider_base].freeze
|
31
32
|
|
32
33
|
def on_send(node)
|
33
|
-
add_offense(node, message: MSG, severity: :warning)
|
34
|
+
add_offense(node, message: MSG, severity: :warning)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
extend RuboCop::Cop::AutoCorrector
|
37
37
|
|
38
38
|
MSG = 'Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.'
|
39
|
+
RESTRICT_ON_SEND = [:shell_out!, :shell_out].freeze
|
39
40
|
|
40
41
|
def_node_matcher :positional_shellout?, <<-PATTERN
|
41
42
|
(send nil? {:shell_out :shell_out!} ... $(hash ... ))
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
#
|
36
36
|
class UsesRunCommandHelper < Base
|
37
37
|
MSG = "Use 'shell_out!' instead of the legacy 'run_command' or 'run_command_with_systems_locale' helpers for shelling out. The run_command helper was removed in Chef Infra Client 13."
|
38
|
+
RESTRICT_ON_SEND = [:require, :run_command, :run_command_with_systems_locale, :include].freeze
|
38
39
|
|
39
40
|
def_node_matcher :calls_run_command?, '(send nil? {:run_command :run_command_with_systems_locale} ...)'
|
40
41
|
def_node_matcher :require_mixin_command?, '(send nil? :require (str "chef/mixin/command"))'
|
@@ -39,6 +39,7 @@ module RuboCop
|
|
39
39
|
extend AutoCorrector
|
40
40
|
|
41
41
|
MSG = "Don't use deprecated positional parameters in cookbook search queries."
|
42
|
+
RESTRICT_ON_SEND = [:search].freeze
|
42
43
|
|
43
44
|
NAMED_PARAM_LOOKUP_TABLE = [nil, nil, 'start', 'rows', 'filter_result'].freeze
|
44
45
|
|
@@ -56,6 +57,8 @@ module RuboCop
|
|
56
57
|
|
57
58
|
private
|
58
59
|
|
60
|
+
VALID_TYPES = %i(send hash block_pass).freeze
|
61
|
+
|
59
62
|
#
|
60
63
|
# Are the arguments in the passed node object positional
|
61
64
|
#
|
@@ -67,7 +70,7 @@ module RuboCop
|
|
67
70
|
return false if node.arguments.count < 3
|
68
71
|
node.arguments[2..-1].each do |arg|
|
69
72
|
# hashes, blocks, or variable/methods are valid. Anything else is not
|
70
|
-
return true unless
|
73
|
+
return true unless VALID_TYPES.include?(arg.type)
|
71
74
|
end
|
72
75
|
false
|
73
76
|
end
|
@@ -80,7 +83,7 @@ module RuboCop
|
|
80
83
|
# @return [String]
|
81
84
|
#
|
82
85
|
def corrected_string(node)
|
83
|
-
args = node.arguments
|
86
|
+
args = node.arguments.dup
|
84
87
|
|
85
88
|
# If the 2nd argument is a String and not an Integer as a String
|
86
89
|
# then it's the old sort field and we need to delete it. Same thing
|
@@ -34,21 +34,20 @@ module RuboCop
|
|
34
34
|
extend AutoCorrector
|
35
35
|
|
36
36
|
MSG = 'use_inline_resources is now the default for resources in Chef Infra Client 13+ and does not need to be specified.'
|
37
|
+
RESTRICT_ON_SEND = [:use_inline_resources].freeze
|
37
38
|
|
38
39
|
def on_send(node)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
return if node.parent && node.parent.defined_type?
|
40
|
+
# don't alert on the use_inline_resources within the defined? check
|
41
|
+
# that would result in 2 alerts on the same line and wouldn't be useful
|
42
|
+
return if node.parent && node.parent.defined_type?
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
# catch the full offense if the method is gated like this: use_inline_resources if defined?(use_inline_resources)
|
45
|
+
if node.parent && node.parent.if_type? && %i(defined? respond_to?).include?(node.parent.children.first.method_name)
|
46
|
+
node = node.parent
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
49
|
+
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
50
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
52
51
|
end
|
53
52
|
end
|
54
53
|
end
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
|
49
49
|
def on_block(node)
|
50
50
|
match_property_in_resource?(:windows_feature, :install_method, node) do |prop_node|
|
51
|
-
add_offense(prop_node, message: MSG, severity: :warning) if prop_node.source.
|
51
|
+
add_offense(prop_node, message: MSG, severity: :warning) if prop_node.source.include?(':servermanagercmd')
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# 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
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# windows_package 'AppveyorDeploymentAgent' do
|
29
|
+
# source 'https://www.example.com/appveyor.msi'
|
30
|
+
# installer_type 'msi'
|
31
|
+
# options "/quiet /qn /norestart /log install.log"
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# windows_package 'AppveyorDeploymentAgent' do
|
36
|
+
# source 'https://www.example.com/appveyor.msi'
|
37
|
+
# installer_type :msi
|
38
|
+
# options "/quiet /qn /norestart /log install.log"
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
class WindowsPackageInstallerTypeString < Base
|
42
|
+
include RuboCop::Chef::CookbookHelpers
|
43
|
+
extend AutoCorrector
|
44
|
+
|
45
|
+
MSG = "In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol."
|
46
|
+
|
47
|
+
def on_block(node)
|
48
|
+
match_property_in_resource?(:windows_package, 'installer_type', node) do |offense|
|
49
|
+
return unless offense.arguments.count == 1 # we can only analyze simple string args
|
50
|
+
return unless offense.arguments.first.str_type? # anything else is fine
|
51
|
+
|
52
|
+
add_offense(offense.loc.expression, message: MSG, severity: :warning) do |corrector|
|
53
|
+
corrector.replace(offense.arguments.first.source_range, ":#{offense.arguments.first.value}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|