Class: RuboCop::Cop::Elegant::PairedBrackets
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Elegant::PairedBrackets
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/elegant/paired_brackets.rb
Overview
Enforces the “paired brackets” notation: every round, square, or curly bracket must either be paired with its matching counterpart on the same line, or end its own line (when opening) or start its own line (when closing). Brackets stranded in the middle of a multi-line expression are forbidden because they hide the structure of the code.
Auto-correct relocates the offending bracket onto its own line: an opener that is not at end-of-line gets a newline and the opener-line indent plus two spaces inserted right after it; a closer that is not at start-of-line gets a newline and the opener-line indent inserted right before it. Surrounding indentation may still need a follow-up layout pass, but the brackets themselves end up paired.
See www.yegor256.com/2014/10/23/paired-brackets-notation.html
Constant Summary collapse
- MSG =
'Bracket %<text>s must be paired on the same line, or start/end its line'
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ Object
32 33 34 35 |
# File 'lib/rubocop/cop/elegant/paired_brackets.rb', line 32 def on_new_investigation super pair.each { |duo| check(duo) } end |