cookstyle 6.16.10 → 6.19.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cookstyle +1 -2
  3. data/config/cookstyle.yml +127 -16
  4. data/config/disable_all.yml +8 -0
  5. data/config/upstream.yml +50 -3
  6. data/cookstyle.gemspec +1 -2
  7. data/lib/cookstyle.rb +7 -7
  8. data/lib/cookstyle/version.rb +2 -2
  9. data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +1 -1
  10. data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +1 -1
  11. data/lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb +1 -1
  12. data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +23 -14
  13. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +1 -1
  14. data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +2 -2
  15. data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +1 -1
  16. data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +1 -1
  17. data/lib/rubocop/cop/chef/correctness/lazy_in_resource_guard.rb +67 -0
  18. data/lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb +2 -2
  19. data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +1 -1
  20. data/lib/rubocop/cop/chef/correctness/property_without_type.rb +59 -0
  21. data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +1 -1
  22. data/lib/rubocop/cop/chef/correctness/scoped_file_exist.rb +1 -1
  23. data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +2 -2
  24. data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +1 -1
  25. data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +2 -2
  26. data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +86 -0
  27. data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +1 -1
  28. data/lib/rubocop/cop/chef/deprecation/chefdk_generators.rb +1 -1
  29. data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +1 -1
  30. data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +1 -1
  31. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +1 -1
  32. data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +8 -4
  33. data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -1
  34. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
  35. data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +51 -0
  36. data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +67 -0
  37. data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +1 -1
  38. data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +1 -1
  39. data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
  40. data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +1 -1
  41. data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +2 -2
  42. data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +2 -2
  43. data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +5 -3
  44. data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +1 -1
  45. data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +1 -1
  46. data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +61 -0
  47. data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +2 -2
  48. data/lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb +4 -4
  49. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -1
  50. data/lib/rubocop/cop/chef/effortless/chef_vault_used.rb +89 -0
  51. data/lib/rubocop/cop/chef/effortless/depends_chef_vault.rb +49 -0
  52. data/lib/rubocop/cop/chef/modernize/action_method_in_resource.rb +2 -2
  53. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +2 -2
  54. data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -1
  55. data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +1 -1
  56. data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
  57. data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +1 -1
  58. data/lib/rubocop/cop/chef/modernize/foodcritic_comments.rb +1 -1
  59. data/lib/rubocop/cop/chef/modernize/if_provides_default_action.rb +1 -1
  60. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +2 -2
  61. data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
  62. data/lib/rubocop/cop/chef/modernize/node_init_package.rb +3 -3
  63. data/lib/rubocop/cop/chef/modernize/node_roles_include.rb +1 -1
  64. data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +1 -1
  65. data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +1 -1
  66. data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +1 -1
  67. data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +1 -1
  68. data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +7 -4
  69. data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +5 -5
  70. data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +1 -1
  71. data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +1 -1
  72. data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +1 -1
  73. data/lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb +1 -1
  74. data/lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb +1 -1
  75. data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +1 -1
  76. data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -1
  77. data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
  78. data/lib/rubocop/cop/chef/redundant/double_compile_time.rb +1 -1
  79. data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +1 -1
  80. data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +1 -1
  81. data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +1 -1
  82. data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -1
  83. data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -1
  84. data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
  85. data/lib/rubocop/cop/chef/style/attribute_keys.rb +1 -1
  86. data/lib/rubocop/cop/chef/style/chef_whaaat.rb +1 -1
  87. data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +2 -2
  88. data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +2 -2
  89. data/lib/rubocop/cop/chef/style/comments_default_copyright.rb +1 -1
  90. data/lib/rubocop/cop/chef/style/comments_format.rb +6 -13
  91. data/lib/rubocop/cop/chef/style/file_mode.rb +2 -2
  92. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +2 -2
  93. data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +2 -2
  94. data/lib/rubocop/cop/chef/style/negating_only_if.rb +2 -2
  95. data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +2 -2
  96. data/lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb +1 -1
  97. data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -2
  98. data/lib/rubocop/cop/chef/style/unnecessary_os_check.rb +4 -4
  99. data/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +2 -2
  100. data/lib/rubocop/cop/chef/style/use_platform_helpers.rb +6 -6
  101. metadata +12 -4
