rubocop-sketchup 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +20 -19
  3. data/assets/output.html.erb +301 -301
  4. data/config/default.yml +379 -355
  5. data/lib/rubocop-sketchup.rb +49 -48
  6. data/lib/rubocop/sketchup.rb +12 -12
  7. data/lib/rubocop/sketchup/config.rb +63 -63
  8. data/lib/rubocop/sketchup/cop.rb +111 -111
  9. data/lib/rubocop/sketchup/cop/bugs/material_name.rb +108 -0
  10. data/lib/rubocop/sketchup/cop/bugs/render_mode.rb +72 -0
  11. data/lib/rubocop/sketchup/cop/bugs/uniform_scaling.rb +36 -0
  12. data/lib/rubocop/sketchup/cop/deprecations/add_separator_to_menu.rb +25 -25
  13. data/lib/rubocop/sketchup/cop/deprecations/operation_next_transparent.rb +30 -30
  14. data/lib/rubocop/sketchup/cop/deprecations/require_all.rb +27 -27
  15. data/lib/rubocop/sketchup/cop/deprecations/set_texture_projection.rb +26 -26
  16. data/lib/rubocop/sketchup/cop/deprecations/show_ruby_panel.rb +25 -25
  17. data/lib/rubocop/sketchup/cop/deprecations/sketchup_set.rb +30 -30
  18. data/lib/rubocop/sketchup/cop/performance/openssl.rb +41 -41
  19. data/lib/rubocop/sketchup/cop/performance/operation_disable_ui.rb +33 -33
  20. data/lib/rubocop/sketchup/cop/performance/selection_bulk.rb +79 -79
  21. data/lib/rubocop/sketchup/cop/performance/type_check.rb +63 -63
  22. data/lib/rubocop/sketchup/cop/performance/typename.rb +24 -24
  23. data/lib/rubocop/sketchup/cop/requirements/api_namespace.rb +30 -30
  24. data/lib/rubocop/sketchup/cop/requirements/exit.rb +32 -32
  25. data/lib/rubocop/sketchup/cop/requirements/extension_namespace.rb +108 -108
  26. data/lib/rubocop/sketchup/cop/requirements/file_structure.rb +97 -97
  27. data/lib/rubocop/sketchup/cop/requirements/gem_install.rb +45 -45
  28. data/lib/rubocop/sketchup/cop/requirements/get_extension_license.rb +95 -95
  29. data/lib/rubocop/sketchup/cop/requirements/global_constants.rb +38 -38
  30. data/lib/rubocop/sketchup/cop/requirements/global_include.rb +42 -42
  31. data/lib/rubocop/sketchup/cop/requirements/global_methods.rb +65 -65
  32. data/lib/rubocop/sketchup/cop/requirements/global_variables.rb +95 -95
  33. data/lib/rubocop/sketchup/cop/requirements/language_handler_globals.rb +46 -46
  34. data/lib/rubocop/sketchup/cop/requirements/load_path.rb +83 -83
  35. data/lib/rubocop/sketchup/cop/requirements/minimal_registration.rb +73 -73
  36. data/lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb +161 -161
  37. data/lib/rubocop/sketchup/cop/requirements/register_extension.rb +45 -45
  38. data/lib/rubocop/sketchup/cop/requirements/ruby_core_namespace.rb +291 -291
  39. data/lib/rubocop/sketchup/cop/requirements/ruby_stdlib_namespace.rb +634 -634
  40. data/lib/rubocop/sketchup/cop/requirements/shipped_extensions_namespace.rb +61 -61
  41. data/lib/rubocop/sketchup/cop/requirements/sketchup_extension.rb +119 -119
  42. data/lib/rubocop/sketchup/cop/requirements/sketchup_require.rb +163 -163
  43. data/lib/rubocop/sketchup/cop/suggestions/add_group.rb +49 -49
  44. data/lib/rubocop/sketchup/cop/suggestions/compatibility.rb +121 -117
  45. data/lib/rubocop/sketchup/cop/suggestions/dc_internals.rb +34 -34
  46. data/lib/rubocop/sketchup/cop/suggestions/file_encoding.rb +78 -78
  47. data/lib/rubocop/sketchup/cop/suggestions/model_entities.rb +58 -58
  48. data/lib/rubocop/sketchup/cop/suggestions/monkey_patched_api.rb +45 -45
  49. data/lib/rubocop/sketchup/cop/suggestions/operation_name.rb +137 -103
  50. data/lib/rubocop/sketchup/cop/suggestions/sketchup_find_support_file.rb +39 -39
  51. data/lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb +44 -44
  52. data/lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb +66 -66
  53. data/lib/rubocop/sketchup/cop/suggestions/tool_user_input.rb +41 -41
  54. data/lib/rubocop/sketchup/cop/suggestions/toolbar_timer.rb +65 -65
  55. data/lib/rubocop/sketchup/dc_globals.rb +24 -24
  56. data/lib/rubocop/sketchup/dc_methods.rb +130 -130
  57. data/lib/rubocop/sketchup/extension_project.rb +65 -65
  58. data/lib/rubocop/sketchup/features.rb +738 -738
  59. data/lib/rubocop/sketchup/formatter/extension_review.rb +269 -259
  60. data/lib/rubocop/sketchup/inject.rb +19 -19
  61. data/lib/rubocop/sketchup/namespace.rb +47 -47
  62. data/lib/rubocop/sketchup/namespace_checker.rb +46 -46
  63. data/lib/rubocop/sketchup/no_comment_disable.rb +17 -17
  64. data/lib/rubocop/sketchup/range_help.rb +52 -52
  65. data/lib/rubocop/sketchup/sketchup_target_range.rb +75 -0
  66. data/lib/rubocop/sketchup/sketchup_version.rb +117 -87
  67. data/lib/rubocop/sketchup/tool_checker.rb +43 -43
  68. data/lib/rubocop/sketchup/version.rb +5 -5
  69. data/rubocop-sketchup.gemspec +27 -27
  70. metadata +8 -4
@@ -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
@@ -1,24 +1,24 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module SketchUp
5
- module DynamicComponentGlobals
6
-
7
- DC_GLOBALS = %i[
8
- $dc_strings
9
- $dc_extension
10
- $dc_CONFIGURATOR_NAME
11
- $dc_REPORTER_NAME
12
- $dc_MANAGER_NAME
13
- $dc_observers
14
- ].freeze
15
-
16
- private
17
-
18
- def dc_global_var?(global_var)
19
- DC_GLOBALS.include?(global_var)
20
- end
21
-
22
- end
23
- end
24
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module SketchUp
5
+ module DynamicComponentGlobals
6
+
7
+ DC_GLOBALS = %i[
8
+ $dc_strings
9
+ $dc_extension
10
+ $dc_CONFIGURATOR_NAME
11
+ $dc_REPORTER_NAME
12
+ $dc_MANAGER_NAME
13
+ $dc_observers
14
+ ].freeze
15
+
16
+ private
17
+
18
+ def dc_global_var?(global_var)
19
+ DC_GLOBALS.include?(global_var)
20
+ end
21
+
22
+ end
23
+ end
24
+ end