Class: Rubocop::Cop::AvoidGlobalVars
- Defined in:
- lib/rubocop/cop/avoid_global_vars.rb
Constant Summary collapse
- ERROR_MESSAGE =
'Do not introduce global variables.'
- BUILT_IN_VARS =
predefined global variables their English aliases www.zenspider.com/Languages/Ruby/QuickRef.html
%w( $: $LOAD_PATH $" $LOADED_FEATURES $0 $PROGRAM_NAME $! $ERROR_INFO $@ $ERROR_POSITION $; $FS $FIELD_SEPARATOR $, $OFS $OUTPUT_FIELD_SEPARATOR $/ $RS $INPUT_RECORD_SEPARATOR $\\ $ORS $OUTPUT_RECORD_SEPARATOR $. $NR $INPUT_LINE_NUMBER $_ $LAST_READ_LINE $> $DEFAULT_OUTPUT $< $DEFAULT_INPUT $$ $PID $PROCESS_ID $? $CHILD_STATUS $~ $LAST_MATCH_INFO $= $IGNORECASE $* $ARGV $& $MATCH $` $PREMATCH $' $POSTMATCH $+ $LAST_PAREN_MATCH $stdin $stdout $stderr $DEBUG $FILENAME $VERBOSE $-0 $-a $-d $-F $-i $-I $-l $-p $-v $-w )
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
38 39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/cop/avoid_global_vars.rb', line 38 def inspect(file, source, tokens, sexp) each(:@gvar, sexp) do |s| global_var = s[1] unless BUILT_IN_VARS.include?(global_var) add_offence(:convention, s[2].lineno, ERROR_MESSAGE) end end end |