Class: RuboCop::Cop::Legion::ConstantSafety::BareProcess

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/legion/constant_safety/bare_process.rb

Overview

Detects bare ‘Process` method calls inside `module Legion` namespaces where `Process` resolves to `Legion::Process` instead of the stdlib.

Examples:

# bad (inside module Legion)
module Legion
  Process.pid
end

# good
module Legion
  ::Process.pid
end

Constant Summary collapse

MSG =
'Inside `module Legion`, bare `Process` resolves to `Legion::Process`. ' \
'Use `::Process`.'
RESTRICT_ON_SEND =
%i[
  pid ppid kill detach fork wait wait2 waitpid waitpid2
  getpgid setpgid daemon exit spawn times groups
  uid gid euid egid
].freeze

Instance Method Summary collapse

Instance Method Details

#bare_process_send?(node) ⇒ Object



33
34
35
# File 'lib/rubocop/cop/legion/constant_safety/bare_process.rb', line 33

def_node_matcher :bare_process_send?, <<~PATTERN
  (send (const nil? :Process) _ ...)
PATTERN

#on_send(node) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/legion/constant_safety/bare_process.rb', line 37

def on_send(node)
  return unless bare_process_send?(node)
  return unless inside_legion_namespace?(node)

  receiver = node.receiver
  add_offense(receiver) do |corrector|
    corrector.replace(receiver.source_range, '::Process')
  end
end