class RuboCop::Cop::InSpecStyle::ShadowProperties

Shadow resource properties `user|password|last_change|expiry_date|line` is deprecated in favor of `users|passwords|last_changes|expiry_dates|lines`

@example EnforcedStyle: InSpecStyle (default)

# Use users instead

# bad
describe shadow('/etc/my-custom-place/shadow') do
  its('user') { should eq 'user' }
end

# good
describe shadow('/etc/my-custom-place/shadow') do
  its('users') { should eq 'user' }
end

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/inspecstyle/shadow_properties.rb, line 64
def autocorrect(node)
  lambda do |corrector|
    corrector.insert_after(offense_range(node), 's')
  end
end
on_block(node) click to toggle source
# File lib/rubocop/cop/inspecstyle/shadow_properties.rb, line 48
def on_block(node)
  return unless inside_shadow_spec?(node)
  node.descendants.each do |descendant|
    deprecated_shadow_property?(descendant) do |violation|
      add_offense(
        descendant,
        location: offense_range(descendant),
        message: format(
          MSG,
          violation: violation
        )
      )
    end
  end
end

Private Instance Methods

inside_shadow_spec?(root) click to toggle source
# File lib/rubocop/cop/inspecstyle/shadow_properties.rb, line 72
def inside_shadow_spec?(root)
  spec?(root) && shadow_resource?(root)
end
offense_range(node) click to toggle source
# File lib/rubocop/cop/inspecstyle/shadow_properties.rb, line 76
def offense_range(node)
  source = node.children[0].children[-1].loc.expression
  range_between(source.begin_pos+1, source.end_pos-1)
end