Class: RuboCop::Cop::Style::RbsInline::StructNewWithBlock
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Style::RbsInline::StructNewWithBlock
- Includes:
- FileFilter, StructClassMatcher
- Defined in:
- lib/rubocop/cop/style/rbs_inline/struct_new_with_block.rb,
sig/rubocop/cop/style/rbs_inline/struct_new_with_block.rbs
Overview
Checks for Struct.new calls with a block.
RBS::Inline does not parse the contents of Struct.new blocks, so any
methods defined inside will not be recognized for type checking. Instead,
call Struct.new without a block and define additional methods by
reopening the class separately.
Constant Summary collapse
- MSG =
"Do not use `Struct.new` with a block. RBS::Inline does not parse block contents, " \ "so methods defined in the block will not be recognized. " \ "Use a separate class definition instead."
Constants included from FileFilter
FileFilter::MAGIC_COMMENT_DISABLED, FileFilter::MAGIC_COMMENT_ENABLED, FileFilter::SUPPORTED_MODES
Instance Method Summary collapse
Methods included from StructClassMatcher
#attr_argument?, #struct_like_class?
Methods included from FileFilter
#add_offense, #configured_mode, #on_new_investigation, #rbs_inline_disabled?, #rbs_inline_enabled?, #rbs_inline_file_skipped?, #skip_by_mode?, warn_invalid_mode
Instance Method Details
#on_send(node) ⇒ void
This method returns an undefined value.
36 37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/style/rbs_inline/struct_new_with_block.rb', line 36 def on_send(node) #: void return unless struct_like_class?(node) block_node = node.parent return unless block_node&.block_type? add_offense(node) end |