@@ -51,7 +51,7 @@ module RuboCop
51
51
  def on_const(node)
52
52
  chefspec_runner?(node) do
53
53
  add_offense(node, message: MSG, severity: :warning) do |corrector|
54
- corrector.replace(node.loc.expression, 'ChefSpec::ServerRunner')
54
+ corrector.replace(node, 'ChefSpec::ServerRunner')
55
55
  end
56
56
  end
57
57
  end
@@ -120,7 +120,7 @@ module RuboCop
120
120
  next unless legacy_chefspec_platform(plat.value, ver.value)
121
121
  add_offense(node, message: MSG, severity: :warning) do |corrector|
122
122
  if replacement = replacement_string(plat.value, ver.value) # rubocop: disable Lint/AssignmentInCondition
123
- corrector.replace(ver.loc.expression, "'#{replacement}'")
123
+ corrector.replace(ver, "'#{replacement}'")
124
124
  end
125
125
  end
126
126
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright:: 2019, Chef Software Inc.
3
+ # Copyright:: 2019-2020, Chef Software Inc.
4
4
  # Author:: Tim Smith (<tsmith@chef.io>)
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@ module RuboCop
20
20
  module Cop
21
21
  module Chef
22
22
  module ChefDeprecations
23
- # Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
23
+ # Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
24
24
  #
25
25
  # @example
26
26
  #
@@ -34,15 +34,19 @@ module RuboCop
34
34
  # resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
35
35
  # provider = Chef::Platform.find_provider_for_node(node, resource)
36
36
  #
37
+ # Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew
38
+ #
37
39
  # # good
38
40
  # resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
39
41
  # provider = resource.provider_for_action(:create)
40
42
  #
43
+ # # provides :package, platform_family: 'mac_os_x'
44
+
41
45
  class DeprecatedPlatformMethods < Base
42
- MSG = 'Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
46
+ MSG = 'Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
43
47
 
44
48
  def_node_matcher :platform_method?, <<-PATTERN
45
- (send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node} ... )
49
+ (send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node :set} ... )
46
50
  PATTERN
47
51
 
48
52
  def on_send(node)
@@ -54,7 +54,7 @@ module RuboCop
54
54
  %w(url keyurl mirrorexpire).each do |prop|
55
55
  match_property_in_resource?(:yum_repository, prop, node) do |prop_node|
56
56
  add_offense(prop_node, message: MSG, severity: :warning) do |corrector|
57
- corrector.replace(prop_node.loc.expression, prop_node.loc.expression.source
57
+ corrector.replace(prop_node, prop_node.source
58
58
  .gsub(/^url/, 'baseurl')
59
59
  .gsub(/^keyurl/, 'gpgkey')
60
60
  .gsub(/^mirrorexpire/, 'mirror_expire'))
@@ -42,7 +42,7 @@ module RuboCop
42
42
 
43
43
  def on_send(node)
44
44
  add_offense(node, message: MSG, severity: :warning) do |corrector|
45
- corrector.replace(node.loc.expression, 'ignore_failure true')
45
+ corrector.replace(node, 'ignore_failure true')
46
46
  end
47
47
  end
48
48
  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, 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, message: MSG, severity: :warning)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -49,7 +49,7 @@ module RuboCop
49
49
  def on_class(node)
50
50
  inherits_from_compat_resource?(node) do
51
51
  add_offense(node, message: MSG, severity: :warning) do |corrector|
52
- corrector.replace(node.loc.expression, node.loc.expression.source.gsub('ChefCompat', 'Chef'))
52
+ corrector.replace(node, node.source.gsub('ChefCompat', 'Chef'))
53
53
  end
54
54
  end
55
55
  end
@@ -80,7 +80,7 @@ module RuboCop
80
80
  end
81
81
  new_val = "#{notify_type} #{action.source}, #{service_value}".dup
82
82
  new_val << ", #{timing.first.source}" unless timing.empty?
83
- corrector.replace(node.loc.expression, new_val)
83
+ corrector.replace(node, new_val)
84
84
  end
85
85
  end
86
86
  end
@@ -49,7 +49,7 @@ module RuboCop
49
49
  def on_send(node)
