class RuboCop::Cop::Layout::EmptyLineAfterMagicComment

def last_magic_comment(source)

Returns:
  • (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