Class: RuboCop::Cop::Yoshiki::Layout::HangingKeywordArguments
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Yoshiki::Layout::HangingKeywordArguments
- Extended by:
- AutoCorrector
- Includes:
- AllowedMethods, ReparsedEquivalence, KeywordOnlyArguments
- Defined in:
- lib/rubocop/cop/yoshiki/layout/hanging_keyword_arguments.rb
Overview
Prefers multiline keyword-only method calls in hanging form: first keyword on the same line as the method, continuations aligned under the first keyword.
Ordinary kwargs omit parentheses. Hash value omission (key:) keeps
parentheses (see Yoshiki/Lint/ParenthesizeValueOmission); this cop only
hangs inside existing parens for those calls.
Key order is Yoshiki/Style/SortedKeywordArguments. Padding is Layout/HashAlignment.
Constant Summary collapse
- MSG_OMIT_PARENS =
[ 'Use hanging keyword arguments ', '(first kwarg on the method line, no parentheses).' ].join.freeze
- MSG_KEEP_PARENS =
[ 'Use hanging keyword arguments with parentheses ', 'when using hash value omission ', '(first kwarg on the method line).' ].join.freeze
Instance Method Summary collapse
- #on_investigation_end ⇒ Object
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_investigation_end ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubocop/cop/yoshiki/layout/hanging_keyword_arguments.rb', line 61 def on_investigation_end verified_by_reparse(@pending || []).each do |node| add_offense(offense_range(node), message: (node)) do |corrector| autocorrect(corrector, node) end end @pending = [] super end |
#on_send(node) ⇒ Object Also known as: on_csend
54 55 56 57 58 |
# File 'lib/rubocop/cop/yoshiki/layout/hanging_keyword_arguments.rb', line 54 def on_send node return unless eligible?(node) (@pending ||= []) << node end |