Class: Rubocop::Cop::LineBreakAroundConditionalBlock
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Rubocop::Cop::LineBreakAroundConditionalBlock
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp
- Defined in:
- lib/rubocop/cop/line_break_around_conditional_block.rb
Overview
Ensures a line break around conditional blocks.
Constant Summary collapse
- MSG =
'Add a line break around conditional blocks'
Instance Method Summary collapse
Instance Method Details
#on_if(node) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubocop/cop/line_break_around_conditional_block.rb', line 51 def on_if(node) # This cop causes errors in haml files, so let's skip those return if in_haml?(node) return if node.single_line? return unless node.if? || node.unless? corrector_block = lambda do |corrector| line = range_by_whole_lines(node.source_range) corrector.insert_before(line, "\n") unless previous_line_valid?(node) corrector.insert_after(line, "\n") unless last_line_valid?(node) end add_offense(node, &corrector_block) unless previous_line_valid?(node) add_offense(node, &corrector_block) unless last_line_valid?(node) end |