cookstyle 5.4.13 → 5.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/config/cookstyle.yml +231 -129
  3. data/lib/cookstyle.rb +1 -0
  4. data/lib/cookstyle/version.rb +1 -1
  5. data/lib/rubocop/chef/cookbook_helpers.rb +67 -0
  6. data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +34 -31
  7. data/lib/rubocop/cop/chef/correctness/cb_depends_on_self.rb +16 -14
  8. data/lib/rubocop/cop/chef/correctness/default_maintainer_metadata.rb +22 -20
  9. data/lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb +32 -30
  10. data/lib/rubocop/cop/chef/correctness/invalid_license_string.rb +454 -453
  11. data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +57 -57
  12. data/lib/rubocop/cop/chef/correctness/metadata_missing_name.rb +18 -16
  13. data/lib/rubocop/cop/chef/correctness/name_property_and_required.rb +61 -59
  14. data/lib/rubocop/cop/chef/correctness/node_normal.rb +29 -27
  15. data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +29 -27
  16. data/lib/rubocop/cop/chef/correctness/node_save.rb +46 -0
  17. data/lib/rubocop/cop/chef/correctness/ohai_default_recipe.rb +47 -0
  18. data/lib/rubocop/cop/chef/correctness/property_with_default_and_required.rb +35 -33
  19. data/lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb +29 -27
  20. data/lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb +52 -0
  21. data/lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb +51 -0
  22. data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +52 -0
  23. data/lib/rubocop/cop/chef/correctness/service_resource.rb +26 -24
  24. data/lib/rubocop/cop/chef/correctness/tmp_path.rb +30 -28
  25. data/lib/rubocop/cop/chef/deprecation/attribute_metadata.rb +22 -21
  26. data/lib/rubocop/cop/chef/deprecation/chef_rest.rb +56 -0
  27. data/lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb +58 -0
  28. data/lib/rubocop/cop/chef/deprecation/conflicts_metadata.rb +18 -16
  29. data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +21 -19
  30. data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +17 -15
  31. data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +17 -15
  32. data/lib/rubocop/cop/chef/deprecation/deprecated_mixins.rb +39 -37
  33. data/lib/rubocop/cop/chef/deprecation/easy_install.rb +15 -13
  34. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +24 -22
  35. data/lib/rubocop/cop/chef/deprecation/erl_call.rb +15 -13
  36. data/lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb +55 -0
  37. data/lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb +24 -22
  38. data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +45 -0
  39. data/lib/rubocop/cop/chef/deprecation/long_description_metadata.rb +21 -19
  40. data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +55 -53
  41. data/lib/rubocop/cop/chef/deprecation/node_set.rb +27 -25
  42. data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +27 -25
  43. data/lib/rubocop/cop/chef/deprecation/provides_metadata.rb +18 -16
  44. data/lib/rubocop/cop/chef/deprecation/replaces_metadata.rb +18 -16
  45. data/lib/rubocop/cop/chef/deprecation/require_recipe.rb +23 -21
  46. data/lib/rubocop/cop/chef/deprecation/suggests_metadata.rb +18 -16
  47. data/lib/rubocop/cop/chef/deprecation/use_inline_resources.rb +56 -0
  48. data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +53 -0
  49. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +51 -0
  50. data/lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb +51 -0
  51. data/lib/rubocop/cop/chef/effortless/data_bags.rb +13 -11
  52. data/lib/rubocop/cop/chef/effortless/search_used.rb +13 -11
  53. data/lib/rubocop/cop/chef/modernize/apt_default_recipe.rb +22 -20
  54. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +31 -29
  55. data/lib/rubocop/cop/chef/modernize/build_essential.rb +25 -23
  56. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +27 -25
  57. data/lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb +25 -23
  58. data/lib/rubocop/cop/chef/modernize/execute_apt_update.rb +19 -17
  59. data/lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb +27 -25
  60. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +41 -0
  61. data/lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb +21 -19
  62. data/lib/rubocop/cop/chef/modernize/powershell_expand_archive.rb +48 -0
  63. data/lib/rubocop/cop/chef/modernize/powershell_install_package.rb +51 -0
  64. data/lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb +54 -0
  65. data/lib/rubocop/cop/chef/modernize/resource_set_or_return.rb +25 -23
  66. data/lib/rubocop/cop/chef/modernize/resource_with_allowed_actions.rb +77 -0
  67. data/lib/rubocop/cop/chef/modernize/resource_with_attributes.rb +37 -35
  68. data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +54 -0
  69. data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +25 -23
  70. data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +26 -24
  71. data/lib/rubocop/cop/chef/{effortless/node_save.rb → modernize/seven_zip_archive.rb} +16 -16
  72. data/lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb +59 -0
  73. data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +20 -18
  74. data/lib/rubocop/cop/chef/modernize/windows_default_recipe.rb +23 -21
  75. data/lib/rubocop/cop/chef/modernize/windows_version_helper.rb +20 -18
  76. data/lib/rubocop/cop/chef/modernize/windows_zipfile.rb +15 -13
  77. data/lib/rubocop/cop/chef/style/attribute_keys.rb +59 -57
  78. data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +14 -12
  79. data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +65 -63
  80. data/lib/rubocop/cop/chef/style/comments_format.rb +48 -45
  81. data/lib/rubocop/cop/chef/style/file_mode.rb +32 -30
  82. metadata +24 -9
  83. data/lib/rubocop/cop/chef/deprecation/respond_to_metadata.rb +0 -53
  84. data/lib/rubocop/cop/chef/modernize/ohai_default_recipe.rb +0 -45
  85. data/lib/rubocop/cop/chef/modernize/resource_with_allowed_action.rb +0 -75
  86. data/lib/rubocop/cop/chef/modernize/use_inline_resources.rb +0 -54
  87. data/lib/rubocop/cop/chef/modernize/xml_ruby_recipe.rb +0 -49
  88. data/lib/rubocop/cop/chef/modernize/yum_dnf_compat_recipe.rb +0 -49
