Class: RuboCop::Cop::Ruact::NoSharedState

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/ruact/no_shared_state.rb

Overview

Prohibits shared mutable state: class variables, Thread.current, and module-level instance variables. All data must flow via explicit method arguments (NFR8, NFR13).

Examples:

# bad
@@manifest = nil
Thread.current[:rsc_request] = req

# good
def serialize(value, request:)
  request.allocate_id
end

Constant Summary collapse

MSG =
"Shared state is prohibited (NFR8/NFR13). Pass data as explicit method arguments."

Instance Method Summary collapse

Instance Method Details

#on_cvasgn(node) ⇒ Object



22
23
24
# File 'lib/rubocop/cop/ruact/no_shared_state.rb', line 22

def on_cvasgn(node)
  add_offense(node)
end

#on_send(node) ⇒ Object



26
27
28
29
30
# File 'lib/rubocop/cop/ruact/no_shared_state.rb', line 26

def on_send(node)
  return unless thread_current_write?(node)

  add_offense(node)
end