50
50
  node_ohai_methods?(node) do
51
51
  add_offense(node.loc.selector, message: MSG, severity: :warning) do |corrector|
52
- corrector.replace(node.loc.expression, "node['#{node.method_name}']")
52
+ corrector.replace(node, "node['#{node.method_name}']")
53
53
  end
54
54
  end
55
55
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
  def on_send(node)
48
48
  ps_cb_helper?(node) do |ver|
49
49
  add_offense(node, message: MSG, severity: :warning) do |corrector|
50
- corrector.replace(node.loc.expression, "node['powershell']['version'].to_f == #{ver.source}")
50
+ corrector.replace(node, "node['powershell']['version'].to_f == #{ver.source}")
51
51
  end
52
52
  end
53
53
  end
@@ -45,8 +45,8 @@ module RuboCop
45
45
  def on_send(node)
46
46
  positional_shellout?(node) do |h|
47
47
  next unless h.braces?
48
- add_offense(h.loc.expression, message: MSG, severity: :refactor) do |corrector|
49
- corrector.replace(h.loc.expression, h.loc.expression.source[1..-2])
48
+ add_offense(h, message: MSG, severity: :refactor) do |corrector|
49
+ corrector.replace(h, h.source[1..-2])
50
50
  end
51
51
  end
52
52
  end
@@ -50,8 +50,8 @@ module RuboCop
50
50
  match_property_in_resource?(:ruby_block, 'action', node) do |ruby_action|
51
51
  ruby_action.arguments.each do |action|
52
52
  next unless action.source == ':create'
53
- add_offense(action.loc.expression, message: MSG, severity: :warning) do |corrector|
54
- corrector.replace(action.loc.expression, ':run')
53
+ add_offense(action, message: MSG, severity: :warning) do |corrector|
54
+ corrector.replace(action, ':run')
55
55
  end
56
56
  end
57
57
  end
@@ -50,13 +50,15 @@ module RuboCop
50
50
  def on_send(node)
51
51
  search_method?(node) do
52
52
  add_offense(node, message: MSG, severity: :warning) do |corrector|
53
- corrector.replace(node.loc.expression, corrected_string(node))
53
+ corrector.replace(node, corrected_string(node))
54
54
  end if positional_arguments?(node)
55
55
  end
56
56
  end
57
57
 
58
58
  private
59
59
 
60
+ VALID_TYPES = %i(send hash block_pass).freeze
61
+
60
62
  #
61
63
  # Are the arguments in the passed node object positional
62
64
  #
@@ -68,7 +70,7 @@ module RuboCop
68
70
  return false if node.arguments.count < 3
69
71
  node.arguments[2..-1].each do |arg|
70
72
  # hashes, blocks, or variable/methods are valid. Anything else is not
71
- return true unless %i(send hash block_pass).include?(arg.type)
73
+ return true unless VALID_TYPES.include?(arg.type)
72
74
  end
73
75
  false
74
76
  end
@@ -81,7 +83,7 @@ module RuboCop
81
83
  # @return [String]
82
84
  #
83
85
  def corrected_string(node)
84
- args = node.arguments
86
+ args = node.arguments.dup
85
87
 
86
88
  # If the 2nd argument is a String and not an Integer as a String
87
89
  # then it's the old sort field and we need to delete it. Same thing
@@ -60,7 +60,7 @@ module RuboCop
60
60
  new_text << "#{key_value} #{v.source}"
61
61
  end
62
62
 
63
- corrector.replace(property.loc.expression, new_text.join("\n "))
63
+ corrector.replace(property, new_text.join("\n "))
64
64
  end
65
65
  end
66
66
  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.match?(/:servermanagercmd/)
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, 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
@@ -67,11 +67,11 @@ module RuboCop
67
67
  if ast_obj.respond_to?(:value) && ast_obj.value == :change
68
68
  add_offense(ast_obj, message: MSG, severity: :warning) do |corrector|
69
69
  if ast_obj.parent.send_type? # :change was the only action
70
- corrector.replace(ast_obj.loc.expression, ':create')
70
+ corrector.replace(ast_obj, ':create')
71
71
  # chances are it's [:create, :change] since that's all that makes sense, but double check that theory
