Class: RuboCop::Cop::Legion::HelperMigration::DefinedTransportGuard
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::HelperMigration::DefinedTransportGuard
- Defined in:
- lib/rubocop/cop/legion/helper_migration/defined_transport_guard.rb
Overview
Detects ‘defined?(Legion::Transport)` guards and suggests using `transport_connected?` from `Legion::Transport::Helper` instead. The helper checks both that the module is loaded and that the transport is actually connected, which is the correct semantics.
Constant Summary collapse
- MSG =
'Use `transport_connected?` instead of `defined?(Legion::Transport)`. ' \ 'Include `Legion::Transport::Helper` via the transport helper mixin.'
Instance Method Summary collapse
-
#on_defined?(node) ⇒ Boolean
Cannot use def_node_matcher with ‘defined?` node type — Ruby treats `defined?` as a keyword and the matcher DSL chokes on the `?` suffix.
Instance Method Details
#on_defined?(node) ⇒ Boolean
Cannot use def_node_matcher with ‘defined?` node type — Ruby treats `defined?` as a keyword and the matcher DSL chokes on the `?` suffix. Use manual AST inspection instead (same approach as LoggingGuard).
27 28 29 30 31 |
# File 'lib/rubocop/cop/legion/helper_migration/defined_transport_guard.rb', line 27 def on_defined?(node) return false unless legion_transport_defined?(node) add_offense(node, message: MSG) end |