Class: RuboCop::Cop::Isucon::Shell::Backtick

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

Overview

Avoid external command calls with backtick

Examples:

# bad
def digest(src)
  `printf "%s" #{Shellwords.shellescape(src)} | openssl dgst -sha512 | sed 's/^.*= //'`.strip
end

# bad
def digest(src)
  %x(printf "%s" \#{Shellwords.shellescape(src)} | openssl dgst -sha512 | sed 's/^.*= //').strip
end

# good
def digest(src)
  OpenSSL::Digest::SHA512.hexdigest(src)
end

# bad
`curl -s https://example.com`

# good
require "open-uri"
URI.open("https://example.com").read

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#on_xstr(node) ⇒ Object

Parameters:

  • node (RuboCop::AST::Node)


36
37
38
# File 'lib/rubocop/cop/isucon/shell/backtick.rb', line 36

def on_xstr(node)
  add_offense(node)
end