Class: RuboCop::Cop::SketchupRequirements::GlobalMethods
- Inherits:
-
SketchUp::Cop
- Object
- SketchUp::WorkaroundCop
- SketchUp::Cop
- RuboCop::Cop::SketchupRequirements::GlobalMethods
- Includes:
- SketchUp, SketchUp::NoCommentDisable
- Defined in:
- lib/rubocop/sketchup/cop/requirements/global_methods.rb
Overview
Extensions in SketchUp all share the same Ruby environment on the user’s machine. Because of this it’s important that each extension isolate itself to avoid clashing with other extensions.
Extensions submitted to Extension Warehouse is expected to not define global methods.
Constant Summary collapse
- MSG =
'Do not introduce global methods.'
Constants included from SketchUp
SketchUp::CONFIG, SketchUp::VERSION
Constants inherited from SketchUp::Cop
SketchUp::Cop::SKETCHUP_DEPARTMENT_SEVERITY
Constants included from SketchUp::Config
SketchUp::Config::DEFAULT_CONFIGURATION
Instance Method Summary collapse
- #on_def(node) ⇒ Object (also: #on_defs)
Methods inherited from SketchUp::Cop
Instance Method Details
#on_def(node) ⇒ Object Also known as: on_defs
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubocop/sketchup/cop/requirements/global_methods.rb', line 45 def on_def(node) if class_method?(node) class_method_parent = class_method(node) namespace = Namespace.new(class_method_parent.to_s) else # If a method is defined inside a block then parent_module_name # will return nil. return if node.parent_module_name.nil? namespace = Namespace.new(node.parent_module_name) end return unless namespace.top_level? add_offense(node, location: :name) end |