cookstyle 5.23.0 → 6.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/config/cookstyle.yml +86 -4
  3. data/config/disable_all.yml +58 -52
  4. data/config/upstream.yml +377 -336
  5. data/lib/cookstyle.rb +0 -1
  6. data/lib/cookstyle/version.rb +2 -2
  7. data/lib/rubocop/chef/cookbook_helpers.rb +3 -3
  8. data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +58 -0
  9. data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +11 -5
  10. data/lib/rubocop/cop/chef/correctness/powershell_delete_file.rb +53 -0
  11. data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +3 -3
  12. data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +2 -2
  13. data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +4 -4
  14. data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +56 -0
  15. data/lib/rubocop/cop/chef/deprecation/cheffile.rb +1 -1
  16. data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +1 -1
  17. data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +1 -1
  18. data/lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb +1 -1
  19. data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
  20. data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -5
  21. data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +1 -1
  22. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +1 -1
  23. data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +3 -3
  24. data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +1 -1
  25. data/lib/rubocop/cop/chef/deprecation/deprecated_windows_version_check.rb +40 -0
  26. data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -4
  27. data/lib/rubocop/cop/chef/deprecation/easy_install.rb +1 -1
  28. data/lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb +1 -1
  29. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
  30. data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -1
  31. data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +1 -1
  32. data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +1 -4
  33. data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -1
  34. data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +1 -1
  35. data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +1 -1
  36. data/lib/rubocop/cop/chef/deprecation/log_resource_notifications.rb +60 -0
  37. data/lib/rubocop/cop/chef/deprecation/name_property_and_default.rb +1 -1
  38. data/lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb +2 -2
  39. data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
  40. data/lib/rubocop/cop/chef/deprecation/node_set.rb +1 -1
  41. data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +1 -1
  42. data/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb +2 -2
  43. data/lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb +1 -1
  44. data/lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb +1 -1
  45. data/lib/rubocop/cop/chef/deprecation/poise_archive.rb +2 -2
  46. data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +1 -1
  47. data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +1 -1
  48. data/lib/rubocop/cop/chef/deprecation/resource_uses_dsl_name_method.rb +1 -1
  49. data/lib/rubocop/cop/chef/deprecation/resource_uses_provider_base_method.rb +1 -1
  50. data/lib/rubocop/cop/chef/deprecation/resource_uses_updated_method.rb +1 -1
  51. data/lib/rubocop/cop/chef/deprecation/resource_without_name_or_provides.rb +81 -0
  52. data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +1 -1
  53. data/lib/rubocop/cop/chef/deprecation/run_command_helper.rb +3 -3
  54. data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +1 -1
  55. data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +1 -1
  56. data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +1 -1
  57. data/lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb +1 -4
  58. data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +1 -1
  59. data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +1 -4
  60. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -1
  61. data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +1 -1
  62. data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +58 -0
  63. data/lib/rubocop/cop/chef/modernize/powershell_guard_interpreter.rb +17 -8
  64. data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +3 -3
  65. data/lib/rubocop/cop/chef/modernize/provides_initializer.rb +69 -0
  66. data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +5 -15
  67. data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +103 -0
  68. data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +2 -9
  69. data/lib/rubocop/cop/chef/modernize/windows_registry_uac.rb +2 -2
  70. data/lib/rubocop/cop/chef/redundant/apt_repository_distribution_default.rb +0 -1
  71. data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +3 -3
  72. data/lib/rubocop/monkey_patches/comment_config.rb +1 -1
  73. data/lib/rubocop/monkey_patches/config.rb +1 -1
  74. metadata +13 -5
  75. data/lib/rubocop/monkey_patches/json_formatter.rb +0 -20
data/lib/cookstyle.rb CHANGED
@@ -7,7 +7,6 @@ require 'yaml'
7
7
  gem 'rubocop', "= #{Cookstyle::RUBOCOP_VERSION}"
8
8
  require 'rubocop'
9
9
  require 'rubocop/monkey_patches/comment_config.rb'
10
- require 'rubocop/monkey_patches/json_formatter.rb'
11
10
 
12
11
  # monkey patches needed for the TargetChefVersion config option
13
12
  require 'rubocop/monkey_patches/config.rb'
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.23.0".freeze # rubocop: disable Style/StringLiterals
3
- RUBOCOP_VERSION = '0.75.1'.freeze
2
+ VERSION = "6.0.19".freeze # rubocop: disable Style/StringLiterals
3
+ RUBOCOP_VERSION = '0.80.1'.freeze
4
4
  end
@@ -39,16 +39,16 @@ module RuboCop
39
39
 
40
40
  # Match particular properties within a resource
41
41
  #
42
- # @param [String] resource_name The name of the resource to match
42
+ # @param [Symbol, Array<Symbol>] resource_names The name of the resources to match
43
43
  # @param [String] property_names The name of the property to match (or action)
44
44
  # @param [RuboCop::AST::Node] node The rubocop ast node to search
45
45
  #
46
46
  # @yield
47
47
  #
48
- def match_property_in_resource?(resource_name, property_names, node)
48
+ def match_property_in_resource?(resource_names, property_names, node)
49
49
  return unless looks_like_resource?(node)
50
50
  # bail out if we're not in the resource we care about or nil was passed (all resources)
51
- return unless resource_name.nil? || node.children.first.method?(resource_name.to_sym) # see if we're in the right resource
51
+ return unless resource_names.nil? || Array(resource_names).include?(node.children.first.method_name) # see if we're in the right resource
52
52
 
53
53
  resource_block = node.children[2] # the 3rd child is the actual block in the resource
54
54
  return unless resource_block # nil would be an empty block
@@ -0,0 +1,58 @@
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 raise to force Chef Infra Client to fail instead of using Chef::Application.fatal, which masks the full stack trace of the failure and makes debugging difficult.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # Chef::Application.fatal!('Something horrible happened!')
27
+ #
28
+ # # good
29
+ # raise "Something horrible happened!"
30
+ #
31
+ class ChefApplicationFatal < Cop
32
+ MSG = 'Use raise to force Chef Infra Client to fail instead of using Chef::Application.fatal'.freeze
33
+
34
+ def_node_matcher :application_fatal?, <<-PATTERN
35
+ (send
36
+ (const
37
+ (const nil? :Chef) :Application) :fatal!
38
+ $( ... ))
39
+ PATTERN
40
+
41
+ def on_send(node)
42
+ application_fatal?(node) do
43
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
44
+ end
45
+ end
46
+
47
+ def autocorrect(node)
48
+ lambda do |corrector|
49
+ application_fatal?(node) do |val|
50
+ corrector.replace(node.loc.expression, "raise(#{val.source})")
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2019-2020, Chef Software Inc.
2
+ # Copyright:: Copyright 2019, 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,22 +18,24 @@ module RuboCop
18
18
  module Cop
19
19
  module Chef
20
20
  module ChefCorrectness
21
- # Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.
21
+ # Libraries should be injected into the Chef::DSL::Recipe or Chef::DSL::Resource classes and not Recipe/Resource/Provider classes directly.
22
22
  #
23
23
  # @example
24
24
  #
25
25
  # # bad
26
26
  # ::Chef::Recipe.send(:include, Filebeat::Helpers)
27
27
  # ::Chef::Provider.send(:include, Filebeat::Helpers)
28
+ # ::Chef::Resource.send(:include, Filebeat::Helpers)
28
29
  #
29
30
  # # good
30
31
  # ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
32
+ # ::Chef::DSL::Resource.send(:include, Filebeat::Helpers)
31
33
  #
32
34
  class IncorrectLibraryInjection < Cop
33
- MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'.freeze
35
+ MSG = 'Libraries should be injected into the Chef::DSL::Recipe or Chef::DSL::Resource classes and not Recipe/Resource/Provider classes directly.'.freeze
34
36
 
35
37
  def_node_matcher :legacy_class_sends?, <<-PATTERN
36
- (send (const (const (cbase) :Chef) {:Recipe :Provider}) :send (sym :include) ... )
38
+ (send (const (const (cbase) :Chef) {:Recipe :Provider :Resource}) :send (sym :include) ... )
37
39
  PATTERN
38
40
 
39
41
  def on_send(node)
@@ -44,7 +46,11 @@ module RuboCop
44
46
 
45
47
  def autocorrect(node)
46
48
  lambda do |corrector|
