Class: RuboCop::Cop::Seams::NoCrossEngineDependency

Inherits:
Base
  • Object
show all
Defined in:
lib/seams/cops/no_cross_engine_dependency.rb

Overview

Flags ‘require`/`require_relative` calls that pull source files out of another engine. Engines should depend on each other only through public events (Seams::Events::Publisher) and explicitly-exposed concerns — not by requiring private files.

Constant Summary collapse

MSG =
"Engine `%<own>s` must not require `%<path>s` from another engine. " \
"Communicate via events or via `%<other>s`'s exposed concerns."

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/seams/cops/no_cross_engine_dependency.rb', line 21

def on_send(node)
  path = require_call?(node)
  return unless path

  offending_engine = other_engine_for(path)
  return unless offending_engine

  add_offense(
    node,
    message: format(MSG, own: own_engine, path: path,
                         other: capitalize(offending_engine))
  )
end

#require_call?(node) ⇒ Object



17
18
19
# File 'lib/seams/cops/no_cross_engine_dependency.rb', line 17

def_node_matcher :require_call?, <<~PATTERN
  (send nil? {:require :require_relative} (str $_))
PATTERN