Class: RuboCop::Cop::Chef::Style::FileMode
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/style/file_mode.rb
Overview
Use strings to represent file modes to avoid confusion between octal and base 10 integer formats.
Constant Summary collapse
- MSG =
'Use strings to represent file modes to avoid confusion between octal and base 10 integer formats'
- RESTRICT_ON_SEND =
[:mode, :files_mode].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubocop/cop/chef/style/file_mode.rb', line 63 def on_send(node) resource_mode?(node) do |mode_int| add_offense(mode_int, severity: :refactor) do |corrector| # If it was an octal literal, make sure we write out the right number. replacement_base = octal?(mode_int) ? 8 : 10 replacement_mode = mode_int.children.first.to_s(replacement_base) # we build our own escaped string instead of using .inspect because that way # we can use single quotes instead of the double quotes that .inspect adds corrector.replace(mode_int, "\'#{replacement_mode}\'") end end end |