cookstyle 6.2.9 → 6.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/config/cookstyle.yml +306 -15
- data/config/disable_all.yml +21 -3
- data/config/upstream.yml +141 -35
- data/lib/cookstyle.rb +1 -1
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/chef/platform_helpers.rb +2 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +10 -4
- data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +65 -0
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +77 -0
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +59 -0
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +6 -1
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +24 -3
- data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +93 -0
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +15 -5
- data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +64 -0
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
- data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +1 -1
- data/lib/rubocop/cop/target_chef_version.rb +4 -0
- data/lib/rubocop/monkey_patches/team.rb +24 -0
- metadata +14 -5
- data/lib/rubocop/monkey_patches/commissioner.rb +0 -26
data/lib/cookstyle.rb
CHANGED
@@ -11,7 +11,7 @@ require 'rubocop/monkey_patches/comment_config.rb'
|
|
11
11
|
# monkey patches needed for the TargetChefVersion config option
|
12
12
|
require 'rubocop/monkey_patches/config.rb'
|
13
13
|
require 'rubocop/monkey_patches/cop.rb'
|
14
|
-
require 'rubocop/monkey_patches/
|
14
|
+
require 'rubocop/monkey_patches/team.rb'
|
15
15
|
|
16
16
|
module RuboCop
|
17
17
|
class ConfigLoader
|
data/lib/cookstyle/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: Copyright 2019-2020, Chef Software Inc.
|
3
3
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -32,6 +32,7 @@ module RuboCop
|
|
32
32
|
'mswin' => 'windows',
|
33
33
|
'opensuse' => 'suse',
|
34
34
|
'opensuseleap' => 'suse',
|
35
|
+
'oracle' => 'rhel',
|
35
36
|
'redhat' => 'rhel',
|
36
37
|
'scientific' => 'rhel',
|
37
38
|
'sles' => 'suse',
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# Use valid platform family values in case statements.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# case node['platform_family']
|
27
|
+
# when 'redhat'
|
28
|
+
# puts "I'm on a RHEL-like system"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
class InvalidPlatformFamilyInCase < Cop
|
32
|
+
include RangeHelp
|
33
|
+
include ::RuboCop::Chef::PlatformHelpers
|
34
|
+
|
35
|
+
MSG = 'Use valid platform family values in case statements.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :node_platform_family?, <<-PATTERN
|
38
|
+
(send (send nil? :node) :[] (str "platform_family") )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_case(node)
|
42
|
+
node_platform_family?(node.condition) do
|
43
|
+
node.each_when do |when_node|
|
44
|
+
when_node.each_condition do |con|
|
45
|
+
next unless con.str_type? # if the condition isn't a string we can't check so skip
|
46
|
+
|
47
|
+
if INVALID_PLATFORM_FAMILIES[con.str_content]
|
48
|
+
add_offense(con, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def autocorrect(node)
|
56
|
+
new_value = INVALID_PLATFORM_FAMILIES[node.str_content]
|
57
|
+
|
58
|
+
# some invalid platform families have no direct correction value and return nil instead
|
59
|
+
return unless new_value
|
60
|
+
|
61
|
+
# if the correct value already exists in the when statement then we just want to delete this node
|
62
|
+
if node.parent.conditions.any? { |x| x.str_content == new_value }
|
63
|
+
lambda do |corrector|
|
64
|
+
range = range_with_surrounding_comma(range_with_surrounding_space(range: node.loc.expression, side: :left), :both)
|
65
|
+
corrector.remove(range)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
lambda do |corrector|
|
69
|
+
corrector.replace(node.loc.expression, "'#{new_value}'")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# Use valid platform values in case statements.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# case node['platform']
|
27
|
+
# when 'rhel'
|
28
|
+
# puts "I'm on a Red Hat system!"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
class InvalidPlatformInCase < Cop
|
32
|
+
include RangeHelp
|
33
|
+
include ::RuboCop::Chef::PlatformHelpers
|
34
|
+
|
35
|
+
MSG = 'Use valid platform values in case statements.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :node_platform?, <<-PATTERN
|
38
|
+
(send (send nil? :node) :[] (str "platform") )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_case(node)
|
42
|
+
node_platform?(node.condition) do
|
43
|
+
node.each_when do |when_node|
|
44
|
+
when_node.each_condition do |con|
|
45
|
+
next unless con.str_type? # if the condition isn't a string we can't check so skip
|
46
|
+
|
47
|
+
if INVALID_PLATFORMS[con.str_content]
|
48
|
+
add_offense(con, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def autocorrect(node)
|
56
|
+
new_value = INVALID_PLATFORMS[node.str_content]
|
57
|
+
|
58
|
+
# some invalid platform have no direct correction value and return nil instead
|
59
|
+
return unless new_value
|
60
|
+
|
61
|
+
# if the correct value already exists in the when statement then we just want to delete this node
|
62
|
+
if node.parent.conditions.any? { |x| x.str_content == new_value }
|
63
|
+
lambda do |corrector|
|
64
|
+
range = range_with_surrounding_comma(range_with_surrounding_space(range: node.loc.expression, side: :left), :both)
|
65
|
+
corrector.remove(range)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
lambda do |corrector|
|
69
|
+
corrector.replace(node.loc.expression, "'#{new_value}'")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefCorrectness
|
22
|
+
# When setting a node attribute as the default value for a custom resource property, wrap the node attribute in `lazy {}` so that its value is available when the resource executes.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# property :Something, String, default: node['hostname']
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# property :Something, String, default: lazy { node['hostname'] }
|
31
|
+
#
|
32
|
+
class LazyEvalNodeAttributeDefaults < Cop
|
33
|
+
include RuboCop::Chef::CookbookHelpers
|
34
|
+
|
35
|
+
MSG = 'When setting a node attribute as the default value for a custom resource property, wrap the node attribute in `lazy {}` so that its value is available when the resource executes.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :non_lazy_node_attribute_default?, <<-PATTERN
|
38
|
+
(send nil? :property (sym _) ... (hash <(pair (sym :default) $(send (send _ :node) :[] _) ) ...>))
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_send(node)
|
42
|
+
non_lazy_node_attribute_default?(node) do |default|
|
43
|
+
add_offense(default, location: :expression, message: MSG, severity: :refactor)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
corrector.replace(node.loc.expression, "lazy { #{node.loc.expression.source} }")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Chef
|
19
19
|
module ChefCorrectness
|
20
20
|
# Normal attributes are discouraged since their semantics differ importantly from the
|
21
|
-
# default and override levels.
|
21
|
+
# default and override levels. Their values persist in the node object even after
|
22
22
|
# all code referencing them has been deleted, unlike default and override.
|
23
23
|
#
|
24
24
|
# Code should be updated to use default or override levels, but this will change
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Chef
|
19
19
|
module ChefCorrectness
|
20
20
|
# Normal attributes are discouraged since their semantics differ importantly from the
|
21
|
-
# default and override levels.
|
21
|
+
# default and override levels. Their values persist in the node object even after
|
22
22
|
# all code referencing them has been deleted, unlike default and override.
|
23
23
|
#
|
24
24
|
# Code should be updated to use default or override levels, but this will change
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# The openSSL cookbook provides a deprecated `secure_password` helper in the `Opscode::OpenSSL::Password` class, which should not longer be used. This helper would generate a random password that would be used when a data bag or attribute was no present. The practice of generating passwords to be stored on the node is bad security as it exposes the password to anyone that can view the nodes, and deleting a node deletes the password. Passwords should be retrieved from a secure source for use in cookbooks.
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# ::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)
|
25
|
+
# basic_auth_password = secure_password
|
26
|
+
#
|
27
|
+
class OpenSSLPasswordHelpers < Cop
|
28
|
+
MSG = 'The `secure_password` helper from the openssl cookbooks `Opscode::OpenSSL::Password` class should not be used to generate passwords.'.freeze
|
29
|
+
|
30
|
+
def_node_matcher :openssl_helper?, <<~PATTERN
|
31
|
+
(const
|
32
|
+
(const
|
33
|
+
(const nil? :Opscode) :OpenSSL) :Password)
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_const(node)
|
37
|
+
openssl_helper?(node) do
|
38
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
# Don't depend on the deprecated compat_resource cookbook made obsolete by Chef 12.19+
|
21
|
+
# Don't depend on the deprecated compat_resource cookbook made obsolete by Chef Infra Client 12.19+
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -47,22 +47,28 @@ module RuboCop
|
|
47
47
|
'> 16.04, < 18.04' => true,
|
48
48
|
},
|
49
49
|
'fedora' => {
|
50
|
-
'<
|
50
|
+
'< 31' => '31',
|
51
51
|
},
|
52
52
|
'freebsd' => {
|
53
|
-
'< 11' => '
|
53
|
+
'~> 11.0, < 11.2' => '11',
|
54
|
+
'= 12.0' => '12',
|
55
|
+
'< 11' => true,
|
54
56
|
},
|
55
57
|
'mac_os_x' => {
|
56
58
|
'< 10.12' => '10.15',
|
57
59
|
},
|
60
|
+
'suse' => {
|
61
|
+
'~> 12.0, < 12.4' => '12',
|
62
|
+
'< 12' => true,
|
63
|
+
},
|
58
64
|
'opensuse' => {
|
59
65
|
'< 14' => true,
|
60
66
|
'~> 42.0' => true,
|
61
67
|
},
|
62
68
|
'debian' => {
|
63
69
|
'< 8' => true,
|
64
|
-
'> 8.0, < 8.
|
65
|
-
'> 9.0, < 9.
|
70
|
+
'> 8.0, < 8.10' => '8',
|
71
|
+
'> 9.0, < 9.9' => '9',
|
66
72
|
},
|
67
73
|
'centos' => {
|
68
74
|
'< 6.0' => true,
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefDeprecations
|
22
|
+
# The large number of shell_out helper methods in Chef Infra Client has been reduced to just shell_out and shell_out! methods. The legacy methods were removed in Chef Infra Client and cookbooks using these legacy helpers will need to be updated.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# shell_out_compact('foo')
|
28
|
+
# shell_out_compact!('foo')
|
29
|
+
# shell_out_with_timeout('foo')
|
30
|
+
# shell_out_with_timeout!('foo')
|
31
|
+
# shell_out_with_systems_locale('foo')
|
32
|
+
# shell_out_with_systems_locale!('foo')
|
33
|
+
# shell_out_compact_timeout('foo')
|
34
|
+
# shell_out_compact_timeout!('foo')
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# shell_out('foo')
|
38
|
+
# shell_out!('foo')
|
39
|
+
# shell_out!('foo', default_env: false) # replaces shell_out_with_systems_locale
|
40
|
+
#
|
41
|
+
class DeprecatedShelloutMethods < Cop
|
42
|
+
extend TargetChefVersion
|
43
|
+
|
44
|
+
minimum_target_chef_version '14.3'
|
45
|
+
|
46
|
+
DEPRECATED_SHELLOUT_METHODS = %i( shell_out_compact
|
47
|
+
shell_out_compact!
|
48
|
+
shell_out_compact_timeout
|
49
|
+
shell_out_compact_timeout!
|
50
|
+
shell_out_with_timeout
|
51
|
+
shell_out_with_timeout!
|
52
|
+
shell_out_with_systems_locale
|
53
|
+
shell_out_with_systems_locale!
|
54
|
+
).freeze
|
55
|
+
|
56
|
+
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.'.freeze
|
57
|
+
|
58
|
+
def on_send(node)
|
59
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if DEPRECATED_SHELLOUT_METHODS.include?(node.method_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefDeprecations
|
22
|
-
# Don't use the deprecated easy_install resource removed in Chef 13
|
22
|
+
# Don't use the deprecated easy_install resource removed in Chef Infra Client 13
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
class EasyInstallResource < Cop
|
32
|
-
MSG = "Don't use the deprecated easy_install resource removed in Chef 13".freeze
|
32
|
+
MSG = "Don't use the deprecated easy_install resource removed in Chef Infra Client 13".freeze
|
33
33
|
|
34
34
|
def on_send(node)
|
35
35
|
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :easy_install
|