Sha256: cb2b1231e57321aa1be86829b2ca2c66f37bc50d4e89620289183cd84daf1ad0

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RBS
      module Layout
        # @example default
        #   # bad
        #   class Foo[:space:]
        #     def foo: () -> void[:space:]
        #   end[:space:]
        #
        #   # good
        #   class Foo
        #     def foo: () -> void
        #   end
        class TrailingWhitespace < RuboCop::RBS::CopBase
          extend AutoCorrector

          MSG = "Trailing whitespace detected."

          def on_rbs_new_investigation
            total = 0
            processed_source.raw_source.each_line do |line|
              total += line.length
              chomped = line.chomp
              next unless chomped.end_with?(' ', "\t")

              range = range_between(
                total - line.length + chomped.rstrip.length,
                total - line.length + chomped.length,
              )
              add_offense(range) do |corrector|
                corrector.remove(range)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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