Class: RuboCop::Cop::Chef::ChefStyle::FileMode

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/style/file_mode.rb

Overview

Check the file modes are given as strings instead of integers.

Examples:


# bad
mode 644
mode 0644

# good
mode '644'

Constant Summary collapse

MSG =
'Use strings for file modes'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/rubocop/cop/chef/style/file_mode.rb', line 45

def autocorrect(node)
  lambda do |corrector|
    # If it was an octal literal, make sure we write out the right number.
    replacement_base = octal?(node) ? 8 : 10
    replacement_mode = node.children.first.to_s(replacement_base)
    corrector.replace(node.loc.expression, replacement_mode.inspect)
  end
end

#on_send(node) ⇒ Object



39
40
41
42
43
# File 'lib/rubocop/cop/chef/style/file_mode.rb', line 39

def on_send(node)
  resource_mode?(node) do |mode_int|
    add_offense(mode_int, location: :expression, message: MSG, severity: :refactor)
  end
end