Class: RuboCop::Cop::Yoshiki::Style::SortedKeywordArguments

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

Overview

Enforces alphabetical order for keyword-only method call arguments.

Layout is Yoshiki/Layout/HangingKeywordArguments. Value-omission parentheses are Yoshiki/Lint/ParenthesizeValueOmission. Padding is Layout/HashAlignment.

Examples:

# bad
annotations read_only_hint: true,
            destructive_hint: false

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

# good
annotations(destructive_hint:, read_only_hint:)

Constant Summary collapse

MSG =
'Sort keyword arguments alphabetically by key name.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_investigation_endObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/rubocop/cop/yoshiki/style/sorted_keyword_arguments.rb', line 42

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



35
36
37
38
39
# File 'lib/rubocop/cop/yoshiki/style/sorted_keyword_arguments.rb', line 35

def on_send node
  return unless eligible?(node)

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