Class: RuboCop::Cop::RBS::Lint::TopLevelInterface

Inherits:
RBS::CopBase
  • Object
show all
Defined in:
lib/rubocop/cop/rbs/lint/top_level_interface.rb

Overview

Top-level namespaces are likely to conflict and should be avoided.

Examples:

# bad
interface _Option
  def option: () -> untyped
end

# good
class Foo
  interface _Option
    def option: () -> untyped
  end
end

Constant Summary collapse

MSG =
'Top level interface detected.'

Instance Attribute Summary

Attributes inherited from RBS::CopBase

#processed_rbs_source

Instance Method Summary collapse

Methods inherited from RBS::CopBase

documentation_url, #investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_attribute, #on_rbs_constant, #on_rbs_def, #on_rbs_global, #on_rbs_parsing_error, #on_rbs_private, #on_rbs_public, #on_rbs_type_alias, #on_rbs_var, #parse_rbs, #rbs_buffer, #tokenize, #walk

Methods included from RBS::OnTypeHelper

#on_not_type, #on_type

Instance Method Details

#on_rbs_class(decl) ⇒ Object Also known as: on_rbs_module



29
30
31
32
33
# File 'lib/rubocop/cop/rbs/lint/top_level_interface.rb', line 29

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

#on_rbs_interface(decl) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/rubocop/cop/rbs/lint/top_level_interface.rb', line 36

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

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

#on_rbs_new_investigationObject



25
26
27
# File 'lib/rubocop/cop/rbs/lint/top_level_interface.rb', line 25

def on_rbs_new_investigation
  @last_end = nil
end