Class: RuboCop::Cop::SketchupRequirements::LoadPath

Inherits:
SketchUp::Cop show all
Includes:
SketchUp::NoCommentDisable
Defined in:
lib/rubocop/sketchup/cop/requirements/load_path.rb

Overview

Do not modify the load path. Modifying ‘$LOAD_PATH` is bad practice because it can cause extensions to inadvertently load the wrong file.

Constant Summary collapse

MSG =
'Do not modify the load path.'
LOAD_PATH_ALIASES =
%i[
  $: $LOAD_PATH
].freeze
MUTATORS =
%i[
  <<
  []=
  clear
  collect!
  compact!
  concat
  delete
  delete_at
  delete_if
  drop
  drop_while
  fill
  flatten!
  insert
  keep_if
  map!
  pop
  push
  reject!
  replace
  reverse!
  rotate!
  select!
  shift
  shuffle!
  slice!
  sort!
  sort_by!
  uniq!
  unshift
].freeze

Constants inherited from SketchUp::Cop

SketchUp::Cop::SKETCHUP_DEPARTMENT_SEVERITY

Constants included from SketchUp::Config

SketchUp::Config::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Methods inherited from SketchUp::Cop

inherited, #relevant_file?

Instance Method Details

#load_path?(sym) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 58

def load_path?(sym)
  LOAD_PATH_ALIASES.include?(sym)
end

#mutator?(sym) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 62

def mutator?(sym)
  MUTATORS.include?(sym)
end

#on_gvasgn(node) ⇒ Object



66
67
68
69
70
71
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 66

def on_gvasgn(node)
  global_var, = *node
  return unless load_path?(global_var)

  add_offense(node, location: :expression)
end

#on_send(node) ⇒ Object



73
74
75
76
77
78
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 73

def on_send(node)
  method_name = load_path_mutator?(node)
  return unless method_name

  add_offense(node, location: :expression)
end