@@ -0,0 +1,47 @@
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
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ module ChefCorrectness
21
+ # The Ohai default recipe previously allowed a user to ship custom Ohai plugins to a system by including them
22
+ # in a directory in the Ohai cookbook. This functionality was replaced with the ohai_plugin resource, which
23
+ # should be used instead as it doesn't require forking the ohai cookbook.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # include_recipe 'ohai::default'
29
+ # include_recipe 'ohai'
30
+ #
31
+ class IncludingOhaiDefaultRecipe < Cop
32
+ MSG = "Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely".freeze
33
+
34
+ def_node_matcher :ohai_recipe_usage?, <<-PATTERN
35
+ (send nil? :include_recipe (str {"ohai" "ohai::default"}))
36
+ PATTERN
37
+
38
+ def on_send(node)
39
+ ohai_recipe_usage?(node) do
40
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -17,49 +17,51 @@
17
17
  module RuboCop
18
18
  module Cop
19
19
  module Chef
20
- # When using properties in a custom resource you shouldn't set a property to
21
- # required and then provide a default value. If a property is required the
22
- # user will always pass in a value and the default will never be used. In Chef
23
- # Infra Client 13+ this became an error.
24
- #
25
- # @example
26
- #
27
- # # bad
28
- # property :bob, String, required: true, default: 'foo'
29
- #
30
- # # good
31
- # property :bob, String, required: true
32
- #
33
- class PropertyWithRequiredAndDefault < Cop
34
- MSG = 'Resource property should not be both required and have a default value. This will fail on Chef Infra Client 13+'.freeze
20
+ module ChefCorrectness
21
+ # When using properties in a custom resource you shouldn't set a property to
22
+ # required and then provide a default value. If a property is required the
23
+ # user will always pass in a value and the default will never be used. In Chef
24
+ # Infra Client 13+ this became an error.
25
+ #
26
+ # @example
27
+ #
28
+ # # bad
29
+ # property :bob, String, required: true, default: 'foo'
30
+ #
31
+ # # good
32
+ # property :bob, String, required: true
33
+ #
34
+ class PropertyWithRequiredAndDefault < Cop
35
+ MSG = 'Resource property should not be both required and have a default value. This will fail on Chef Infra Client 13+'.freeze
35
36
 
