Sha256: b255df3b0a39e41b3268e758634939f223ecdf067a83dead6f5ce0c618d5c0a0

Contents?: true

Size: 1023 Bytes

Versions: 197

Compression:

Stored size: 1023 Bytes

Contents

# frozen_string_literal: true

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

197 entries across 190 versions & 19 rubygems

Version Path
rubocop-1.72.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.72.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.71.2 lib/rubocop/cop/layout/leading_empty_lines.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.71.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.71.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.70.0 lib/rubocop/cop/layout/leading_empty_lines.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.69.2 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.69.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.69.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.68.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.67.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.66.1 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.66.0 lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.65.1 lib/rubocop/cop/layout/leading_empty_lines.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/layout/leading_empty_lines.rb
rubocop-1.65.0 lib/rubocop/cop/layout/leading_empty_lines.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/leading_empty_lines.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/leading_empty_lines.rb