rubocop-sketchup 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +21 -20
  3. data/assets/output.html.erb +301 -301
  4. data/config/default.yml +400 -379
  5. data/lib/rubocop/sketchup/config.rb +63 -63
  6. data/lib/rubocop/sketchup/cop/bugs/material_name.rb +108 -108
  7. data/lib/rubocop/sketchup/cop/bugs/render_mode.rb +72 -72
  8. data/lib/rubocop/sketchup/cop/bugs/uniform_scaling.rb +36 -36
  9. data/lib/rubocop/sketchup/cop/deprecations/add_separator_to_menu.rb +25 -25
  10. data/lib/rubocop/sketchup/cop/deprecations/operation_next_transparent.rb +30 -30
  11. data/lib/rubocop/sketchup/cop/deprecations/require_all.rb +27 -27
  12. data/lib/rubocop/sketchup/cop/deprecations/set_texture_projection.rb +26 -26
  13. data/lib/rubocop/sketchup/cop/deprecations/show_ruby_panel.rb +25 -25
  14. data/lib/rubocop/sketchup/cop/deprecations/sketchup_set.rb +30 -30
  15. data/lib/rubocop/sketchup/cop/performance/openssl.rb +41 -41
  16. data/lib/rubocop/sketchup/cop/performance/operation_disable_ui.rb +33 -33
  17. data/lib/rubocop/sketchup/cop/performance/selection_bulk.rb +79 -79
  18. data/lib/rubocop/sketchup/cop/performance/type_check.rb +63 -63
  19. data/lib/rubocop/sketchup/cop/performance/typename.rb +24 -24
  20. data/lib/rubocop/sketchup/cop/requirements/api_namespace.rb +30 -30
  21. data/lib/rubocop/sketchup/cop/requirements/debug_mode.rb +27 -0
  22. data/lib/rubocop/sketchup/cop/requirements/exit.rb +33 -33
  23. data/lib/rubocop/sketchup/cop/requirements/extension_namespace.rb +125 -125
  24. data/lib/rubocop/sketchup/cop/requirements/file_structure.rb +97 -97
  25. data/lib/rubocop/sketchup/cop/requirements/gem_install.rb +45 -45
  26. data/lib/rubocop/sketchup/cop/requirements/get_extension_license.rb +95 -95
  27. data/lib/rubocop/sketchup/cop/requirements/global_constants.rb +38 -38
  28. data/lib/rubocop/sketchup/cop/requirements/global_include.rb +42 -42
  29. data/lib/rubocop/sketchup/cop/requirements/global_methods.rb +65 -65
  30. data/lib/rubocop/sketchup/cop/requirements/global_variables.rb +95 -95
  31. data/lib/rubocop/sketchup/cop/requirements/initialize_entity.rb +76 -0
  32. data/lib/rubocop/sketchup/cop/requirements/language_handler_globals.rb +46 -46
  33. data/lib/rubocop/sketchup/cop/requirements/load_path.rb +83 -83
  34. data/lib/rubocop/sketchup/cop/requirements/minimal_registration.rb +73 -73
  35. data/lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb +161 -161
  36. data/lib/rubocop/sketchup/cop/requirements/register_extension.rb +45 -45
  37. data/lib/rubocop/sketchup/cop/requirements/ruby_core_namespace.rb +291 -291
  38. data/lib/rubocop/sketchup/cop/requirements/ruby_stdlib_namespace.rb +634 -634
  39. data/lib/rubocop/sketchup/cop/requirements/shipped_extensions_namespace.rb +61 -61
  40. data/lib/rubocop/sketchup/cop/requirements/sketchup_extension.rb +119 -119
  41. data/lib/rubocop/sketchup/cop/requirements/sketchup_require.rb +150 -150
  42. data/lib/rubocop/sketchup/cop/suggestions/add_group.rb +49 -49
  43. data/lib/rubocop/sketchup/cop/suggestions/compatibility.rb +128 -128
  44. data/lib/rubocop/sketchup/cop/suggestions/dc_internals.rb +34 -34
  45. data/lib/rubocop/sketchup/cop/suggestions/file_encoding.rb +78 -78
  46. data/lib/rubocop/sketchup/cop/suggestions/model_entities.rb +58 -58
  47. data/lib/rubocop/sketchup/cop/suggestions/monkey_patched_api.rb +45 -45
  48. data/lib/rubocop/sketchup/cop/suggestions/operation_name.rb +137 -137
  49. data/lib/rubocop/sketchup/cop/suggestions/sketchup_find_support_file.rb +39 -39
  50. data/lib/rubocop/sketchup/cop/suggestions/sleep.rb +25 -0
  51. data/lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb +45 -45
  52. data/lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb +68 -68
  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/cop.rb +110 -110
  56. data/lib/rubocop/sketchup/dc_globals.rb +24 -24
  57. data/lib/rubocop/sketchup/dc_methods.rb +130 -130
  58. data/lib/rubocop/sketchup/extension_project.rb +65 -65
  59. data/lib/rubocop/sketchup/features.rb +1514 -1477
  60. data/lib/rubocop/sketchup/formatter/extension_review.rb +269 -269
  61. data/lib/rubocop/sketchup/generator.rb +21 -0
  62. data/lib/rubocop/sketchup/inject.rb +19 -19
  63. data/lib/rubocop/sketchup/namespace.rb +49 -49
  64. data/lib/rubocop/sketchup/namespace_checker.rb +103 -103
  65. data/lib/rubocop/sketchup/no_comment_disable.rb +17 -17
  66. data/lib/rubocop/sketchup/range_help.rb +52 -52
  67. data/lib/rubocop/sketchup/sketchup_target_range.rb +75 -75
  68. data/lib/rubocop/sketchup/sketchup_version.rb +131 -129
  69. data/lib/rubocop/sketchup/tool_checker.rb +41 -41
  70. data/lib/rubocop/sketchup/version.rb +7 -7
  71. data/lib/rubocop/sketchup.rb +14 -14
  72. data/lib/rubocop-sketchup.rb +53 -53
  73. data/rubocop-sketchup.gemspec +28 -29
  74. metadata +7 -23
