Class: Rubocop::Cop::LineBreakAfterGuardClauses
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Rubocop::Cop::LineBreakAfterGuardClauses
- Defined in:
- lib/rubocop/cop/line_break_after_guard_clauses.rb
Overview
Ensures a line break after guard clauses.
Constant Summary collapse
- MSG =
'Add a line break after guard clauses'
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
74 75 76 77 78 |
# File 'lib/rubocop/cop/line_break_after_guard_clauses.rb', line 74 def autocorrect(node) lambda do |corrector| corrector.insert_after(node.loc.expression, "\n") end end |
#guard_clause_node?(node) ⇒ Object
62 63 64 |
# File 'lib/rubocop/cop/line_break_after_guard_clauses.rb', line 62 def_node_matcher :guard_clause_node?, <<-PATTERN [{(send nil? {:raise :fail :throw} ...) return break next} single_line?] PATTERN |
#on_if(node) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/rubocop/cop/line_break_after_guard_clauses.rb', line 66 def on_if(node) return unless node.single_line? return unless guard_clause?(node) return if next_line(node).blank? || clause_last_line?(next_line(node)) || guard_clause?(next_sibling(node)) add_offense(node) end |