47
- corrector.replace(node.loc.expression, node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
49
+ new_val = node.source
50
+ new_val.gsub!(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe')
51
+ new_val.gsub!(/Chef::Resource/, 'Chef::DSL::Resource')
52
+
53
+ corrector.replace(node.loc.expression, new_val)
48
54
  end
49
55
  end
50
56
  end
@@ -0,0 +1,53 @@
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 ChefCorrectness
21
+ # Use the `file` or `directory` resources built into Chef Infra Client with the :delete action to remove files/directories instead of using Remove-Item in a powershell_script resource
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # powershell_script 'Cleanup old files' do
27
+ # code 'Remove-Item C:\Windows\foo\bar.txt'
28
+ # only_if { ::File.exist?('C:\\Windows\\foo\\bar.txt') }
29
+ # end
30
+ #
31
+ # # good
32
+ # file 'C:\Windows\foo\bar.txt' do
33
+ # action :delete
34
+ # end
35
+ #
36
+ class PowershellScriptDeleteFile < Cop
37
+ include RuboCop::Chef::CookbookHelpers
38
+
39
+ MSG = 'Use the `file` or `directory` resources built into Chef Infra Client with the :delete action to remove files/directories instead of using Remove-Item in a powershell_script resource'.freeze
40
+
41
+ def on_block(node)
42
+ match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
43
+ property_data = method_arg_ast_to_string(code_property)
44
+ if property_data && property_data.match?(/^remove-item/i) && !property_data.include?('*')
45
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ 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");
@@ -39,8 +39,8 @@ module RuboCop
39
39
  MSG = 'Use the type property instead of the deprecated supports property in the chef_handler resource. The supports property was removed in chef_handler cookbook version 3.0 (June 2017) and Chef Infra Client 14.0.'.freeze
40
40
 
41
41
  def on_block(node)
42
- match_property_in_resource?('chef_handler', 'supports', node) do |prop_node|
43
- add_offense(prop_node, location: :expression, message: MSG, severity: :refactor)
42
+ match_property_in_resource?(:chef_handler, 'supports', node) do |prop_node|
43
+ add_offense(prop_node, location: :expression, message: MSG, severity: :warning)
44
44
  end
45
45
  end
46
46
 
@@ -40,13 +40,13 @@ module RuboCop
40
40
 
41
41
  def on_send(node)
42
42
  require_rest?(node) do
43
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
43
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
44
44
  end
45
45
  end
46
46
 
47
47
  def on_const(node)
48
48
  rest_const?(node) do
49
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
49
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
50
50
  end
51
51
  end
52
52
  end
@@ -62,21 +62,21 @@ module RuboCop
62
62
 
63
63
  def on_send(node)
64
64
  rewind_gem_install?(node) do
65
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
65
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
66
66
  end
67
67
 
68
68
  require_rewind?(node) do
69
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
69
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
70
70
  end
71
71
 
72
72
  rewind_resources?(node) do
73
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
73
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
74
74
  end
75
75
  end
76
76
 
77
77
  def on_block(node)
78
78
  match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name|
79
- add_offense(node, location: :expression, message: MSG, severity: :refactor) if pkg_name.arguments&.first&.str_content == 'chef-rewind'
79
+ add_offense(node, location: :expression, message: MSG, severity: :warning) if pkg_name.arguments&.first&.str_content == 'chef-rewind'
80
80
  end
81
81
  end
82
82
 
@@ -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
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ module ChefDeprecations
21
+ # Use `platform?('windows')` instead of the legacy `Chef::Platform.windows?` helper
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # Chef::Platform.windows?
27
+ #
28
+ # # good
29
+ # platform?('windows')
30
+ # platform_family?('windows')
31
+ #
32
+ class ChefWindowsPlatformHelper < Cop
33
+ MSG = "Use `platform?('windows')` instead of the legacy `Chef::Platform.windows?` helper.".freeze
34
+
35
+ def_node_matcher :chef_platform_windows?, <<-PATTERN
36
+ (send
37
+ (const
38
+ (const nil? :Chef) :Platform) :windows?)
39
+ PATTERN
40
+
41
+ def on_send(node)
42
+ chef_platform_windows?(node) do
43
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
44
+ end
45
+ end
46
+
47
+ def autocorrect(node)
48
+ lambda do |corrector|
49
+ corrector.replace(node.loc.expression, "platform?('windows')")
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -32,7 +32,7 @@ module RuboCop
32
32
  # Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
33
33
  range = source_range(processed_source.buffer, 1, 0)
34
34
 
35
- add_offense(nil, location: range, message: MSG, severity: :refactor)
35
+ add_offense(nil, location: range, message: MSG, severity: :warning)
36
36
  end
37
37
  end
38
38
  end
@@ -36,7 +36,7 @@ module RuboCop
36
36
 
37
37
  def on_block(node)
38
38
  coverage_reporter?(node) do
39
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
39
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
40
40
  end
41
41
  end
42
42
 
@@ -48,7 +48,7 @@ module RuboCop
48
48
 
49
49
  def on_const(node)
50
50
  chefspec_runner?(node) do
51
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
51
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
52
52
  end
53
53
  end
54
54
 
@@ -41,7 +41,7 @@ module RuboCop
41
41
  def on_block(node)
42
42
  match_property_in_resource?(:chocolatey_package, 'action', node) do |choco_action|
43
43
  choco_action.arguments.each do |action|
44
- add_offense(action, location: :expression, message: MSG, severity: :refactor) if action.source == ':uninstall'
44
+ add_offense(action, location: :expression, message: MSG, severity: :warning) if action.source == ':uninstall'
45
45
  end
46
46
  end
47
47
  end
@@ -39,7 +39,7 @@ module RuboCop
39
39
 
40
40
  def on_send(node)
41
41
  depends_compat_resource?(node) do
42
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
42
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
43
43
  end
44
44
  end
45
45
 
@@ -26,10 +26,6 @@ module RuboCop
26
26
  # depends 'partial_search'
27
27
  #
28
28
  class CookbookDependsOnPartialSearch < Cop
29
- extend TargetChefVersion
30
-
31
- minimum_target_chef_version '13.0'
32
-
33
29
  MSG = "Don't depend on the deprecated partial_search cookbook made obsolete by Chef 13".freeze
34
30
 
35
31
  def_node_matcher :depends_partial_search?, <<-PATTERN
@@ -38,7 +34,7 @@ module RuboCop
38
34
 
39
35
  def on_send(node)
40
36
  depends_partial_search?(node) do
41
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
37
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
42
38
  end
43
39
  end
44
40
  end
@@ -35,7 +35,7 @@ module RuboCop
35
35
 
36
36
  def on_send(node)
37
37
  depends_method?(node) do |arg|
38
- add_offense(node, location: :expression, message: MSG, severity: :refactor) if %w(poise poise-service).include?(arg.value)
38
+ add_offense(node, location: :expression, message: MSG, severity: :warning) if %w(poise poise-service).include?(arg.value)
39
39
  end
40
40
  end
41
41
  end
@@ -108,7 +108,7 @@ module RuboCop
108
108
 
109
109
  def on_send(node)
110
110
  chefspec_definition?(node) do |plat, ver|
111
- add_offense(node, location: :expression, message: MSG, severity: :refactor) if legacy_chefspec_platform(plat.value, ver.value)
111
+ add_offense(node, location: :expression, message: MSG, severity: :warning) if legacy_chefspec_platform(plat.value, ver.value)
112
112
  end
113
113
  end
114
114
 
@@ -52,15 +52,15 @@ module RuboCop
52
52
 
53
53
  def on_send(node)
54
54
  deprecated_mixin?(node) do
55
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
55
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
56
56
  end
57
57
 
58
58
  deprecated_dsl?(node) do
59
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
59
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
60
60
  end
61
61
 
62
62
  dsl_mixin_require?(node) do
63
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
63
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
64
64
  end
65
65
  end
66
66
 
@@ -46,7 +46,7 @@ module RuboCop
46
46
 
47
47
  def on_send(node)
48
48
  platform_method?(node) do
49
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
49
+ add_offense(node, location: :expression, message: MSG, severity: :warning)
50
50
  end
51
51
  end
52
52
  end
@@ -0,0 +1,40 @@
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 ChefDeprecations
21
+ # 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.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # if older_than_win_2012_or_8?
27
+ # # do some legacy things
28
+ # end
29
+ #
30
+ class DeprecatedWindowsVersionCheck < Cop
31
+ 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.".freeze
32
+
33
+ def on_send(node)
34
+ add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :older_than_win_2012_or_8?
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end