Class: RuboCop::Cop::Style::RbsInline::RequireRbsInlineComment

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/style/rbs_inline/require_rbs_inline_comment.rb

Overview

Checks for the presence or absence of ‘# rbs_inline:` magic comment.

RBS::Inline supports two modes: opt-in (requires ‘# rbs_inline: enabled`) and opt-out (processes all files by default). This cop enforces consistency in which mode your codebase uses.

Examples:

EnforcedStyle: always (default)

# bad
# (no rbs_inline comment)
class Foo
end

# good
# rbs_inline: enabled
class Foo
end

# good
# rbs_inline: disabled
class Foo
end

EnforcedStyle: never

# bad
# rbs_inline: enabled
class Foo
end

# good
# rbs_inline: disabled
class Foo
end

# good
# (no rbs_inline comment)
class Foo
end

Constant Summary collapse

MSG_MISSING =
'Missing `# rbs_inline:` magic comment.'
MSG_FORBIDDEN =
'Remove `# rbs_inline:` magic comment.'

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject

: void



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubocop/cop/style/rbs_inline/require_rbs_inline_comment.rb', line 52

def on_new_investigation #: void
  return if processed_source.buffer.source.empty?

  magic_comment = find_rbs_inline_magic_comment
  return if disabled?(magic_comment)

  if style == :always
    check_always_style(magic_comment)
  elsif style == :never
    check_never_style(magic_comment)
  end
end