Class: RuboCop::Cop::Sevencop::RSpecMatcherConsistentParentheses

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/sevencop/rspec_matcher_consistent_parentheses.rb

Overview

Keep consistent parentheses style in RSpec matchers.

Examples:

# bad
is_expected.to eq 1

# good
is_expected.to eq(1)

Constant Summary collapse

MSG =
'Keep consistent parentheses style in RSpec matchers.'
RESTRICT_ON_SEND =
%i[to].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/sevencop/rspec_matcher_consistent_parentheses.rb', line 23

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

  first_argument = node.first_argument
  return unless inconsistent?(first_argument)

  add_offense(first_argument) do |corrector|
    add_parentheses(first_argument, corrector)
  end
end