Class: RuboCop::Cop::Chef::Correctness::TmpPath
- Defined in:
- lib/rubocop/cop/chef/correctness/tmp_path.rb
Overview
Use file_cache_path rather than hard-coding system temp paths
Constant Summary collapse
- MSG =
'Use file_cache_path rather than hard-coding tmp paths'
- RESTRICT_ON_SEND =
[:remote_file].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#file_cache_path?(path) ⇒ Boolean
51 52 53 54 |
# File 'lib/rubocop/cop/chef/correctness/tmp_path.rb', line 51 def file_cache_path?(path) path_str = path.to_s.scan(/"(.*)"/)[0][0] path_str.start_with?("\#\{Chef::Config[:file_cache_path]\}") end |
#hardcoded_tmp?(path) ⇒ Boolean
46 47 48 49 |
# File 'lib/rubocop/cop/chef/correctness/tmp_path.rb', line 46 def hardcoded_tmp?(path) path_str = path.to_s.scan(/"(.*)"/)[0][0] path_str.start_with?('/tmp/') end |
#on_send(node) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rubocop/cop/chef/correctness/tmp_path.rb', line 39 def on_send(node) remote_file?(node) do |command| return unless hardcoded_tmp?(command) && !file_cache_path?(command) add_offense(command, severity: :refactor) end end |