Class: Rubocop::Cop::Eval

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/eval.rb

Constant Summary collapse

ERROR_MESSAGE =
'The use of eval is a serious security risk.'

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #name

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#inspect(file, source, tokens, sexp) ⇒ Object



8
9
10
11
# File 'lib/rubocop/cop/eval.rb', line 8

def inspect(file, source, tokens, sexp)
  each(:command, sexp) { |s| process_ident(s[1]) }
  each(:fcall, sexp) { |s| process_ident(s[1]) }
end

#process_ident(sexp) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rubocop/cop/eval.rb', line 13

def process_ident(sexp)
  if sexp[0] == :@ident && sexp[1] == 'eval'
    add_offence(:security,
                sexp[2].lineno,
                ERROR_MESSAGE)
  end
end