Class: RuboCop::Cop::Yoshiki::Lint::ParenthesizeValueOmission

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
AllowedMethods, ReparsedEquivalence, KeywordOnlyArguments
Defined in:
lib/rubocop/cop/yoshiki/lint/parenthesize_value_omission.rb

Overview

Requires parentheses around method calls that use hash value omission (key:). Bare forms can absorb a following expression as the last keyword's value (silent semantic change).

Layout (hanging first kwarg) is Yoshiki/Layout/HangingKeywordArguments. Key order is Yoshiki/Style/SortedKeywordArguments.

Examples:

# bad
annotations destructive_hint:,
            read_only_hint:

# good
annotations(destructive_hint:,
            read_only_hint:)
# bad
annotations destructive_hint:, read_only_hint:

# good
annotations(destructive_hint:, read_only_hint:)

Constant Summary collapse

MSG =
[
  'Parenthesize method calls that use hash value omission ',
  '(`key:`) so a following expression is not absorbed as a value.'
].join.freeze

Instance Method Summary collapse

Instance Method Details

#on_investigation_endObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/rubocop/cop/yoshiki/lint/parenthesize_value_omission.rb', line 46

def on_investigation_end
  verified_by_reparse(@pending || []).each do |node|
    add_offense(offense_range(node), message: MSG) do |corrector|
      autocorrect(corrector, node)
    end
  end
  @pending = []

  super
end

#on_send(node) ⇒ Object Also known as: on_csend



39
40
41
42
43
# File 'lib/rubocop/cop/yoshiki/lint/parenthesize_value_omission.rb', line 39

def on_send node
  return unless eligible?(node)

  (@pending ||= []) << node
end