Sha256: 5d9045a270042a5da3845a5b4cb8cdef25e87a75b7416314a4d33ed8fe3664f7

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # This hint checks for unnecessary leading blank lines at the beginning
      # of a file.
      #
      # @example
      #
      #   # bad
      #   # (start of file)
      #
      #   class Foo
      #   end
      #
      #   # bad
      #   # (start of file)
      #
      #   # a comment
      #
      #   # good
      #   # (start of file)
      #   class Foo
      #   end
      #
      #   # good
      #   # (start of file)
      #   # a comment
      class LeadingEmptyLines < Cop
        MSG = 'Unnecessary blank line at the beginning of the source.'

        def investigate(processed_source)
          token = processed_source.tokens[0]
          return unless token && token.line > 1

          add_offense(processed_source.tokens[0],
                      location: processed_source.tokens[0].pos)
        end

        def autocorrect(node)
          range = Parser::Source::Range.new(processed_source.buffer,
                                            0,
                                            node.begin_pos)

          lambda do |corrector|
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rbhint-0.87.1.rc1 lib/rubocop/cop/layout/leading_empty_lines.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/layout/leading_empty_lines.rb