Sha256: d0d27497209d22ca1d10a37102bef2bd81a244cbcac008b554dc5a4751fb3456

Contents?: true

Size: 1.01 KB

Versions: 73

Compression:

Stored size: 1.01 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 < Base
        extend AutoCorrector

        MSG = 'Unnecessary blank line at the beginning of the source.'

        def on_new_investigation
          token = processed_source.tokens[0]
          return unless token && token.line > 1

          add_offense(token.pos) do |corrector|
            range = Parser::Source::Range.new(processed_source.buffer, 0, token.begin_pos)

            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 8 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/layout/leading_empty_lines.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.29.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.29.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.28.2 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.28.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.28.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.27.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.26.1 lib/rubocop/cop/layout/leading_empty_lines.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.26.0 lib/rubocop/cop/layout/leading_empty_lines.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/leading_empty_lines.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.25.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.25.0 lib/rubocop/cop/layout/leading_empty_lines.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/leading_empty_lines.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/leading_empty_lines.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.24.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.24.0 lib/rubocop/cop/layout/leading_empty_lines.rb