36
- def on_send(node)
37
- if required_property?(node) && property_has_default?(node)
38
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
37
+ def on_send(node)
38
+ if required_property?(node) && property_has_default?(node)
39
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
40
+ end
39
41
  end
40
- end
41
42
 
42
- private
43
+ private
43
44
 
44
- def required_property?(node)
45
- if node.method_name == :property
46
- node.arguments.each do |arg|
47
- if arg.type == :hash
48
- return true if arg.source.match?(/required:\s*true/)
45
+ def required_property?(node)
46
+ if node.method_name == :property
47
+ node.arguments.each do |arg|
48
+ if arg.type == :hash
49
+ return true if arg.source.match?(/required:\s*true/)
50
+ end
49
51
  end
52
+ false # no required: true found
50
53
  end
51
- false # no required: true found
52
54
  end
53
- end
54
55
 
55
- def property_has_default?(node)
56
- if node.method_name == :property
57
- node.arguments.each do |arg|
58
- if arg.type == :hash
59
- return true if arg.source.match?(/default:/)
56
+ def property_has_default?(node)
57
+ if node.method_name == :property
58
+ node.arguments.each do |arg|
59
+ if arg.type == :hash
60
+ return true if arg.source.match?(/default:/)
61
+ end
60
62
  end
63
+ false # no default: found
61
64
  end
62
- false # no default: found
63
65
  end
64
66
  end
65
67
  end
@@ -17,40 +17,42 @@
17
17
  module RuboCop
18
18
  module Cop
19
19
  module Chef
20
- # When using properties in a custom resource you should use name_property not
21
- # the legacy name_attribute from the days of attributes
22
- #
23
- # @example
24
- #
25
- # # bad
26
- # property :bob, String, name_attribute: true
27
- #
28
- # # good
29
- # property :bob, String, name_property: true
30
- #
31
- class PropertyWithNameAttribute < Cop
32
- MSG = 'Resource property sets name_attribute not name_property'.freeze
20
+ module ChefCorrectness
21
+ # When using properties in a custom resource you should use name_property not
22
+ # the legacy name_attribute from the days of attributes
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # property :bob, String, name_attribute: true
28
+ #
29
+ # # good
30
+ # property :bob, String, name_property: true
31
+ #
32
+ class PropertyWithNameAttribute < Cop
33
+ MSG = 'Resource property sets name_attribute not name_property'.freeze
33
34
 
34
- def on_send(node)
35
- add_offense(node, location: :expression, message: MSG, severity: :refactor) if attribute_method_mix?(node)
36
- end
35
+ def on_send(node)
36
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if attribute_method_mix?(node)
37
+ end
37
38
 
38
- def autocorrect(node)
39
- lambda do |corrector|
40
- corrector.replace(node.loc.expression, node.source.gsub('name_attribute', 'name_property'))
39
+ def autocorrect(node)
40
+ lambda do |corrector|
41
+ corrector.replace(node.loc.expression, node.source.gsub('name_attribute', 'name_property'))
42
+ end
41
43
  end
42
- end
43
44
 
44
- private
45
+ private
45
46
 
46
- def attribute_method_mix?(node)
47
- if node.method_name == :property
48
- node.arguments.each do |arg|
49
- if arg.type == :hash
50
- return true if arg.source.match?(/name_attribute:/)
47
+ def attribute_method_mix?(node)
48
+ if node.method_name == :property
49
+ node.arguments.each do |arg|
50
+ if arg.type == :hash
51
+ return true if arg.source.match?(/name_attribute:/)
52
+ end
51
53
  end
54
+ false # no name_attribute found
52
55
  end
