cookstyle 6.2.5 → 6.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/config/cookstyle.yml +292 -13
  4. data/config/disable_all.yml +13 -3
  5. data/config/upstream.yml +88 -17
  6. data/lib/cookstyle/version.rb +2 -2
  7. data/lib/rubocop/chef/platform_helpers.rb +2 -1
  8. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +77 -0
  9. data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +77 -0
  10. data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
  11. data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -1
  12. data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -1
  13. data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
  14. data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
  15. data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -1
  16. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +10 -4
  17. data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +65 -0
  18. data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -2
  19. data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -1
  20. data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +2 -2
  21. data/lib/rubocop/cop/chef/deprecation/log_resource_notifications.rb +5 -2
  22. data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
  23. data/lib/rubocop/cop/chef/deprecation/node_set.rb +2 -3
  24. data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +2 -3
  25. data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +3 -3
  26. data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +59 -0
  27. data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +6 -1
  28. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +3 -3
  29. data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +93 -0
  30. data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +15 -5
  31. data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +64 -0
  32. data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
  33. data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +9 -2
  34. data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +0 -1
  35. data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +3 -3
  36. data/lib/rubocop/cop/chef/style/negating_only_if.rb +8 -3
  37. data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +1 -1
  38. data/lib/rubocop/cop/target_chef_version.rb +4 -0
  39. metadata +12 -4
@@ -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");
@@ -18,8 +18,7 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefDeprecations
21
- # Do not include the deprecated xml::ruby recipe to install the nokogiri gem.
22
- # Chef Infra Client 12 and later ships with nokogiri included.
21
+ # Do not include the deprecated xml::ruby recipe to install the nokogiri gem. Chef Infra Client 12 and later ships with nokogiri included.
23
22
  #
24
23
  # @example
25
24
  #
@@ -35,6 +34,7 @@ module RuboCop
35
34
 
36
35
  def on_send(node)
37
36
  xml_ruby_recipe?(node) do
37
+ node = node.parent if node.parent&.conditional? && node.parent&.single_line_condition? # make sure we catch any inline conditionals
38
38
  add_offense(node, location: :expression, message: MSG, severity: :warning)
39
39
  end
40
40
  end
@@ -0,0 +1,93 @@
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
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ module ChefModernize
21
+ # There is no need to check if the chef_gem resource supports compile_time as Chef Infra Client 12.1 and later support the compile_time property.
22
+ #
23
+ # # bad
24
+ # chef_gem 'ultradns-sdk' do
25
+ # compile_time true if Chef::Resource::ChefGem.method_defined?(:compile_time)
26
+ # action :nothing
27
+ # end
28
+ #
29
+ # chef_gem 'ultradns-sdk' do
30
+ # compile_time true if Chef::Resource::ChefGem.instance_methods(false).include?(:compile_time)
31
+ # action :nothing
32
+ # end
33
+ #
34
+ # chef_gem 'ultradns-sdk' do
35
+ # compile_time true if respond_to?(:compile_time)
36
+ # action :nothing
37
+ # end
38
+ #
39
+ # # good
40
+ # chef_gem 'ultradns-sdk' do
41
+ # compile_time true
42
+ # action :nothing
43
+ # end
44
+ #
45
+ class RespondToCompileTime < Cop
46
+ extend TargetChefVersion
47
+
48
+ minimum_target_chef_version '12.1'
49
+
50
+ MSG = 'There is no need to check if the chef_gem resource supports compile_time as Chef Infra Client 12.1 and later support the compile_time property.'.freeze
51
+
52
+ def_node_matcher :compile_time_method_defined?, <<-PATTERN
53
+ (if
54
+ {
55
+ (send
56
+ (const
57
+ (const
58
+ (const nil? :Chef) :Resource) :ChefGem) :method_defined?
59
+ (sym :compile_time))
60
+
61
+ (send
62
+ (send
63
+ (const
64
+ (const
65
+ (const nil? :Chef) :Resource) :ChefGem) :instance_methods
66
+ (false)) :include?
67
+ (sym :compile_time))
68
+
69
+ (send nil? :respond_to?
70
+ (sym :compile_time))
71
+ }
72
+ (send nil? :compile_time
73
+ $(_)) nil?)
74
+ PATTERN
75
+
76
+ def on_if(node)
77
+ compile_time_method_defined?(node) do
78
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
79
+ end
80
+ end
81
+
82
+ def autocorrect(node)
83
+ lambda do |corrector|
84
+ compile_time_method_defined?(node) do |val|
85
+ corrector.replace(node.loc.expression, "compile_time #{val.source}")
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -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");
@@ -18,19 +18,20 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefModernize
21
- # It is not longer necessary respond_to?(:foo) in metadata. This was used to support new metadata
22
- # methods in Chef 11 and early versions of Chef 12.
21
+ # In Chef Infra Client 12+ is is no longer necessary to gate the use of the provides methods in resources with `if respond_to?(:provides)` or `if defined? provides`.
23
22
  #
