rubocop-sketchup 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +19 -19
  3. data/assets/output.html.erb +301 -301
  4. data/config/default.yml +355 -355
  5. data/lib/rubocop/sketchup/config.rb +63 -63
  6. data/lib/rubocop/sketchup/cop/deprecations/add_separator_to_menu.rb +25 -25
  7. data/lib/rubocop/sketchup/cop/deprecations/operation_next_transparent.rb +30 -30
  8. data/lib/rubocop/sketchup/cop/deprecations/require_all.rb +27 -27
  9. data/lib/rubocop/sketchup/cop/deprecations/set_texture_projection.rb +26 -26
  10. data/lib/rubocop/sketchup/cop/deprecations/show_ruby_panel.rb +25 -25
  11. data/lib/rubocop/sketchup/cop/deprecations/sketchup_set.rb +30 -30
  12. data/lib/rubocop/sketchup/cop/performance/openssl.rb +41 -41
  13. data/lib/rubocop/sketchup/cop/performance/operation_disable_ui.rb +33 -33
  14. data/lib/rubocop/sketchup/cop/performance/selection_bulk.rb +79 -79
  15. data/lib/rubocop/sketchup/cop/performance/type_check.rb +63 -63
  16. data/lib/rubocop/sketchup/cop/performance/typename.rb +24 -24
  17. data/lib/rubocop/sketchup/cop/requirements/api_namespace.rb +30 -30
  18. data/lib/rubocop/sketchup/cop/requirements/exit.rb +32 -32
  19. data/lib/rubocop/sketchup/cop/requirements/extension_namespace.rb +108 -108
  20. data/lib/rubocop/sketchup/cop/requirements/file_structure.rb +97 -97
  21. data/lib/rubocop/sketchup/cop/requirements/gem_install.rb +45 -45
  22. data/lib/rubocop/sketchup/cop/requirements/get_extension_license.rb +95 -95
  23. data/lib/rubocop/sketchup/cop/requirements/global_constants.rb +38 -38
  24. data/lib/rubocop/sketchup/cop/requirements/global_include.rb +42 -42
  25. data/lib/rubocop/sketchup/cop/requirements/global_methods.rb +65 -65
  26. data/lib/rubocop/sketchup/cop/requirements/global_variables.rb +95 -95
  27. data/lib/rubocop/sketchup/cop/requirements/language_handler_globals.rb +46 -46
  28. data/lib/rubocop/sketchup/cop/requirements/load_path.rb +83 -83
  29. data/lib/rubocop/sketchup/cop/requirements/minimal_registration.rb +73 -73
  30. data/lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb +161 -161
  31. data/lib/rubocop/sketchup/cop/requirements/register_extension.rb +45 -45
  32. data/lib/rubocop/sketchup/cop/requirements/ruby_core_namespace.rb +291 -291
  33. data/lib/rubocop/sketchup/cop/requirements/ruby_stdlib_namespace.rb +634 -634
  34. data/lib/rubocop/sketchup/cop/requirements/shipped_extensions_namespace.rb +61 -61
  35. data/lib/rubocop/sketchup/cop/requirements/sketchup_extension.rb +119 -119
  36. data/lib/rubocop/sketchup/cop/requirements/sketchup_require.rb +163 -163
  37. data/lib/rubocop/sketchup/cop/suggestions/add_group.rb +49 -49
  38. data/lib/rubocop/sketchup/cop/suggestions/compatibility.rb +117 -117
  39. data/lib/rubocop/sketchup/cop/suggestions/dc_internals.rb +34 -34
  40. data/lib/rubocop/sketchup/cop/suggestions/file_encoding.rb +78 -78
  41. data/lib/rubocop/sketchup/cop/suggestions/model_entities.rb +58 -58
  42. data/lib/rubocop/sketchup/cop/suggestions/monkey_patched_api.rb +45 -45
  43. data/lib/rubocop/sketchup/cop/suggestions/operation_name.rb +103 -103
  44. data/lib/rubocop/sketchup/cop/suggestions/sketchup_find_support_file.rb +39 -39
  45. data/lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb +44 -44
  46. data/lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb +66 -66
  47. data/lib/rubocop/sketchup/cop/suggestions/tool_user_input.rb +41 -41
  48. data/lib/rubocop/sketchup/cop/suggestions/toolbar_timer.rb +65 -65
  49. data/lib/rubocop/sketchup/cop.rb +111 -111
  50. data/lib/rubocop/sketchup/dc_globals.rb +24 -24
  51. data/lib/rubocop/sketchup/dc_methods.rb +130 -130
  52. data/lib/rubocop/sketchup/extension_project.rb +65 -65
  53. data/lib/rubocop/sketchup/features.rb +738 -738
  54. data/lib/rubocop/sketchup/formatter/extension_review.rb +259 -259
  55. data/lib/rubocop/sketchup/inject.rb +19 -19
  56. data/lib/rubocop/sketchup/namespace.rb +47 -47
  57. data/lib/rubocop/sketchup/namespace_checker.rb +46 -46
  58. data/lib/rubocop/sketchup/no_comment_disable.rb +17 -17
  59. data/lib/rubocop/sketchup/range_help.rb +52 -52
  60. data/lib/rubocop/sketchup/sketchup_version.rb +87 -87
  61. data/lib/rubocop/sketchup/tool_checker.rb +43 -43
  62. data/lib/rubocop/sketchup/version.rb +5 -5
  63. data/lib/rubocop/sketchup.rb +12 -12
  64. data/lib/rubocop-sketchup.rb +48 -48
  65. data/rubocop-sketchup.gemspec +27 -27
  66. metadata +4 -4
@@ -1,39 +1,39 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupSuggestions
6
- # Avoid `Sketchup.find_support_file` to find your extension's files.
7
- #
8
- # Users might install your extension to locations other than the default
9
- # Plugins directory. If you use `Sketchup.find_support_file` to build
10
- # a path for files in your extension it will fail in these scenarios.
11
- #
12
- # Instead prefer to use `__FILE__` or `__dir__` to build paths relative
13
- # to your source files. This have the added benefit of allowing you to
14
- # load your extensions directly from external directories under version
15
- # control.
16
- class SketchupFindSupportFile < SketchUp::Cop
17
-
18
- MSG = 'Avoid `Sketchup.find_support_file` to find your '\
19
- "extension's files.".freeze
20
-
21
- # http://www.rubydoc.info/gems/rubocop/RuboCop/NodePattern
22
- # https://rubocop.readthedocs.io/en/latest/node_pattern/
23
- def_node_matcher :sketchup_find_support_file?, <<-PATTERN
24
- (send
25
- (const nil? :Sketchup) :find_support_file
26
- ...
27
- )
28
- PATTERN
29
-
30
- def on_send(node)
31
- return unless sketchup_find_support_file?(node)
32
-
33
- add_offense(node, location: :expression)
34
- end
35
-
36
- end
37
- end
38
- end
39
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupSuggestions
6
+ # Avoid `Sketchup.find_support_file` to find your extension's files.
7
+ #
8
+ # Users might install your extension to locations other than the default
9
+ # Plugins directory. If you use `Sketchup.find_support_file` to build
10
+ # a path for files in your extension it will fail in these scenarios.
11
+ #
12
+ # Instead prefer to use `__FILE__` or `__dir__` to build paths relative
13
+ # to your source files. This have the added benefit of allowing you to
14
+ # load your extensions directly from external directories under version
15
+ # control.
16
+ class SketchupFindSupportFile < SketchUp::Cop
17
+
18
+ MSG = 'Avoid `Sketchup.find_support_file` to find your '\
19
+ "extension's files.".freeze
20
+
21
+ # http://www.rubydoc.info/gems/rubocop/RuboCop/NodePattern
22
+ # https://rubocop.readthedocs.io/en/latest/node_pattern/
23
+ def_node_matcher :sketchup_find_support_file?, <<-PATTERN
24
+ (send
25
+ (const nil? :Sketchup) :find_support_file
26
+ ...
27
+ )
28
+ PATTERN
29
+
30
+ def on_send(node)
31
+ return unless sketchup_find_support_file?(node)
32
+
33
+ add_offense(node, location: :expression)
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,44 +1,44 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupSuggestions
6
- # When drawing 3D geometry to the viewport from a tool, make sure to
7
- # implement `getExtents` that return a `Geom::BoundingBox` object large
8
- # enough to encompass what you draw.
9
- #
10
- # With out doing that the drawn content might end up being clipped.
11
- #
12
- # @example
13
- # # good
14
- # class ExampleTool
15
- #
16
- # def getExtents
17
- # bounds = Geom::BoundingBox.new
18
- # bounds.add(@points)
19
- # bounds
20
- # end
21
- #
22
- # def draw(view)
23
- # view.draw(GL_LINES, @points)
24
- # end
25
- #
26
- # end
27
- class ToolDrawingBounds < Cop
28
-
29
- include SketchUp::ToolChecker
30
-
31
- MSG_MISSING_GET_EXTENTS = 'When drawing to the viewport implement '\
32
- '`getExtents` so drawn geometry is not clipped.'.freeze
33
-
34
- def on_tool_class(class_node, body_methods)
35
- return unless find_method(body_methods, :draw)
36
- return if find_method(body_methods, :getExtents)
37
-
38
- add_offense(class_node, message: MSG_MISSING_GET_EXTENTS)
39
- end
40
-
41
- end
42
- end
43
- end
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupSuggestions
6
+ # When drawing 3D geometry to the viewport from a tool, make sure to
7
+ # implement `getExtents` that return a `Geom::BoundingBox` object large
8
+ # enough to encompass what you draw.
9
+ #
10
+ # With out doing that the drawn content might end up being clipped.
11
+ #
12
+ # @example
13
+ # # good
14
+ # class ExampleTool
15
+ #
16
+ # def getExtents
17
+ # bounds = Geom::BoundingBox.new
18
+ # bounds.add(@points)
19
+ # bounds
20
+ # end
21
+ #
22
+ # def draw(view)
23
+ # view.draw(GL_LINES, @points)
24
+ # end
25
+ #
26
+ # end
27
+ class ToolDrawingBounds < Cop
28
+
29
+ include SketchUp::ToolChecker
30
+
31
+ MSG_MISSING_GET_EXTENTS = 'When drawing to the viewport implement '\
32
+ '`getExtents` so drawn geometry is not clipped.'.freeze
33
+
34
+ def on_tool_class(class_node, body_methods)
35
+ return unless find_method(body_methods, :draw)
36
+ return if find_method(body_methods, :getExtents)
37
+
38
+ add_offense(class_node, message: MSG_MISSING_GET_EXTENTS)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,66 +1,66 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupSuggestions
6
- # After having drawn to the viewport from a tool, make sure to invalidate
7
- # the view on `deactivate` and `suspend`.
8
- #
9
- # If you don't do that the things you drew might stick around for longer
10
- # than the life-span of the tool and cause confusion for the user.
11
- #
12
- # @example
13
- # # good
14
- # class ExampleTool
15
- #
16
- # def deactivate(view)
17
- # view_invalidate
18
- # end
19
- #
20
- # def suspend(view)
21
- # view_invalidate
22
- # end
23
- #
24
- # def draw(view)
25
- # view.draw(GL_LINES, @points)
26
- # end
27
- #
28
- # end
29
- class ToolInvalidate < Cop
30
-
31
- include SketchUp::ToolChecker
32
-
33
- MSG_MISSING_INVALIDATE_METHOD = 'When drawing to the viewport, make '\
34
- 'sure to `suspend` and `deactivate` calls `view.invalidate`.'.freeze
35
-
36
- MSG_MISSING_INVALIDATE = 'When drawing to the viewport, make sure to '\
37
- 'call `view.invalidate` when the tool becomes inactive.'.freeze
38
-
39
- def_node_search :view_invalidate?, <<-PATTERN
40
- (send (lvar :view) :invalidate ...)
41
- PATTERN
42
-
43
- def on_tool_class(class_node, body_methods)
44
- return unless find_method(body_methods, :draw)
45
-
46
- check_method_invalidate(:deactivate, body_methods, class_node)
47
- check_method_invalidate(:suspend, body_methods, class_node)
48
- end
49
-
50
- private
51
-
52
- def check_method_invalidate(method_name, body_methods, class_node)
53
- method_node = find_method(body_methods, method_name)
54
- if method_node
55
- return if view_invalidate?(method_node)
56
-
57
- add_offense(method_node, message: MSG_MISSING_INVALIDATE)
58
- else
59
- add_offense(class_node, message: MSG_MISSING_INVALIDATE_METHOD)
60
- end
61
- end
62
-
63
- end
64
- end
65
- end
66
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupSuggestions
6
+ # After having drawn to the viewport from a tool, make sure to invalidate
7
+ # the view on `deactivate` and `suspend`.
8
+ #
9
+ # If you don't do that the things you drew might stick around for longer
10
+ # than the life-span of the tool and cause confusion for the user.
11
+ #
12
+ # @example
13
+ # # good
14
+ # class ExampleTool
15
+ #
16
+ # def deactivate(view)
17
+ # view_invalidate
18
+ # end
19
+ #
20
+ # def suspend(view)
21
+ # view_invalidate
22
+ # end
23
+ #
24
+ # def draw(view)
25
+ # view.draw(GL_LINES, @points)
26
+ # end
27
+ #
28
+ # end
29
+ class ToolInvalidate < Cop
30
+
31
+ include SketchUp::ToolChecker
32
+
33
+ MSG_MISSING_INVALIDATE_METHOD = 'When drawing to the viewport, make '\
34
+ 'sure to `suspend` and `deactivate` calls `view.invalidate`.'.freeze
35
+
36
+ MSG_MISSING_INVALIDATE = 'When drawing to the viewport, make sure to '\
37
+ 'call `view.invalidate` when the tool becomes inactive.'.freeze
38
+
39
+ def_node_search :view_invalidate?, <<-PATTERN
40
+ (send (lvar :view) :invalidate ...)
41
+ PATTERN
42
+
43
+ def on_tool_class(class_node, body_methods)
44
+ return unless find_method(body_methods, :draw)
45
+
46
+ check_method_invalidate(:deactivate, body_methods, class_node)
47
+ check_method_invalidate(:suspend, body_methods, class_node)
48
+ end
49
+
50
+ private
51
+
52
+ def check_method_invalidate(method_name, body_methods, class_node)
53
+ method_node = find_method(body_methods, method_name)
54
+ if method_node
55
+ return if view_invalidate?(method_node)
56
+
57
+ add_offense(method_node, message: MSG_MISSING_INVALIDATE)
58
+ else
59
+ add_offense(class_node, message: MSG_MISSING_INVALIDATE_METHOD)
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,41 +1,41 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupSuggestions
6
- # When a tool takes user input via `onUserText`, make sure to define
7
- # `enableVCB?` so that the VCB is enabled.
8
- #
9
- # @example
10
- # # good
11
- # class ExampleTool
12
- #
13
- # def enableVCB?
14
- # true
15
- # end
16
- #
17
- # def onUserText(text, view)
18
- # # ...
19
- # end
20
- #
21
- # end
22
- class ToolUserInput < Cop
23
-
24
- include SketchUp::ToolChecker
25
-
26
- MSG_MISSING_ENABLE_VCB = 'When accepting user input, make sure to '\
27
- 'define `enableVCB?`.'.freeze
28
-
29
- def on_tool_class(class_node, body_methods)
30
- return unless find_method(body_methods, :onUserText)
31
-
32
- method_node = find_method(body_methods, :enableVCB?)
33
- return if method_node
34
-
35
- add_offense(class_node, message: MSG_MISSING_ENABLE_VCB)
36
- end
37
-
38
- end
39
- end
40
- end
41
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupSuggestions
6
+ # When a tool takes user input via `onUserText`, make sure to define
7
+ # `enableVCB?` so that the VCB is enabled.
8
+ #
9
+ # @example
10
+ # # good
11
+ # class ExampleTool
12
+ #
13
+ # def enableVCB?
14
+ # true
15
+ # end
16
+ #
17
+ # def onUserText(text, view)
18
+ # # ...
19
+ # end
20
+ #
21
+ # end
22
+ class ToolUserInput < Cop
23
+
24
+ include SketchUp::ToolChecker
25
+
26
+ MSG_MISSING_ENABLE_VCB = 'When accepting user input, make sure to '\
27
+ 'define `enableVCB?`.'.freeze
28
+
29
+ def on_tool_class(class_node, body_methods)
30
+ return unless find_method(body_methods, :onUserText)
31
+
32
+ method_node = find_method(body_methods, :enableVCB?)
33
+ return if method_node
34
+
35
+ add_offense(class_node, message: MSG_MISSING_ENABLE_VCB)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,65 +1,65 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupSuggestions
6
- # Wrapping `toolbar.restore` in `UI.start_timer` is redundant. It was a
7
- # workaround for an issue in a very old version of SketchUp. There is no
8
- # need to still be using this workaround.
9
- #
10
- # @example Creating a new toolbar
11
- # # bad
12
- # toolbar = UI::Toolbar.new('Example')
13
- # # ...
14
- # toolbar.restore
15
- # UI.start_timer(0.1, false) {
16
- # toolbar.restore
17
- # }
18
- #
19
- # # good
20
- # toolbar = UI::Toolbar.new('Example')
21
- # # ...
22
- # toolbar.restore
23
- class ToolbarTimer < Cop
24
-
25
- include RangeHelp
26
-
27
- MSG = 'Wrapping `toolbar.restore` in `UI.start_timer` is '\
28
- 'redundant.'.freeze
29
-
30
- def_node_matcher :toolbar_new?, <<-PATTERN
31
- (send (const (const nil? :UI) :Toolbar) :new _)
32
- PATTERN
33
-
34
- def_node_search :ui_start_timer_restore, <<-PATTERN
35
- (block
36
- (send
37
- (const nil? :UI) :start_timer
38
- (float _)
39
- (false))
40
- (args)
41
- (send
42
- $_ :restore))
43
- PATTERN
44
-
45
- def on_send(node)
46
- return unless toolbar_new?(node)
47
- return unless node.parent.assignment?
48
-
49
- assignment_node = node.parent
50
- toolbar_variable_name = assignment_node.children.first
51
-
52
- receiver = ui_start_timer_restore(assignment_node.parent).first
53
- return unless receiver && receiver.variable?
54
-
55
- receiver_variable_name = receiver.children.first
56
-
57
- return unless receiver_variable_name == toolbar_variable_name
58
-
59
- add_offense(receiver.parent)
60
- end
61
-
62
- end
63
- end
64
- end
65
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupSuggestions
6
+ # Wrapping `toolbar.restore` in `UI.start_timer` is redundant. It was a
7
+ # workaround for an issue in a very old version of SketchUp. There is no
8
+ # need to still be using this workaround.
9
+ #
10
+ # @example Creating a new toolbar
11
+ # # bad
12
+ # toolbar = UI::Toolbar.new('Example')
13
+ # # ...
14
+ # toolbar.restore
15
+ # UI.start_timer(0.1, false) {
16
+ # toolbar.restore
17
+ # }
18
+ #
19
+ # # good
20
+ # toolbar = UI::Toolbar.new('Example')
21
+ # # ...
22
+ # toolbar.restore
23
+ class ToolbarTimer < Cop
24
+
25
+ include RangeHelp
26
+
27
+ MSG = 'Wrapping `toolbar.restore` in `UI.start_timer` is '\
28
+ 'redundant.'.freeze
29
+
30
+ def_node_matcher :toolbar_new?, <<-PATTERN
31
+ (send (const (const nil? :UI) :Toolbar) :new _)
32
+ PATTERN
33
+
34
+ def_node_search :ui_start_timer_restore, <<-PATTERN
35
+ (block
36
+ (send
37
+ (const nil? :UI) :start_timer
38
+ (float _)
39
+ (false))
40
+ (args)
41
+ (send
42
+ $_ :restore))
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ return unless toolbar_new?(node)
47
+ return unless node.parent.assignment?
48
+
49
+ assignment_node = node.parent
50
+ toolbar_variable_name = assignment_node.children.first
51
+
52
+ receiver = ui_start_timer_restore(assignment_node.parent).first
53
+ return unless receiver && receiver.variable?
54
+
55
+ receiver_variable_name = receiver.children.first
56
+
57
+ return unless receiver_variable_name == toolbar_variable_name
58
+
59
+ add_offense(receiver.parent)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end