Class: RuboCop::Cop::SketchupRequirements::MinimalRegistration

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

Overview

Don't load extension files in the root file registering the extension. Extensions should not load additional files when it's disabled.

Constant Summary collapse

MSG =
"Don't load extension files in the root file registering the extension.".freeze

Constants included from SketchUp::Config

SketchUp::Config::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Methods included from SketchUp::ExtensionProject

#config_path, #path_relative_to_source, #relative_source_path, #root_file?, #source_path

Methods inherited from SketchUp::Cop

inherited, #relevant_file?

Instance Method Details

#extension_file?(filename) ⇒ Boolean


32
33
34
35
36
# File 'lib/rubocop/sketchup/cop/requirements/minimal_registration.rb', line 32

def extension_file?(filename)
  return false unless filename.include?('/')
  first_directory = filename.split('/').first
  @extension_basename.casecmp(first_directory) == 0
end

#investigate(processed_source) ⇒ Object


25
26
27
28
29
30
# File 'lib/rubocop/sketchup/cop/requirements/minimal_registration.rb', line 25

def investigate(processed_source)
  if root_file?(processed_source)
    filename = processed_source.buffer.name
    @extension_basename = File.basename(filename, '.*')
  end
end

#on_send(node) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/rubocop/sketchup/cop/requirements/minimal_registration.rb', line 38

def on_send(node)
  return unless @extension_basename
  filename = require_filename(node)
  return if filename.nil?
  return unless extension_file?(filename)
  add_offense(node, severity: :error)
end