class RuboCop::Cop::SketchupRequirements::GlobalVariables

Extensions in SketchUp all share the same Ruby environment on the user's machine. Because of this it's important that each extension isolate itself to avoid clashing with other extensions.

Extensions submitted to Extension Warehouse is expected to not define global variables.

This cops looks for uses of global variables. It does not report offenses for built-in global variables. Built-in global variables are allowed by default. Additionally users can allow additional variables via the AllowedVariables option.

Note that backreferences like `$1`, `$2`, etc are not global variables.

Constants

ALLOWED_VARS
BUILT_IN_VARS

predefined global variables their English aliases www.zenspider.com/Languages/Ruby/QuickRef.html

MSG
READ_ONLY_VARS

Some globals, like DC's, are being read from so often that it's better to ignore these to reduce noise.

SKETCHUP_VARS

Public Instance Methods

allowed_var?(global_var) click to toggle source
# File lib/rubocop/sketchup/cop/requirements/global_variables.rb, line 68
def allowed_var?(global_var)
  ALLOWED_VARS.include?(global_var)
end
check(node) click to toggle source
# File lib/rubocop/sketchup/cop/requirements/global_variables.rb, line 85
def check(node)
  global_var, = *node

  return if allowed_var?(global_var)

  add_offense(node, location: :name)
end
on_gvar(node) click to toggle source
# File lib/rubocop/sketchup/cop/requirements/global_variables.rb, line 76
def on_gvar(node)
  global_var, = *node
  check(node) unless read_allowed?(global_var)
end
on_gvasgn(node) click to toggle source
# File lib/rubocop/sketchup/cop/requirements/global_variables.rb, line 81
def on_gvasgn(node)
  check(node)
end
read_allowed?(global_var) click to toggle source
# File lib/rubocop/sketchup/cop/requirements/global_variables.rb, line 72
def read_allowed?(global_var)
  READ_ONLY_VARS.include?(global_var)
end