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 last_magic_comment(source)
-
(nil)
- otherwise -
(Parser::Source::Comment)
- if magic comments exist before code
def last_magic_comment(source) source .comments .take_while { |comment| comment.loc.line < source.ast.loc.line } .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 processed_source.ast && (last_magic_comment = last_magic_comment(processed_source)) return if processed_source[last_magic_comment.loc.line].strip.empty? offending_range = offending_range(last_magic_comment) add_offense(offending_range) do |corrector| corrector.insert_before(offending_range, "\n") end end