53
- false # no name_attribute found
54
56
  end
55
57
  end
56
58
  end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright:: 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
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ module ChefCorrectness
21
+ # Chef Infra Client uses properties in several resources to track state. These
22
+ # should not be set in recipes as they break the internal workings of the Chef
23
+ # Infra Client
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # service 'foo' do
29
+ # running true
30
+ # action [:start, :enable]
31
+ # end
32
+ #
33
+ # # good
34
+ # service 'foo' do
35
+ # action [:start, :enable]
36
+ # end
37
+ #
38
+ class ResourceSetsInternalProperties < Cop
39
+ include RuboCop::Chef::CookbookHelpers
40
+
41
+ MSG = 'Do not set properties used internally by Chef Infra Client to track the system state.'.freeze
42
+
43
+ def on_block(node)
44
+ match_property_in_resource?(:service, 'running', node) do |prop|
45
+ add_offense(prop, location: :expression, message: MSG, severity: :refactor)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,51 @@
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 ChefCorrectness
22
+ # Use name properties instead of setting the name property in a resource. Setting the name property
23
+ # directly causes notification and reporting issues.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # service 'foo' do
29
+ # name 'bar'
30
+ # end
31
+ #
32
+ # # good
33
+ # service 'foo' do
34
+ # service_name 'bar'
35
+ # end
36
+ #
37
+ class ResourceSetsNameProperty < Cop
38
+ include RuboCop::Chef::CookbookHelpers
39
+
40
+ MSG = 'Resource sets the name property in the resource instead of using a name_property.'.freeze
41
+
42
+ def on_block(node)
43
+ match_property_in_resource?(nil, 'name', node) do |name_node|
44
+ add_offense(name_node, location: :expression, message: MSG, severity: :refactor)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
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 ChefCorrectness
22
+ # The :nothing action is often typo'd as :none
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # service 'foo' do
28
+ # action :none
29
+ # end
30
+ #
31
+ # # good
32
+ # service 'foo' do
33
+ # action :nothing
34
+ # end
35
+ #
36
+ class ResourceWithNoneAction < Cop
37
+ include RuboCop::Chef::CookbookHelpers
38
+
39
+ MSG = 'Resource uses the nonexistent :none action instead of the :nothing action'.freeze
40
+
41
+ def on_block(node)
42
+ match_property_in_resource?(nil, 'action', node) do |action_node|
43
+ action_node.arguments.each do |action|
44
+ add_offense(action, location: :expression, message: MSG, severity: :refactor) if action.source == ':none'
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -17,35 +17,37 @@
17
17
  module RuboCop
18
18
  module Cop
19
19
  module Chef
20
- # Use a service resource to start and stop services
21
- #
22
- # @example when command starts a service
23
- #
24
- # # bad
25
- # command "/etc/init.d/mysql start"
26
- # command "/sbin/service/memcached start"
27
- #
28
- class ServiceResource < Cop
29
- MSG = 'Use a service resource to start and stop services'.freeze
20
+ module ChefCorrectness
21
+ # Use a service resource to start and stop services
22
+ #
23
+ # @example when command starts a service
24
+ #
25
+ # # bad
26
+ # command "/etc/init.d/mysql start"
27
+ # command "/sbin/service/memcached start"
28
+ #
29
+ class ServiceResource < Cop
30
+ MSG = 'Use a service resource to start and stop services'.freeze
30
31
 
31
- def_node_matcher :execute_command?, <<-PATTERN
32
- (send nil? :command $str)
33
- PATTERN
32
+ def_node_matcher :execute_command?, <<-PATTERN
33
+ (send nil? :command $str)
34
+ PATTERN
34
35
 
35
- def on_send(node)
36
- execute_command?(node) do |command|
37
- if starts_service?(command)
38
- add_offense(command, location: :expression, message: MSG, severity: :refactor)
36
+ def on_send(node)
37
+ execute_command?(node) do |command|
38
+ if starts_service?(command)
39
+ add_offense(command, location: :expression, message: MSG, severity: :refactor)
40
+ end
39
41
  end