24
23
  # @example
25
24
  #
26
25
  # # bad
27
26
  # provides :foo if respond_to?(:provides)
28
27
  #
28
+ # provides :foo if defined? provides
29
+ #
29
30
  # # good
30
31
  # provides :foo
31
32
  #
32
33
  class RespondToProvides < Cop
33
- MSG = 'respond_to?(:provides) in resources is no longer necessary in Chef Infra Client 12+'.freeze
34
+ MSG = 'Using `respond_to?(:provides)` or `if defined? provides` in resources is no longer necessary in Chef Infra Client 12+.'.freeze
34
35
 
35
36
  def on_if(node)
36
37
  if_respond_to_provides?(node) do
@@ -39,7 +40,16 @@ module RuboCop
39
40
  end
40
41
 
41
42
  def_node_matcher :if_respond_to_provides?, <<~PATTERN
42
- (if (send nil? :respond_to? ( :sym :provides ) ) ... )
43
+ (if
44
+ {
45
+ (send nil? :respond_to?
46
+ (sym :provides))
47
+
48
+ (:defined?
49
+ (send nil? :provides))
50
+ }
51
+ (send nil? :provides
52
+ (sym _)) ... )
43
53
  PATTERN
44
54
 
45
55
  def autocorrect(node)
@@ -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)))) nil?)
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
@@ -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");
@@ -35,8 +35,15 @@ module RuboCop
35
35
 
36
36
  MSG = 'whyrun_supported? no longer needs to be set to true as it is the default in Chef Infra Client 13+'.freeze
37
37
 
38
+ # match on both whyrun_supported? and the typo form why_run_supported?
39
+ def_node_matcher :whyrun_true?, <<-PATTERN
40
+ (def {:whyrun_supported? :why_run_supported?}
41
+ (args)
42
+ (true))
43
+ PATTERN
44
+
38
45
  def on_def(node)
39
- if node.method_name == :whyrun_supported? && node.body == s(:true) # rubocop: disable Lint/BooleanSymbol
46
+ whyrun_true?(node) do
40
47
  add_offense(node, location: :expression, message: MSG, severity: :refactor)
41
48
  end
42
49
  end
@@ -26,7 +26,6 @@ module RuboCop
26
26
  # # bad
27
27
  # grouping 'windows_log_rotate', title: 'Demonstration cookbook with code to switch loggers'
28
28
  #
29
- #
30
29
  class GroupingMetadata < Cop
31
30
  include RangeHelp
32
31
  include RuboCop::Chef::AutocorrectHelpers
@@ -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");
@@ -18,13 +18,13 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefRedundantCode
21
- # Every Chef Infra resources already include a sensitive property with a default value of false.
21
+ # Every Chef Infra resource already includes a sensitive property with a default value of false.
22
22
  #
23
23
  # # bad
24
24
  # property :sensitive, [true, false], default: false
25
25
  #
26
26
  class SensitivePropertyInResource < Cop
27
- MSG = 'Every Chef Infra resources already include a sensitive property with a default value of false.'.freeze
27
+ MSG = 'Every Chef Infra resource already includes a sensitive property with a default value of false.'.freeze
28
28
 
29
29
  def_node_matcher :sensitive_property?, <<-PATTERN
