class RuboCop::Cop::Layout::EmptyLineAfterMagicComment
end
# Some code
class Person
# Some documentation for Person
# frozen_string_literal: true
# bad
end
# Some code
class Person
# Some documentation for Person
# frozen_string_literal: true
# good
@example
Checks for a newline after the final magic comment.
def comments_before_code(source)
def comments_before_code(source) if source.ast source.comments.take_while { |comment| comment.loc.line < source.ast.loc.line } else source.comments end end
def last_magic_comment(source)
-
(nil)
- otherwise -
(Parser::Source::Comment)
- if magic comments exist before code
def last_magic_comment(source) comments_before_code(source) .reverse .find { |comment| MagicComment.parse(comment.text).any? } end
def offending_range(last_magic_comment)
def offending_range(last_magic_comment) source_range(processed_source.buffer, last_magic_comment.loc.line + 1, 0) end
def on_new_investigation
def on_new_investigation return unless (last_magic_comment = last_magic_comment(processed_source)) return unless (next_line = processed_source[last_magic_comment.loc.line]) return if next_line.strip.empty? offending_range = offending_range(last_magic_comment) add_offense(offending_range) do |corrector| corrector.insert_before(offending_range, "\n") end end