Sha256: 028ee522dae529bedf52d101d7fe0cd03794fb14d18b70498c9793f57a3178d8

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RBS
      module Lint
        # Top-level namespaces are likely to conflict and should be avoided.
        #
        # @example
        #   # bad
        #   interface _Option
        #     def option: () -> untyped
        #   end
        #
        #   # good
        #   class Foo
        #     interface _Option
        #       def option: () -> untyped
        #     end
        #   end
        #
        class TopLevelInterface < RuboCop::RBS::CopBase
          MSG = 'Top level interface detected.'

          def on_rbs_new_investigation
            @last_end = nil
          end

          def on_rbs_class(decl)
            return unless @last_end_pos.nil? || (@last_end_pos < decl.location.end_pos)

            @last_end_pos = decl.location.end_pos
          end
          alias on_rbs_module on_rbs_class

          def on_rbs_interface(decl)
            return unless @last_end_pos.nil? || (@last_end_pos < decl.location.start_pos)

            range = location_to_range(decl.location)
            add_offense(range)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-on-rbs-1.2.0 lib/rubocop/cop/rbs/lint/top_level_interface.rb