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

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

Constant Summary collapse

MSG =
'Do not modify the load path.'.freeze
LOAD_PATH_ALIASES =
%i(
  $: $LOAD_PATH
)
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
)

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)

56
57
58
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 56

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

#mutator?(sym) ⇒ Boolean

Returns:

  • (Boolean)

60
61
62
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 60

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

#on_gvasgn(node) ⇒ Object


64
65
66
67
68
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 64

def on_gvasgn(node)
  global_var, = *node

  add_offense(node, location: :name, severity: :error) if load_path?(global_var)
end

#on_send(node) ⇒ Object


70
71
72
73
74
75
# File 'lib/rubocop/sketchup/cop/requirements/load_path.rb', line 70

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

  add_offense(node, location: :expression, severity: :error)
end