Class: RuboCop::Cop::InSpecStyle::DeprecatedAttributes

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/inspecstyle/deprecated_attributes.rb

Overview

Checks if deprecated method attribute is used.

Examples:

EnforcedStyle: InSpecStyle (default)

# Attributes have been deprecated for inputs
# https://github.com/inspec/inspec/issues/3802

# bad
attribute('my_element', value: 10)

# good
input('my_element', value: 10)

Constant Summary collapse

MSG =
'Use `#input` instead of `#attribute`. This will be removed in '\
'InSpec 5'

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



34
35
36
37
38
# File 'lib/rubocop/cop/inspecstyle/deprecated_attributes.rb', line 34

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(offense_range(node), preferred_replacement)
  end
end

#on_send(node) ⇒ Object



28
29
30
31
32
# File 'lib/rubocop/cop/inspecstyle/deprecated_attributes.rb', line 28

def on_send(node)
  return unless attribute?(node)

  add_offense(node, location: node.loc.selector)
end