Class: RuboCop::Cop::SketchupSuggestions::ToolbarTimer

Inherits:
RuboCop::Cop show all
Includes:
RangeHelp
Defined in:
lib/rubocop/sketchup/cop/suggestions/toolbar_timer.rb

Overview

Wrapping ‘toolbar.restore` in `UI.start_timer` is redundant. It was a workaround for an issue in a very old version of SketchUp. There is no need to still be using this workaround.

Examples:

Creating a new toolbar

# bad
toolbar = UI::Toolbar.new('Example')
# ...
toolbar.restore
UI.start_timer(0.1, false) {
  toolbar.restore
}

# good
toolbar = UI::Toolbar.new('Example')
# ...
toolbar.restore

Constant Summary collapse

MSG =
'Wrapping `toolbar.restore` in `UI.start_timer` is '\
'redundant.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubocop/sketchup/cop/suggestions/toolbar_timer.rb', line 45

def on_send(node)
  return unless toolbar_new?(node)
  return unless node.parent.assignment?

  assignment_node = node.parent
  toolbar_variable_name = assignment_node.children.first

  receiver = ui_start_timer_restore(assignment_node.parent).first
  return unless receiver&.variable?

  receiver_variable_name = receiver.children.first

  return unless receiver_variable_name == toolbar_variable_name

  add_offense(receiver.parent)
end