@@ -1,161 +1,161 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupRequirements
6
- # Observers that perform model changes must create transparent operations
7
- # to ensure the user can easily undo.
8
- #
9
- # An important part of SketchUp's user experience is to be able to easily
10
- # undo any modification to the model. This is important to prevent
11
- # accidental loss of work.
12
- #
13
- # If you for example have an observer that assigns a material to new faces
14
- # then the user would still expect to undo this in a single operation.
15
- #
16
- # To achieve this, set the fourth argument in `model.start_operation` to
17
- # `true` in order to chain your observer operation to the previous
18
- # operation.
19
- #
20
- # @example
21
- # class ExampleObserver < Sketchup::EntitiesObserver
22
- # def onElementAdded(entities, entity)
23
- # return unless entity.valid?
24
- # return unless entity.is_a?(Sketchup::Face)
25
- # entity.model.start_operation('Paint Face', true, false, true)
26
- # entity.material = 'red'
27
- # entity.model.commit_operation
28
- # end
29
- # end
30
- class ObserversStartOperation < SketchUp::Cop
31
-
32
- include SketchUp::NoCommentDisable
33
- include RangeHelp
34
-
35
- MSG = 'Observers should create transparent operations.'
36
-
37
- def_node_search :start_operation, <<-PATTERN
38
- (send
39
- _ :start_operation
40
- ...)
41
- PATTERN
42
-
43
- OBSERVER_METHODS = %i[
44
- onActivateModel
45
- onNewModel
46
- onOpenModel
47
- onQuit
48
- onUnloadExtension
49
-
50
- onComponentInstanceAdded
51
- onComponentInstanceRemoved
52
-
53
- onComponentAdded
54
- onComponentPropertiesChanged
55
- onComponentRemoved
56
- onComponentTypeChanged
57
-
58
- onTextChanged
59
-
60
- onActiveSectionPlaneChanged
61
- onElementAdded
62
- onElementModified
63
- onElementRemoved
64
- onEraseEntities
65
-
66
- onChangeEntity
67
- onEraseEntity
68
-
69
- onClose
70
- onOpen
71
-
72
- onCurrentLayerChanged
73
- onLayerAdded
74
- onLayerChanged
75
- onLayerRemoved
76
- onRemoveAllLayers
77
-
78
- onMaterialAdd
79
- onMaterialChange
80
- onMaterialRefChange
81
- onMaterialRemove
82
- onMaterialSetCurrent
83
- onMaterialUndoRedo
84
-
85
- onActivePathChanged
86
- onAfterComponentSaveAs
87
- onBeforeComponentSaveAs
88
- onDeleteModel
89
- onEraseAll
90
- onExplode
91
- onPidChanged
92
- onPlaceComponent
93
- onPostSaveModel
94
- onPreSaveModel
95
- onSaveModel
96
- onTransactionAbort
97
- onTransactionCommit
98
- onTransactionEmpty
99
- onTransactionRedo
100
- onTransactionStart
101
- onTransactionUndo
102
-
103
- onOptionsProviderChanged
104
-
105
- onContentsModified
106
- onElementAdded
107
- onElementRemoved
108
-
109
- onRenderingOptionsChanged
110
-
111
- onSelectionAdded
112
- onSelectionBulkChange
113
- onSelectionCleared
114
- onSelectionRemoved
115
-
116
- onShadowInfoChanged
117
-
118
- onActiveToolChanged
119
- onToolStateChanged
120
-
121
- onViewChanged
122
- ].freeze
123
-
124
- def on_def(node)
125
- return unless observer_event?(node)
126
-
127
- operations = start_operation(node)
128
- operations.each { |operation|
129
- _name, _disable_ui, _next_tr, transparent = operation.arguments
130
- next unless transparent.nil? || transparent.falsey_literal?
131
-
132
- location = operation_location(operation)
133
- add_offense(operation, location: location)
134
- }
135
- end
136
-
137
- private
138
-
139
- def range(node)
140
- range_between(node.begin_pos, node.end_pos)
141
- end
142
-
143
- def operation_location(node)
144
- # Highlight the fourth argument if it's used. Fall back to the method
145
- # name.
146
- transparent_argument = node.arguments[3]
147
- if transparent_argument
148
- range(transparent_argument.loc.expression)
149
- else
150
- :selector
151
- end
152
- end
153
-
154
- def observer_event?(node)
155
- OBSERVER_METHODS.include?(node.method_name)
156
- end
157
-
158
- end
159
- end
160
- end
161
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupRequirements
6
+ # Observers that perform model changes must create transparent operations
7
+ # to ensure the user can easily undo.
8
+ #
9
+ # An important part of SketchUp's user experience is to be able to easily
10
+ # undo any modification to the model. This is important to prevent
11
+ # accidental loss of work.
12
+ #
13
+ # If you for example have an observer that assigns a material to new faces
14
+ # then the user would still expect to undo this in a single operation.
15
+ #
16
+ # To achieve this, set the fourth argument in `model.start_operation` to
17
+ # `true` in order to chain your observer operation to the previous
18
+ # operation.
19
+ #
20
+ # @example
21
+ # class ExampleObserver < Sketchup::EntitiesObserver
22
+ # def onElementAdded(entities, entity)
23
+ # return unless entity.valid?
24
+ # return unless entity.is_a?(Sketchup::Face)
25
+ # entity.model.start_operation('Paint Face', true, false, true)
26
+ # entity.material = 'red'
27
+ # entity.model.commit_operation
28
+ # end
29
+ # end
30
+ class ObserversStartOperation < SketchUp::Cop
31
+
32
+ include SketchUp::NoCommentDisable
33
+ include RangeHelp
34
+
35
+ MSG = 'Observers should create transparent operations.'
36
+
37
+ def_node_search :start_operation, <<-PATTERN
38
+ (send
39
+ _ :start_operation
40
+ ...)
41
+ PATTERN
42
+
43
+ OBSERVER_METHODS = %i[
44
+ onActivateModel
45
+ onNewModel
46
+ onOpenModel
47
+ onQuit
48
+ onUnloadExtension
49
+
50
+ onComponentInstanceAdded
51
+ onComponentInstanceRemoved
52
+
53
+ onComponentAdded
54
+ onComponentPropertiesChanged
55
+ onComponentRemoved
56
+ onComponentTypeChanged
57
+
58
+ onTextChanged
59
+
60
+ onActiveSectionPlaneChanged
61
+ onElementAdded
62
+ onElementModified
63
+ onElementRemoved
64
+ onEraseEntities
65
+
66
+ onChangeEntity
67
+ onEraseEntity
68
+
69
+ onClose
70
+ onOpen
71
+
72
+ onCurrentLayerChanged
73
+ onLayerAdded
74
+ onLayerChanged
75
+ onLayerRemoved
76
+ onRemoveAllLayers
77
+
78
+ onMaterialAdd
79
+ onMaterialChange
80
+ onMaterialRefChange
81
+ onMaterialRemove
82
+ onMaterialSetCurrent
83
+ onMaterialUndoRedo
84
+
85
+ onActivePathChanged
86
+ onAfterComponentSaveAs
87
+ onBeforeComponentSaveAs
88
+ onDeleteModel
89
+ onEraseAll
90
+ onExplode
91
+ onPidChanged
92
+ onPlaceComponent
93
+ onPostSaveModel
94
+ onPreSaveModel
95
+ onSaveModel
96
+ onTransactionAbort
97
+ onTransactionCommit
98
+ onTransactionEmpty
99
+ onTransactionRedo
100
+ onTransactionStart
101
+ onTransactionUndo
102
+
103
+ onOptionsProviderChanged
104
+
105
+ onContentsModified
106
+ onElementAdded
107
+ onElementRemoved
108
+
109
+ onRenderingOptionsChanged
110
+
111
+ onSelectionAdded
112
+ onSelectionBulkChange
113
+ onSelectionCleared
114
+ onSelectionRemoved
115
+
116
+ onShadowInfoChanged
117
+
118
+ onActiveToolChanged
119
+ onToolStateChanged
120
+
121
+ onViewChanged
122
+ ].freeze
123
+
124
+ def on_def(node)
125
+ return unless observer_event?(node)
126
+
127
+ operations = start_operation(node)
128
+ operations.each { |operation|
129
+ _name, _disable_ui, _next_tr, transparent = operation.arguments
130
+ next unless transparent.nil? || transparent.falsey_literal?
131
+
132
+ location = operation_location(operation)
133
+ add_offense(operation, location: location)
134
+ }
135
+ end
136
+
137
+ private
138
+
139
+ def range(node)
140
+ range_between(node.begin_pos, node.end_pos)
141
+ end
142
+
143
+ def operation_location(node)
144
+ # Highlight the fourth argument if it's used. Fall back to the method
145
+ # name.
146
+ transparent_argument = node.arguments[3]
147
+ if transparent_argument
148
+ range(transparent_argument.loc.expression)
149
+ else
150
+ :selector
151
+ end
152
+ end
153
+
154
+ def observer_event?(node)
155
+ OBSERVER_METHODS.include?(node.method_name)
156
+ end
157
+
158
+ end
159
+ end
160
+ end
161
+ end
@@ -1,45 +1,45 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module SketchupRequirements
6
- # Always register extensions to load by default. Otherwise it might
7
- # confuse users to think the extension isn't working.
8
- #
9
- # @example Good - Extension will load upon first run.
10
- # module Example
11
- # unless file_loaded?(__FILE__)
12
- # extension = SketchupExtension.new('Hello World', 'example/main')
13
- # Sketchup.register_extension(extension, true)
14
- # file_loaded(__FILE__)
15
- # end
16
- # end
17
- class RegisterExtension < SketchUp::Cop
18
-
19
- include SketchUp::NoCommentDisable
20
-
21
- MSG = 'Always register extensions to load by default.'
22
-
23
- def_node_search :sketchup_register_extension, <<-PATTERN
24
- (send
25
- (const nil? :Sketchup) :register_extension
26
- $...)
27
- PATTERN
28
-
29
- def on_send(node)
30
- sketchup_register_extension(node).each { |args|
31
- if args.size < 2
32
- add_offense(node, location: :selector)
33
- next
34
- end
35
- load_arg = args[1]
36
- next if load_arg.true_type?
37
-
38
- add_offense(load_arg)
39
- }
40
- end
41
-
42
- end
43
- end
44
- end
45
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupRequirements
6
+ # Always register extensions to load by default. Otherwise it might
7
+ # confuse users to think the extension isn't working.
8
+ #
9
+ # @example Good - Extension will load upon first run.
10
+ # module Example
11
+ # unless file_loaded?(__FILE__)
12
+ # extension = SketchupExtension.new('Hello World', 'example/main')
13
+ # Sketchup.register_extension(extension, true)
14
+ # file_loaded(__FILE__)
15
+ # end
16
+ # end
17
+ class RegisterExtension < SketchUp::Cop
18
+
19
+ include SketchUp::NoCommentDisable
20
+
21
+ MSG = 'Always register extensions to load by default.'
22
+
23
+ def_node_search :sketchup_register_extension, <<-PATTERN
24
+ (send
25
+ (const nil? :Sketchup) :register_extension
26
+ $...)
27
+ PATTERN
28
+
29
+ def on_send(node)
30
+ sketchup_register_extension(node).each { |args|
31
+ if args.size < 2
32
+ add_offense(node, location: :selector)
33
+ next
34
+ end
35
+ load_arg = args[1]
36
+ next if load_arg.true_type?
37
+
38
+ add_offense(load_arg)
39
+ }
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end