Class: Steep::Diagnostic::Ruby::ClassModuleMismatch

Inherits:
Base
  • Object
show all
Defined in:
lib/steep/diagnostic/ruby.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #node

Instance Method Summary collapse

Methods inherited from Base

#detail_lines, #diagnostic_code

Methods included from Helper

#error_name, #full_message

Constructor Details

#initialize(node:, name:) ⇒ ClassModuleMismatch

Returns a new instance of ClassModuleMismatch.



415
416
417
418
419
420
421
422
423
424
425
# File 'lib/steep/diagnostic/ruby.rb', line 415

def initialize(node:, name:)
  case node.type
  when :module, :class
    location = node.loc.name # steep:ignore NoMethod
  else
    raise "Unexpected node: #{node.type}"
  end
  super(node: node, location: location)

  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



413
414
415
# File 'lib/steep/diagnostic/ruby.rb', line 413

def name
  @name
end

Instance Method Details

#header_lineObject



427
428
429
430
431
432
433
434
435
436
# File 'lib/steep/diagnostic/ruby.rb', line 427

def header_line
  case node&.type
  when :module
    "#{name} is declared as a class in RBS"
  when :class
    "#{name} is declared as a module in RBS"
  else
    raise
  end
end