Class: RuboCop::Cop::SketchupSuggestions::ModelEntities

Inherits:
SketchUp::Cop
  • Object
show all
Defined in:
lib/rubocop/sketchup/cop/suggestions/model_entities.rb

Overview

Prefer ‘model.active_entities` over `model.entities`.

Most tools/actions act upon the active entities context. This could be an opened group or component instance. Because of this, prefer ‘model.active_entities` by default over `model.entities` unless you have an explicit reason to work in the root model context.

Constant Summary collapse

MSG =
'Prefer `model.active_entities` over `model.entities`.'
MODEL_VARIABLE_NAMES =
%w[model mod].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

#model_entities?(node) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/rubocop/sketchup/cop/suggestions/model_entities.rb', line 29

def model_entities?(node)
  return true if active_model_entities?(node)

  name = entities_receiver(node)
  name && model_variable?(name)
end

#on_send(node) ⇒ Object



36
37
38
# File 'lib/rubocop/sketchup/cop/suggestions/model_entities.rb', line 36

def on_send(node)
  add_offense(node, location: :expression) if model_entities?(node)
end