Sha256: 2c491c5e3353e13943627be361558723e8fe031e5ca7f70cf64810226ac20039

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RBS
      module Layout
        # @example default
        #   # bad
        #   def foo: () -> void
        #
        #          | (Integer) -> Integer
        #
        #   # good
        #   def foo: () -> void
        #          | (Integer) -> Integer
        class EmptyLinesAroundOverloads < RuboCop::RBS::CopBase
          extend AutoCorrector

          MSG = 'Empty line detected around overloads.'

          def on_rbs_def(decl)
            return unless 1 < decl.overloads.length

            decl.overloads.each_cons(2) do |overload, next_overload|
              check_empty_lines(overload, next_overload)
            end
          end

          def check_empty_lines(overload, next_overload)
            return if overload.method_type.location.end_line + 1 == next_overload.method_type.location.start_line

            total = 0
            range = overload.method_type.location.end_line...(next_overload.method_type.location.start_line - 1)
            processed_source.raw_source.each_line.each_with_index do |line, lineno|
              if range.cover?(lineno) && line == "\n"
                empty_line = range_between(total, total + 1)
                add_offense(empty_line) do |corrector|
                  corrector.remove(empty_line)
                end
              end
              total += line.length
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-on-rbs-1.3.0 lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb
rubocop-on-rbs-1.2.0 lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb
rubocop-on-rbs-1.1.0 lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb
rubocop-on-rbs-1.0.0 lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb