Class: RuboCop::Cop::InSpecStyle::FirstCop

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/inspecstyle/first_cop.rb

Overview

TODO: Write cop description and example of bad / good code. For every `SupportedStyle` and unique configuration, there needs to be examples. Examples must have valid Ruby syntax. Do not use upticks.

Examples:

EnforcedStyle: bar (default)

# Description of the `bar` style.

# bad
bad_bar_method

# bad
bad_bar_method(args)

# good
good_bar_method

# good
good_bar_method(args)

EnforcedStyle: foo

# Description of the `foo` style.

# bad
bad_foo_method

# bad
bad_foo_method(args)

# good
good_foo_method

# good
good_foo_method(args)

Constant Summary collapse

MSG =

TODO: Implement the cop in here.

In many cases, you can use a node matcher for matching node pattern. See github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/node_pattern.rb

For example

'Use `#good_method` instead of `#bad_method`. %<example_insertion>'

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



60
61
62
63
64
65
# File 'lib/rubocop/cop/inspecstyle/first_cop.rb', line 60

def autocorrect(node)
  ->(corrector) do
    corrector.insert_before(node.source_range, 'good_method')
    corrector.remove(node.source_range)
  end
end

#on_send(node) ⇒ Object



54
55
56
57
58
# File 'lib/rubocop/cop/inspecstyle/first_cop.rb', line 54

def on_send(node)
  return unless bad_method?(node)
  message = format(MSG, example_insertion: node.first.source)
  add_offense(node, message: message)
end