Module: RuboCop::RSpec::BlankLineSeparation
- Includes:
- Cop::RangeHelp, FinalEndLocation
- Included in:
- Cop::RSpec::EmptyLineAfterExampleGroup, Cop::RSpec::EmptyLineAfterFinalLet, Cop::RSpec::EmptyLineAfterHook, Cop::RSpec::EmptyLineAfterSubject
- Defined in:
- lib/rubocop/rspec/blank_line_separation.rb
Overview
Helps determine the offending location if there is not a blank line following the node. Allows comments to follow directly after.
Instance Method Summary collapse
- #autocorrect(node) ⇒ Object
- #last_child?(node) ⇒ Boolean
- #missing_separating_line(node) {|offending_loc(line)| ... } ⇒ Object
- #offending_loc(last_line) ⇒ Object
Methods included from FinalEndLocation
Instance Method Details
#autocorrect(node) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rubocop/rspec/blank_line_separation.rb', line 36 def autocorrect(node) lambda do |corrector| (node) do |location| corrector.insert_after(location.end, "\n") end end end |
#last_child?(node) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/rubocop/rspec/blank_line_separation.rb', line 30 def last_child?(node) return true unless node.parent&.begin_type? node.equal?(node.parent.children.last) end |
#missing_separating_line(node) {|offending_loc(line)| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/rubocop/rspec/blank_line_separation.rb', line 11 def (node) line = final_end_location(node).line line += 1 while comment_line?(processed_source[line]) return if processed_source[line].blank? yield offending_loc(line) end |
#offending_loc(last_line) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/rubocop/rspec/blank_line_separation.rb', line 21 def offending_loc(last_line) offending_line = processed_source[last_line - 1] content_length = offending_line.lstrip.length start = offending_line.length - content_length source_range(processed_source.buffer, last_line, start, content_length) end |