Sha256: e5690acbd7702a1b1aeba8914665e6118ccb4b8112574a2c89893902f9496436

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # This cop 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

24 entries across 23 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.89.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.89.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.88.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.87.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.87.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.86.0 lib/rubocop/cop/layout/leading_empty_lines.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/layout/leading_empty_lines.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.85.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.85.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.84.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.83.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.82.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.81.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.80.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-0.80.0 lib/rubocop/cop/layout/leading_empty_lines.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/leading_empty_lines.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/leading_empty_lines.rb