30
30
  (send nil? {:property :attribute} (sym :sensitive) ... (hash (pair (sym :default) (false))))
@@ -18,7 +18,7 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefStyle
21
- # Use not_if instead of only_if that negates the Ruby statement with a !
21
+ # Instead of using only_if conditionals with ! to negate the returned value, use not_if which is easier to read
22
22
  #
23
23
  # @example
24
24
  #
@@ -33,7 +33,7 @@ module RuboCop
33
33
  # end
34
34
  #
35
35
  class NegatingOnlyIf < Cop
36
- MSG = 'Use not_if instead of only_if that negates the Ruby statement with a !'.freeze
36
+ MSG = 'Instead of using only_if conditionals with ! to negate the returned value, use not_if which is easier to read'.freeze
37
37
 
38
38
  def_node_matcher :negated_only_if?, <<-PATTERN
39
39
  (block
@@ -45,8 +45,13 @@ module RuboCop
45
45
 
46
46
  def on_block(node)
47
47
  negated_only_if?(node) do |_only_if, code|
48
+ # skip inspec controls where we don't have not_if
49
+ return if node.parent&.parent&.block_type? &&
50
+ node.parent&.parent&.method_name == :control
51
+
48
52
  # the value was double negated to work around types: ex: !!systemd?
49
- return if code.descendants.first.negation_method?
53
+ return if code.descendants.first.send_type? &&
54
+ code.descendants.first.negation_method?
50
55
 
51
56
  add_offense(node, location: :expression, message: MSG, severity: :refactor)
52
57
  end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefStyle
21
- # Don't loop over an array to set cookbook dependencies or supported platforms if you have fewer than three values to set. Setting multiple `supports` or `depends` values is simpler and easier to understand for new users.
21
+ # Don't loop over an array to set cookbook dependencies or supported platforms if you have fewer than three values to set. Setting multiple `supports` or `depends` values is simpler and easier to understand for new users.
22
22
  #
23
23
  # @example
24
24
  #
@@ -6,6 +6,10 @@ module RuboCop
6
6
  module Cop
7
7
  # Common functionality for checking target chef version.
8
8
  module TargetChefVersion
9
+ def required_minimum_chef_version
10
+ @minimum_target_chef_version
11
+ end
12
+
9
13
  def minimum_target_chef_version(version)
10
14
  @minimum_target_chef_version = version
11
15
  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.2.5
4
+ version: 6.6.9
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-04-03 00:00:00.000000000 Z
12
+ date: 2020-05-27 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.81.0
20
+ version: 0.83.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.81.0
27
+ version: 0.83.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
@@ -89,6 +93,7 @@ files:
89
93
  - lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb
90
94
  - lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb
91
95
  - lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb
96
+ - lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb
92
97
  - lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb
93
98
  - lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb
94
99
  - lib/rubocop/cop/chef/deprecation/easy_install.rb
@@ -117,6 +122,7 @@ files:
117
122
  - lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb
118
123
  - lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb
119
124
  - lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb
125
+ - lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb
120
126
  - lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb
121
127
  - lib/rubocop/cop/chef/deprecation/run_command_helper.rb
122
128
  - lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb
@@ -176,11 +182,13 @@ files:
176
182
  - lib/rubocop/cop/chef/modernize/resource_name_initializer.rb
177
183
  - lib/rubocop/cop/chef/modernize/resource_set_or_return.rb
178
184
  - lib/rubocop/cop/chef/modernize/resource_with_attributes.rb
185
+ - lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb
179
186
  - lib/rubocop/cop/chef/modernize/respond_to_metadata.rb
180
187
  - lib/rubocop/cop/chef/modernize/respond_to_provides.rb
181
188
  - lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb
182
189
  - lib/rubocop/cop/chef/modernize/sc_windows_resource.rb
183
190
  - lib/rubocop/cop/chef/modernize/seven_zip_archive.rb
191
+ - lib/rubocop/cop/chef/modernize/shell_out_helper.rb
184
192
  - lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb
185
193
  - lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb
186
194
  - lib/rubocop/cop/chef/modernize/systctl_param_resource.rb