Class: RuboCop::Cop::Sorbet::EnforceSingleSigil

Inherits:
ValidSigil
  • Object
show all
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/sorbet/sigils/enforce_single_sigil.rb

Overview

Checks that there is only one Sorbet sigil in a given file

For example, the following class with two sigils

“‘ruby # typed: true # typed: true # frozen_string_literal: true class Foo; end “`

Will be corrected as:

“‘ruby # typed: true # frozen_string_literal: true class Foo; end “`

Other comments or magic comments are left in place.

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/sorbet/sigils/enforce_single_sigil.rb', line 29

def on_new_investigation
  return if processed_source.tokens.empty?

  sigils = extract_all_sigils(processed_source)
  return if sigils.empty?

  sigils[1..sigils.size].each do |token|
    add_offense(token.pos, message: "Files must only contain one sigil") do |corrector|
      autocorrect(corrector)
    end
  end
end