Class: RuboCop::Cop::SketchupRequirements::RegisterExtension

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

Overview

Always register extensions to load by default. Otherwise it might confuse users to think the extension isn’t working.

Examples:

Good - Extension will load upon first run.

module Example
  unless file_loaded?(__FILE__)
    extension = SketchupExtension.new('Hello World', 'example/main')
    Sketchup.register_extension(extension, true)
    file_loaded(__FILE__)
  end
end

Constant Summary collapse

MSG =
'Always register extensions to load by default.'

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

#on_send(node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/sketchup/cop/requirements/register_extension.rb', line 29

def on_send(node)
  sketchup_register_extension(node).each { |args|
    if args.size < 2
      add_offense(node, location: :selector)
      next
    end
    load_arg = args[1]
    next if load_arg.true_type?

    add_offense(load_arg)
  }
end