class RuboCop::Cop::SketchupRequirements::MinimalRegistration
Don't load extension files in the root file registering the extension. Extensions should not load additional files when it's disabled.
@example Bad - Extension will always load.
module Example require 'example/main' # BAD! This will load even when extension # is disabled. unless file_loaded?(__FILE__) extension = SketchupExtension.new('Hello World', 'example/main') Sketchup.register_extension(extension, true) file_loaded(__FILE__) end end
@example Good - Extension doesn't load anything unless its enabled.
module Example unless file_loaded?(__FILE__) extension = SketchupExtension.new('Hello World', 'example/main') Sketchup.register_extension(extension, true) file_loaded(__FILE__) end end
Constants
- MSG
Public Instance Methods
extension_file?(filename)
click to toggle source
# File lib/rubocop/sketchup/cop/requirements/minimal_registration.rb, line 53 def extension_file?(filename) return false unless filename.include?('/') first_directory = filename.split('/').first @extension_basename.casecmp(first_directory) == 0 end
investigate(processed_source)
click to toggle source
# File lib/rubocop/sketchup/cop/requirements/minimal_registration.rb, line 46 def investigate(processed_source) if root_file?(processed_source) filename = processed_source.buffer.name @extension_basename = File.basename(filename, '.*') end end
on_send(node)
click to toggle source
# File lib/rubocop/sketchup/cop/requirements/minimal_registration.rb, line 60 def on_send(node) return unless @extension_basename filename = require_filename(node) return if filename.nil? return unless extension_file?(filename) add_offense(node) end