Class: Rubocop::Cop::AvoidPerlisms

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

Constant Summary collapse

PREFERRED_VARS =
{
  '$:' => '$LOAD_PATH',
  '$"' => '$LOADED_FEATURES',
  '$0' => '$PROGRAM_NAME',
  '$!' => '$ERROR_INFO from English library',
  '$@' => '$ERROR_POSITION from English library',
  '$;' => '$FS or $FIELD_SEPARATOR from English library',
  '$,' => '$OFS or $OUTPUT_FIELD_SEPARATOR from English library',
  '$/' => '$RS or $INPUT_RECORD_SEPARATOR from English library',
  '$\\' => '$ORS or $OUTPUT_RECORD_SEPARATOR from English library',
  '$.' => '$NR or $INPUT_LINE_NUMBER from English library',
  '$_' => '$LAST_READ_LINE from English library',
  '$>' => '$DEFAULT_OUTPUT from English library',
  '$<' => '$DEFAULT_INPUT from English library',
  '$$' => '$PID or $PROCESS_ID from English library',
  '$?' => '$CHILD_STATUS from English library',
  '$~' => '$LAST_MATCH_INFO from English library',
  '$=' => '$IGNORECASE from English library',
  '$*' => '$ARGV from English library or ARGV constant',
  '$&' => '$MATCH from English library',
  '$`' => '$PREMATCH from English library',
  '$\'' => '$POSTMATCH from English library',
  '$+' => '$LAST_PAREN_MATCH from English library'
}

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, #ignore_node, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

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

Instance Method Details

#on_gvar(node) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubocop/cop/avoid_perlisms.rb', line 31

def on_gvar(node)
  global_var, = *node
  global_var = global_var.to_s

  if PREFERRED_VARS[global_var]
    add_offence(
      :convention,
      node.loc.line,
      "Prefer #{PREFERRED_VARS[global_var]} over #{global_var}."
    )
  end

  super
end