Class: JRuby::Lint::Checkers::ForkExec

Inherits:
Object
  • Object
show all
Includes:
JRuby::Lint::Checker
Defined in:
lib/jruby/lint/checkers/fork_exec.rb

Instance Attribute Summary

Attributes included from JRuby::Lint::Checker

#collector

Instance Method Summary collapse

Methods included from JRuby::Lint::Checker

included, loaded_checkers

Instance Method Details

#add_finding(node) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jruby/lint/checkers/fork_exec.rb', line 31

def add_finding(node)
  msg = nil
  tags = [node.name]
  case node.name
  when 'fork'
    msg = 'Kernel#fork is not implemented on JRuby.'
    tags << :error
  when 'exec'
    msg = 'Kernel#exec does not replace the running JRuby process and may behave unexpectedly'
    tags << :warning
  end

  collector.findings << Finding.new(msg, tags, node.position)
end

#fork_exec?(node) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/jruby/lint/checkers/fork_exec.rb', line 27

def fork_exec?(node)
  node.name == "fork" || node.name == "exec"
end

#visitCallNode(node) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/jruby/lint/checkers/fork_exec.rb', line 6

def visitCallNode(node)
  if fork_exec?(node)
    @call_node = node
    child = node.child_nodes.first
    if child && %w(COLON3NODE CONSTNODE).include?(child.node_type.to_s) && child.name == "Kernel"
      add_finding(node)
    end
    proc { @call_node = nil }
  end
end

#visitFCallNode(node) ⇒ Object



17
18
19
# File 'lib/jruby/lint/checkers/fork_exec.rb', line 17

def visitFCallNode(node)
  add_finding(node) if fork_exec?(node)
end

#visitVCallNode(node) ⇒ Object



21
22
23
24
25
# File 'lib/jruby/lint/checkers/fork_exec.rb', line 21

def visitVCallNode(node)
  if fork_exec?(node)
    add_finding(node) unless @call_node
  end
end