Module: RuboCop::Cop::EngineNodeContext

Included in:
Flexport::EngineApiBoundary, Flexport::GlobalModelAccessFromEngine
Defined in:
lib/rubocop/cop/mixin/engine_node_context.rb

Overview

Helpers for determining the context of a node for engine violations.

Instance Method Summary collapse

Instance Method Details

#in_module_or_class_declaration?(node) ⇒ Boolean

Sometimes modules/class are declared with the same name as an engine or global model. For example, you might have both:

/engines/foo
/app/graph/types/foo

We ignore instead of yielding false positive for the module declaration in the latter.

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/rubocop/cop/mixin/engine_node_context.rb', line 15

def in_module_or_class_declaration?(node)
  depth = 0
  max_depth = 10
  while node.const_type? && node.parent && depth < max_depth
    node = node.parent
    depth += 1
  end
  node.module_type? || node.class_type?
end