Class: RuboCop::Cop::Chef::Correctness::InvalidPlatformMetadata
- Extended by:
- AutoCorrector
- Includes:
- RuboCop::Chef::PlatformHelpers
- Defined in:
- lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb
Overview
metadata.rb ‘supports` methods should contain valid platforms. See [Infra Language: Platform](docs.chef.io/infra_language/checking_platforms/#platform-values) for a list of many common platform values.
Constant Summary collapse
- MSG =
'metadata.rb "supports" platform is invalid'
- RESTRICT_ON_SEND =
[:supports].freeze
Constants included from RuboCop::Chef::PlatformHelpers
RuboCop::Chef::PlatformHelpers::INVALID_PLATFORMS, RuboCop::Chef::PlatformHelpers::INVALID_PLATFORM_FAMILIES
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#corrected_platform_source(node) ⇒ Object
private
78 79 80 81 82 83 84 |
# File 'lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb', line 78 def corrected_platform_source(node) val = INVALID_PLATFORMS[node.str_content.delete(',').downcase] return false unless val # if the value was previously quoted make sure to quote it again node.source.match?(/^('|")/) ? "'" + val + "'" : val end |
#on_block(node) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb', line 63 def on_block(node) supports_array?(node) do |plats| plats.values.each do |plat| next unless INVALID_PLATFORMS[plat.str_content] add_offense(plat, severity: :refactor) do |corrector| correct_string = corrected_platform_source(plat) next unless correct_string corrector.replace(plat, correct_string) end end end end |
#on_send(node) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb', line 52 def on_send(node) supports?(node) do |plat| next unless INVALID_PLATFORMS[plat.str_content] add_offense(plat, severity: :refactor) do |corrector| correct_string = corrected_platform_source(plat) next unless correct_string corrector.replace(plat, correct_string) end end end |