Class: RuboCop::Cop::Isucon::Shell::System

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/isucon/shell/system.rb

Overview

Avoid external command calls with Kernel#system

Examples:

# bad
system("sleep 1")

# good
sleep 1

Constant Summary collapse

MSG =
"Use pure-ruby code instead of external command execution if possible"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

Parameters:

  • node (RuboCop::AST::Node)


27
28
29
30
31
# File 'lib/rubocop/cop/isucon/shell/system.rb', line 27

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

  add_offense(node)
end

#system?(node) ⇒ Boolean

Whether matches system

Returns:

  • (Boolean)


22
23
24
# File 'lib/rubocop/cop/isucon/shell/system.rb', line 22

def_node_matcher :system?, <<~PATTERN
  (send nil? :system ...)
PATTERN