Sha256: 79e13c47145b6d59764ec2d7fc062b54eee5f8a4d6ced077e377bcdb79951f1a

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RBS
      module Layout
        module EmptyLinesAroundBody
          MSG_EXTRA = 'Extra empty line detected at %<kind>s body %<location>s.'

          private

          def check(decl)
            first_line = decl.location.start_line
            last_line = decl.location.end_line
            return if last_line == first_line

            check_beginning(first_line)
            check_ending(last_line)
          end

          def check_beginning(first_line)
            check_source(first_line, 'beginning')
          end

          def check_ending(last_line)
            check_source(last_line - 2, 'end')
          end

          def check_source(line_no, desc)
            return unless line_no.positive?
            return unless processed_source.lines[line_no]
            return unless processed_source.lines[line_no].empty?

            range = source_range(processed_source.buffer, line_no + 1, 0)
            message = message(MSG_EXTRA, desc)
            add_offense(range, message: message) do |corrector|
              corrector.remove(range)
            end
          end

          def message(type, location)
            format(type, kind: self.class::KIND, location: location)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-on-rbs-1.3.0 lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb
rubocop-on-rbs-1.2.0 lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb