-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module SketchupSuggestions | ||
# Avoid kernel `sleep` as it freezes up SketchUp. | ||
# Prefer `UI.start_timer` or a callback from the resource you are waiting | ||
# for. | ||
class Sleep < SketchUp::Cop | ||
MSG = '`sleep` freezes up SketchUp. Prefer `UI.start_timer` or a ' \ | ||
'callback for the resource you are waiting for.' | ||
|
||
def_node_matcher :sleep?, <<-PATTERN | ||
(send {(const nil? :Kernel) nil?} :sleep ...) | ||
PATTERN | ||
|
||
def on_send(node) | ||
return unless sleep?(node) | ||
|
||
add_offense(node, message: MSG) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe RuboCop::Cop::SketchupSuggestions::Sleep do | ||
|
||
subject(:cop) { described_class.new } | ||
|
||
it 'registers an offense when using kernel `sleep`' do | ||
expect_offense(<<~RUBY) | ||
sleep | ||
^^^^^ `sleep` freezes up SketchUp. [...] | ||
RUBY | ||
end | ||
|
||
it 'registers an offense when using kernel `sleep(1)`' do | ||
expect_offense(<<~RUBY) | ||
sleep(1) | ||
^^^^^^^^ `sleep` freezes up SketchUp. [...] | ||
RUBY | ||
end | ||
|
||
it 'registers an offense when using kernel `sleep(0.5)`' do | ||
expect_offense(<<~RUBY) | ||
sleep(0.5) | ||
^^^^^^^^^^ `sleep` freezes up SketchUp. [...] | ||
RUBY | ||
end | ||
|
||
it 'registers an offense when using kernel `Kernel.sleep(0.5)`' do | ||
expect_offense(<<~RUBY) | ||
Kernel.sleep(0.5) | ||
^^^^^^^^^^^^^^^^^ `sleep` freezes up SketchUp. [...] | ||
RUBY | ||
end | ||
|
||
it 'does not registers an offense when using `SomeClass.sleep`' do | ||
expect_no_offenses(<<~RUBY) | ||
SomeClass.sleep | ||
RUBY | ||
end | ||
|
||
it 'does not registers an offense when using custom `object.sleep`' do | ||
expect_no_offenses(<<~RUBY) | ||
object.sleep | ||
RUBY | ||
end | ||
end |