Class: JRuby::Lint::Checkers::System
- Inherits:
-
Object
- Object
- JRuby::Lint::Checkers::System
- Includes:
- JRuby::Lint::Checker
- Defined in:
- lib/jruby/lint/checkers/system.rb
Instance Attribute Summary
Attributes included from JRuby::Lint::Checker
Instance Method Summary collapse
- #add_finding(node) ⇒ Object
-
#red_flag?(node) ⇒ Boolean
Defines red_flag when argument matches ruby.
- #ruby_executable?(node) ⇒ Boolean
-
#visitCallNode(node) ⇒ Object
Make sure to follow all Kernel.system calls.
-
#visitFCallNode(node) ⇒ Object
Visits the function calls for system.
Methods included from JRuby::Lint::Checker
Instance Method Details
#add_finding(node) ⇒ Object
22 23 24 25 |
# File 'lib/jruby/lint/checkers/system.rb', line 22 def add_finding(node) collector.findings << Finding.new("Calling Kernel.system('ruby ...') will get called in-process. Sometimes this works differently than expected", [:system, :warning], node.position) end |
#red_flag?(node) ⇒ Boolean
Defines red_flag when argument matches ruby
28 29 30 31 |
# File 'lib/jruby/lint/checkers/system.rb', line 28 def red_flag?(node) first_arg = node.args_node.child_nodes.first first_arg && first_arg.node_type.to_s == "STRNODE" && ruby_executable?(first_arg) end |
#ruby_executable?(node) ⇒ Boolean
33 34 35 36 |
# File 'lib/jruby/lint/checkers/system.rb', line 33 def ruby_executable?(node) match_on = Regexp.union([/.*ruby$/i, /.*j?irb$/i, /\.rb$/i]) node.value.split.first =~ match_on end |
#visitCallNode(node) ⇒ Object
Make sure to follow all Kernel.system calls
7 8 9 10 11 12 13 |
# File 'lib/jruby/lint/checkers/system.rb', line 7 def visitCallNode(node) if node.name == "system" || node.name == "`" @call_node = node add_finding(node) if red_flag?(node) proc { @call_node = nil } end end |
#visitFCallNode(node) ⇒ Object
Visits the function calls for system
16 17 18 19 20 |
# File 'lib/jruby/lint/checkers/system.rb', line 16 def visitFCallNode(node) if node.name == "system" add_finding(node) if red_flag?(node) end end |