Class: RuboCop::Cop::Sorbet::EnforceSigilOrder
- Inherits:
-
ValidSigil
- Object
- Base
- ValidSigil
- RuboCop::Cop::Sorbet::EnforceSigilOrder
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb
Overview
Checks that the Sorbet sigil comes as the first magic comment in the file, after the encoding comment if any.
The expected order for magic comments is: (en)?coding, typed, warn_indent then frozen_string_literal.
The ordering is for consistency only, except for the encoding comment which must be first, if present.
For example, the following bad ordering:
“‘ruby # frozen_string_literal: true # typed: true class Foo; end “`
Will be corrected as:
“‘ruby # typed: true # frozen_string_literal: true class Foo; end “`
Only ‘(en)?coding`, `typed`, `warn_indent` and `frozen_string_literal` magic comments are considered, other comments or magic comments are left in the same place.
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb', line 35 def on_new_investigation return if processed_source.tokens.empty? tokens = extract_magic_comments(processed_source) return if tokens.empty? check_magic_comments_order(tokens) end |