72
72
  elsif ast_obj.parent.child_nodes.count == 2 &&
73
73
  ast_obj.parent.child_nodes.map(&:value).sort == [:change, :create]
74
- corrector.replace(ast_obj.parent.loc.expression, ':create')
74
+ corrector.replace(ast_obj.parent, ':create')
75
75
  end
76
76
  end
77
77
  end
@@ -52,13 +52,13 @@ module RuboCop
52
52
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
53
53
  case method
54
54
  when :nt_version
55
- corrector.replace(node.loc.expression, 'node[\'platform_version\'].to_f')
55
+ corrector.replace(node, 'node[\'platform_version\'].to_f')
56
56
  when :server_version?
57
- corrector.replace(node.loc.expression, 'node[\'kernel\'][\'product_type\'] == \'Server\'')
57
+ corrector.replace(node, 'node[\'kernel\'][\'product_type\'] == \'Server\'')
58
58
  when :core_version?
59
- corrector.replace(node.loc.expression, 'node[\'kernel\'][\'server_core\']')
59
+ corrector.replace(node, 'node[\'kernel\'][\'server_core\']')
60
60
  when :workstation_version?
61
- corrector.replace(node.loc.expression, 'node[\'kernel\'][\'product_type\'] == \'Workstation\'')
61
+ corrector.replace(node, 'node[\'kernel\'][\'product_type\'] == \'Workstation\'')
62
62
  end
63
63
  end
64
64
  end
@@ -40,7 +40,7 @@ module RuboCop
40
40
  xml_ruby_recipe?(node) do
41
41
  node = node.parent if node.parent&.conditional? && node.parent&.single_line_condition? # make sure we catch any inline conditionals
42
42
  add_offense(node, message: MSG, severity: :warning) do |corrector|
43
- corrector.remove(node.loc.expression)
43
+ corrector.remove(node)
44
44
  end
45
45
  end
46
46
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software Inc.
4
+ # Author:: Scott Vidmar (<svidmar@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 ChefEffortless
23
+ # Chef Vault is not supported in the Effortless pattern, so usage of Chef Vault must be shifted to another secrets management solution before leveraging the Effortless pattern.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # require 'chef-vault'
29
+ #
30
+ # # bad
31
+ # ChefVault::Item
32
+ #
33
+ # # bad
34
+ # include_recipe 'chef-vault'
35
+ #
36
+ # # bad
37
+ # chef_gem 'chef-vault'
38
+ #
39
+ # # bad
40
+ # chef_vault_item_for_environment(arg, arg1)
41
+ #
42
+ # # bad
43
+ # chef_vault_item(arg, arg1)
44
+ #
45
+
46
+ class ChefVaultUsed < Base
47
+ MSG = 'Chef Vault usage is not supported in the Effortless pattern'
48
+ RESTRICT_ON_SEND = [:chef_vault_item,
49
+ :chef_vault_item_for_environment,
50
+ :include_recipe,
51
+ :require,
52
+ :chef_gem].freeze
53
+
54
+ def_node_matcher :require?, <<-PATTERN
55
+ (send nil? { :require :include_recipe :chef_gem }
56
+ (str "chef-vault"))
57
+ PATTERN
58
+
59
+ def_node_matcher :vault_const?, <<-PATTERN
60
+ (const
61
+ (const nil? :ChefVault)
62
+ :Item)
63
+ PATTERN
64
+
65
+ def_node_matcher :chef_vault_item_for_environment?, <<-PATTERN
66
+ (send nil? :chef_vault_item_for_environment _ _)
67
+ PATTERN
68
+
69
+ def_node_matcher :chef_vault_item?, <<-PATTERN
70
+ (send nil? :chef_vault_item _ _)
71
+ PATTERN
72
+
73
+ def on_send(node)
74
+ return unless require?(node) ||
75
+ chef_vault_item_for_environment?(node) ||
76
+ chef_vault_item?(node)
77
+ add_offense(node.loc.expression, message: MSG, severity: :refactor)
78
+ end
79
+
80
+ def on_const(node)
81
+ vault_const?(node) do
82
+ add_offense(node.loc.expression, message: MSG, severity: :refactor)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end