Class: RuboCop::Cop::SketchupSuggestions::ToolUserInput

Inherits:
RuboCop::Cop show all
Includes:
SketchUp::ToolChecker
Defined in:
lib/rubocop/sketchup/cop/suggestions/tool_user_input.rb

Overview

When a tool takes user input via ‘onUserText`, make sure to define `enableVCB?` so that the VCB is enabled.

Examples:

# good
class ExampleTool

  def enableVCB?
    true
  end

  def onUserText(text, view)
    # ...
  end

end

Constant Summary collapse

MSG_MISSING_ENABLE_VCB =
'When accepting user input, make sure to '\
'define `enableVCB?`.'

Instance Method Summary collapse

Methods included from SketchUp::ToolChecker

#on_class

Instance Method Details

#on_tool_class(class_node, body_methods) ⇒ Object



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

def on_tool_class(class_node, body_methods)
  return unless find_method(body_methods, :onUserText)

  method_node = find_method(body_methods, :enableVCB?)
  return if method_node

  add_offense(class_node, message: MSG_MISSING_ENABLE_VCB)
end