cookstyle 6.4.4 → 6.9.0
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 +287 -12
- data/config/disable_all.yml +12 -0
- data/config/upstream.yml +82 -19
- 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/invalid_version_metadata.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +10 -4
- data/lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb +141 -0
- data/lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb +86 -0
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +59 -0
- 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/shell_out_helper.rb +64 -0
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
- data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
- data/lib/rubocop/monkey_patches/team.rb +24 -0
- metadata +13 -6
- data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +0 -81
- data/lib/rubocop/monkey_patches/commissioner.rb +0 -26
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: 2019, Chef Software Inc.
|
2
|
+
# 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");
|
@@ -42,13 +42,34 @@ module RuboCop
|
|
42
42
|
(send nil? :require ( str {"chef/mixin/shell_out" "chef/mixin/powershell_out"} ))
|
43
43
|
PATTERN
|
44
44
|
|
45
|
+
def_node_search :hwrp_classes?, <<-PATTERN
|
46
|
+
(class
|
47
|
+
(const ... )
|
48
|
+
{(const
|
49
|
+
(const
|
50
|
+
(const nil? :Chef) :Provider) :LWRPBase)
|
51
|
+
(const
|
52
|
+
(const nil? :Chef) :Provider)
|
53
|
+
}
|
54
|
+
...)
|
55
|
+
PATTERN
|
56
|
+
|
57
|
+
def check_for_offenses(node)
|
58
|
+
containing_dir = File.basename(File.dirname(processed_source.path))
|
59
|
+
|
60
|
+
# only add offenses when we're in a custom resource or HWRP, but not a plain old library
|
61
|
+
if containing_dir == 'resources' || hwrp_classes?(processed_source.ast)
|
62
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
45
66
|
def on_send(node)
|
46
67
|
require_shellout?(node) do
|
47
|
-
|
68
|
+
check_for_offenses(node)
|
48
69
|
end
|
49
70
|
|
50
71
|
include_shellout?(node) do
|
51
|
-
|
72
|
+
check_for_offenses(node)
|
52
73
|
end
|
53
74
|
end
|
54
75
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
22
|
+
# Use the built-in `shell_out` helper available in Chef Infra Client 12.11+ instead of calling `Mixlib::ShellOut.new('foo').run_command`.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# Mixlib::ShellOut.new('foo').run_command
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# shell_out('foo')
|
31
|
+
#
|
32
|
+
class ShellOutHelper < Cop
|
33
|
+
extend TargetChefVersion
|
34
|
+
|
35
|
+
minimum_target_chef_version '12.11'
|
36
|
+
|
37
|
+
MSG = "Use the built-in `shell_out` helper available in Chef Infra Client 12.11+ instead of calling `Mixlib::ShellOut.new('foo').run_command`.".freeze
|
38
|
+
|
39
|
+
def_node_matcher :mixlib_shellout_run_cmd?, <<-PATTERN
|
40
|
+
(send
|
41
|
+
(send
|
42
|
+
(const
|
43
|
+
(const nil? :Mixlib) :ShellOut) :new
|
44
|
+
$(...)) :run_command)
|
45
|
+
PATTERN
|
46
|
+
|
47
|
+
def on_send(node)
|
48
|
+
mixlib_shellout_run_cmd?(node) do
|
49
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def autocorrect(node)
|
54
|
+
mixlib_shellout_run_cmd?(node) do |cmd|
|
55
|
+
lambda do |corrector|
|
56
|
+
corrector.replace(node.loc.expression, "shell_out(#{cmd.loc.expression.source})")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -47,12 +47,14 @@ module RuboCop
|
|
47
47
|
(send
|
48
48
|
$(array ... ) :each)
|
49
49
|
(args ... )
|
50
|
-
(block
|
50
|
+
{(block
|
51
51
|
(send nil? :package
|
52
52
|
(lvar ... ))
|
53
53
|
(args)
|
54
54
|
(send nil? :action
|
55
|
-
(sym :install)))
|
55
|
+
(sym :install)))
|
56
|
+
(send nil? :package
|
57
|
+
(lvar _))}) nil?)
|
56
58
|
PATTERN
|
57
59
|
|
58
60
|
def_node_matcher :package_array_install?, <<-PATTERN
|
@@ -60,12 +62,14 @@ module RuboCop
|
|
60
62
|
(send
|
61
63
|
$(array ... ) :each)
|
62
64
|
(args ... )
|
63
|
-
(block
|
65
|
+
{(block
|
64
66
|
(send nil? :package
|
65
67
|
(lvar ... ))
|
66
68
|
(args)
|
67
69
|
(send nil? :action
|
68
|
-
(sym :install)))
|
70
|
+
(sym :install)))
|
71
|
+
(send nil? :package
|
72
|
+
(lvar _))})
|
69
73
|
PATTERN
|
70
74
|
|
71
75
|
# see if all platforms in the when condition are multipackage compliant
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
class Team
|
6
|
+
def support_target_chef_version?(cop)
|
7
|
+
return true unless cop.class.respond_to?(:support_target_chef_version?)
|
8
|
+
|
9
|
+
cop.class.support_target_chef_version?(cop.target_chef_version)
|
10
|
+
end
|
11
|
+
|
12
|
+
### START COOKSTYLE MODIFICATION
|
13
|
+
def roundup_relevant_cops(filename)
|
14
|
+
cops.reject do |cop|
|
15
|
+
cop.excluded_file?(filename) ||
|
16
|
+
!support_target_ruby_version?(cop) ||
|
17
|
+
!support_target_chef_version?(cop) ||
|
18
|
+
!support_target_rails_version?(cop)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
### END COOKSTYLE MODIFICATION
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookstyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom May
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.86.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.86.0
|
28
28
|
description:
|
29
29
|
email:
|
30
30
|
- thom@chef.io
|
@@ -57,17 +57,21 @@ files:
|
|
57
57
|
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
|
58
58
|
- lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb
|
59
59
|
- lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb
|
60
|
+
- lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb
|
60
61
|
- lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb
|
61
62
|
- lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb
|
63
|
+
- lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb
|
62
64
|
- lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb
|
63
65
|
- lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb
|
64
66
|
- lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb
|
67
|
+
- lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb
|
65
68
|
- lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb
|
66
69
|
- lib/rubocop/cop/chef/correctness/metadata_missing_name.rb
|
67
70
|
- lib/rubocop/cop/chef/correctness/node_normal.rb
|
68
71
|
- lib/rubocop/cop/chef/correctness/node_normal_unless.rb
|
69
72
|
- lib/rubocop/cop/chef/correctness/node_save.rb
|
70
73
|
- lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb
|
74
|
+
- lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb
|
71
75
|
- lib/rubocop/cop/chef/correctness/powershell_delete_file.rb
|
72
76
|
- lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
|
73
77
|
- lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
|
@@ -96,6 +100,7 @@ files:
|
|
96
100
|
- lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb
|
97
101
|
- lib/rubocop/cop/chef/deprecation/epic_fail.rb
|
98
102
|
- lib/rubocop/cop/chef/deprecation/erl_call.rb
|
103
|
+
- lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb
|
99
104
|
- lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
|
100
105
|
- lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
|
101
106
|
- lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb
|
@@ -115,9 +120,10 @@ files:
|
|
115
120
|
- lib/rubocop/cop/chef/deprecation/require_recipe.rb
|
116
121
|
- lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb
|
117
122
|
- lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb
|
123
|
+
- lib/rubocop/cop/chef/deprecation/resource_uses_only_resource_name.rb
|
118
124
|
- lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb
|
119
125
|
- lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb
|
120
|
-
- lib/rubocop/cop/chef/deprecation/
|
126
|
+
- lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb
|
121
127
|
- lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb
|
122
128
|
- lib/rubocop/cop/chef/deprecation/run_command_helper.rb
|
123
129
|
- lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb
|
@@ -183,6 +189,7 @@ files:
|
|
183
189
|
- lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb
|
184
190
|
- lib/rubocop/cop/chef/modernize/sc_windows_resource.rb
|
185
191
|
- lib/rubocop/cop/chef/modernize/seven_zip_archive.rb
|
192
|
+
- lib/rubocop/cop/chef/modernize/shell_out_helper.rb
|
186
193
|
- lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb
|
187
194
|
- lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb
|
188
195
|
- lib/rubocop/cop/chef/modernize/systctl_param_resource.rb
|
@@ -238,9 +245,9 @@ files:
|
|
238
245
|
- lib/rubocop/cop/chef/style/use_platform_helpers.rb
|
239
246
|
- lib/rubocop/cop/target_chef_version.rb
|
240
247
|
- lib/rubocop/monkey_patches/comment_config.rb
|
241
|
-
- lib/rubocop/monkey_patches/commissioner.rb
|
242
248
|
- lib/rubocop/monkey_patches/config.rb
|
243
249
|
- lib/rubocop/monkey_patches/cop.rb
|
250
|
+
- lib/rubocop/monkey_patches/team.rb
|
244
251
|
homepage:
|
245
252
|
licenses:
|
246
253
|
- Apache-2.0
|
@@ -1,81 +0,0 @@
|
|
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
|
-
# In Chef Infra Client 16 and later a legacy HWRP resource must use either `resource_name` or `provides` to define the resource name.
|
23
|
-
#
|
24
|
-
# @example
|
25
|
-
#
|
26
|
-
# # bad
|
27
|
-
# class Chef
|
28
|
-
# class Resource
|
29
|
-
# class UlimitRule < Chef::Resource
|
30
|
-
# property :type, [Symbol, String], required: true
|
31
|
-
# property :item, [Symbol, String], required: true
|
32
|
-
#
|
33
|
-
# # additional resource code
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# # good
|
39
|
-
# class Chef
|
40
|
-
# class Resource
|
41
|
-
# class UlimitRule < Chef::Resource
|
42
|
-
# resource_name :ulimit_rule
|
43
|
-
#
|
44
|
-
# property :type, [Symbol, String], required: true
|
45
|
-
# property :item, [Symbol, String], required: true
|
46
|
-
#
|
47
|
-
# # additional resource code
|
48
|
-
# end
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# # better
|
53
|
-
# Convert your legacy HWRPs to custom resources
|
54
|
-
#
|
55
|
-
class ResourceWithoutNameOrProvides < Cop
|
56
|
-
MSG = 'In Chef Infra Client 16 and later legacy HWRP resources must use either `resource_name` or `provides` to define the resource name.'.freeze
|
57
|
-
|
58
|
-
def_node_matcher :HWRP?, <<-PATTERN
|
59
|
-
(class
|
60
|
-
(const nil? :Chef) nil?
|
61
|
-
(class
|
62
|
-
(const nil? :Resource) nil?
|
63
|
-
$(class
|
64
|
-
(const nil? ... )
|
65
|
-
(const
|
66
|
-
(const nil? :Chef) :Resource)
|
67
|
-
(begin ... ))))
|
68
|
-
PATTERN
|
69
|
-
|
70
|
-
def_node_search :provides_or_resource_name?, '(send nil? {:provides :resource_name} ...)'
|
71
|
-
|
72
|
-
def on_class(node)
|
73
|
-
HWRP?(node) do |inherit|
|
74
|
-
add_offense(inherit, location: :expression, message: MSG, severity: :warning) if provides_or_resource_name?(processed_source.ast).nil?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
class Commissioner
|
6
|
-
def remove_irrelevant_cops(filename)
|
7
|
-
@cops.reject! { |cop| cop.excluded_file?(filename) }
|
8
|
-
@cops.reject! do |cop|
|
9
|
-
cop.class.respond_to?(:support_target_ruby_version?) &&
|
10
|
-
!cop.class.support_target_ruby_version?(cop.target_ruby_version)
|
11
|
-
end
|
12
|
-
@cops.reject! do |cop|
|
13
|
-
cop.class.respond_to?(:support_target_rails_version?) &&
|
14
|
-
!cop.class.support_target_rails_version?(cop.target_rails_version)
|
15
|
-
end
|
16
|
-
|
17
|
-
### START COOKSTYLE MODIFICATION
|
18
|
-
@cops.reject! do |cop|
|
19
|
-
cop.class.respond_to?(:support_target_chef_version?) &&
|
20
|
-
!cop.class.support_target_chef_version?(cop.target_chef_version)
|
21
|
-
end
|
22
|
-
### END COOKSTYLE MODIFICATION
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|