40
42
  end
41
- end
42
43
 
43
- def starts_service?(cmd)
44
- cmd_str = cmd.to_s
45
- (cmd_str.include?('/etc/init.d') || ['service ', '/sbin/service ',
46
- 'start ', 'stop ', 'invoke-rc.d '].any? do |service_cmd|
47
- cmd_str.start_with?(service_cmd)
48
- end) && %w(start stop restart reload).any? { |a| cmd_str.include?(a) }
44
+ def starts_service?(cmd)
45
+ cmd_str = cmd.to_s
46
+ (cmd_str.include?('/etc/init.d') || ['service ', '/sbin/service ',
47
+ 'start ', 'stop ', 'invoke-rc.d '].any? do |service_cmd|
48
+ cmd_str.start_with?(service_cmd)
49
+ end) && %w(start stop restart reload).any? { |a| cmd_str.include?(a) }
50
+ end
49
51
  end
50
52
  end
51
53
  end
@@ -17,40 +17,42 @@
17
17
  module RuboCop
18
18
  module Cop
19
19
  module Chef
20
- # Use file_cache_path rather than hard-coding tmp paths
21
- #
22
- # @example downloading a large file into /tmp/
23
- #
24
- # # bad
25
- # remote_file '/tmp/large-file.tar.gz' do
26
- #
27
- # # good
28
- # remote_file "#{Chef::Config[:file_cache_path]}/large-file.tar.gz" do
29
- #
30
- #
31
- class TmpPath < Cop
32
- MSG = 'Use file_cache_path rather than hard-coding tmp paths'.freeze
20
+ module ChefCorrectness
21
+ # Use file_cache_path rather than hard-coding tmp paths
22
+ #
23
+ # @example downloading a large file into /tmp/
24
+ #
25
+ # # bad
26
+ # remote_file '/tmp/large-file.tar.gz' do
27
+ #
28
+ # # good
29
+ # remote_file "#{Chef::Config[:file_cache_path]}/large-file.tar.gz" do
30
+ #
31
+ #
32
+ class TmpPath < Cop
33
+ MSG = 'Use file_cache_path rather than hard-coding tmp paths'.freeze
33
34
 
34
- def_node_matcher :remote_file?, <<-PATTERN
35
- (send nil? :remote_file $str)
36
- PATTERN
35
+ def_node_matcher :remote_file?, <<-PATTERN
36
+ (send nil? :remote_file $str)
37
+ PATTERN
37
38
 
38
- def on_send(node)
39
- remote_file?(node) do |command|
40
- if hardcoded_tmp?(command) && !file_cache_path?(command)
41
- add_offense(command, location: :expression, message: MSG, severity: :refactor)
39
+ def on_send(node)
40
+ remote_file?(node) do |command|
41
+ if hardcoded_tmp?(command) && !file_cache_path?(command)
42
+ add_offense(command, location: :expression, message: MSG, severity: :refactor)
43
+ end
42
44
  end
43
45
  end
44
- end
45
46
 
46
- def hardcoded_tmp?(path)
47
- path_str = path.to_s.scan(/"(.*)"/)[0][0]
48
- path_str.start_with?('/tmp/')
49
- end
47
+ def hardcoded_tmp?(path)
48
+ path_str = path.to_s.scan(/"(.*)"/)[0][0]
49
+ path_str.start_with?('/tmp/')
50
+ end
50
51
 
51
- def file_cache_path?(path)
52
- path_str = path.to_s.scan(/"(.*)"/)[0][0]
53
- path_str.start_with?("\#\{Chef::Config[:file_cache_path]\}")
52
+ def file_cache_path?(path)
53
+ path_str = path.to_s.scan(/"(.*)"/)[0][0]
54
+ path_str.start_with?("\#\{Chef::Config[:file_cache_path]\}")
55
+ end
54
56
  end
55
57
  end
56
58
  end