rubocop-sketchup 0.4.1 → 0.5.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -1
  3. data/assets/logo.png +0 -0
  4. data/assets/output.html.erb +301 -0
  5. data/config/default.yml +141 -36
  6. data/lib/rubocop/sketchup/config.rb +28 -8
  7. data/lib/rubocop/sketchup/cop/deprecations/add_separator_to_menu.rb +4 -1
  8. data/lib/rubocop/sketchup/cop/deprecations/operation_next_transparent.rb +11 -2
  9. data/lib/rubocop/sketchup/cop/deprecations/require_all.rb +7 -2
  10. data/lib/rubocop/sketchup/cop/deprecations/set_texture_projection.rb +6 -2
  11. data/lib/rubocop/sketchup/cop/deprecations/show_ruby_panel.rb +4 -1
  12. data/lib/rubocop/sketchup/cop/deprecations/sketchup_set.rb +8 -0
  13. data/lib/rubocop/sketchup/cop/performance/openssl.rb +5 -3
  14. data/lib/rubocop/sketchup/cop/performance/operation_disable_ui.rb +10 -2
  15. data/lib/rubocop/sketchup/cop/performance/selection_bulk.rb +11 -4
  16. data/lib/rubocop/sketchup/cop/performance/type_check.rb +63 -0
  17. data/lib/rubocop/sketchup/cop/performance/typename.rb +6 -1
  18. data/lib/rubocop/sketchup/cop/requirements/api_namespace.rb +8 -2
  19. data/lib/rubocop/sketchup/cop/requirements/exit.rb +7 -3
  20. data/lib/rubocop/sketchup/cop/requirements/extension_namespace.rb +32 -2
  21. data/lib/rubocop/sketchup/cop/requirements/file_structure.rb +22 -10
  22. data/lib/rubocop/sketchup/cop/requirements/gem_install.rb +45 -0
  23. data/lib/rubocop/sketchup/cop/requirements/get_extension_license.rb +95 -0
  24. data/lib/rubocop/sketchup/cop/requirements/global_constants.rb +10 -1
  25. data/lib/rubocop/sketchup/cop/requirements/global_include.rb +9 -2
  26. data/lib/rubocop/sketchup/cop/requirements/global_methods.rb +10 -1
  27. data/lib/rubocop/sketchup/cop/requirements/global_variables.rb +13 -4
  28. data/lib/rubocop/sketchup/cop/requirements/language_handler_globals.rb +6 -4
  29. data/lib/rubocop/sketchup/cop/requirements/load_path.rb +9 -6
  30. data/lib/rubocop/sketchup/cop/requirements/minimal_registration.rb +26 -2
  31. data/lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb +28 -2
  32. data/lib/rubocop/sketchup/cop/requirements/register_extension.rb +12 -2
  33. data/lib/rubocop/sketchup/cop/requirements/ruby_core_namespace.rb +14 -8
  34. data/lib/rubocop/sketchup/cop/requirements/ruby_stdlib_namespace.rb +594 -588
  35. data/lib/rubocop/sketchup/cop/requirements/shipped_extensions_namespace.rb +6 -6
  36. data/lib/rubocop/sketchup/cop/requirements/sketchup_extension.rb +28 -9
  37. data/lib/rubocop/sketchup/cop/requirements/sketchup_require.rb +163 -0
  38. data/lib/rubocop/sketchup/cop/suggestions/add_group.rb +49 -0
  39. data/lib/rubocop/sketchup/cop/suggestions/compatibility.rb +35 -6
  40. data/lib/rubocop/sketchup/cop/suggestions/dc_internals.rb +6 -3
  41. data/lib/rubocop/sketchup/cop/suggestions/file_encoding.rb +3 -0
  42. data/lib/rubocop/sketchup/cop/suggestions/model_entities.rb +9 -2
  43. data/lib/rubocop/sketchup/cop/suggestions/monkey_patched_api.rb +5 -1
  44. data/lib/rubocop/sketchup/cop/suggestions/operation_name.rb +20 -9
  45. data/lib/rubocop/sketchup/cop/suggestions/sketchup_find_support_file.rb +13 -2
  46. data/lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb +44 -0
  47. data/lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb +66 -0
  48. data/lib/rubocop/sketchup/cop/suggestions/tool_user_input.rb +41 -0
  49. data/lib/rubocop/sketchup/cop/suggestions/toolbar_timer.rb +65 -0
  50. data/lib/rubocop/sketchup/cop.rb +38 -18
  51. data/lib/rubocop/sketchup/dc_globals.rb +1 -1
  52. data/lib/rubocop/sketchup/dc_methods.rb +27 -27
  53. data/lib/rubocop/sketchup/extension_project.rb +19 -2
  54. data/lib/rubocop/sketchup/formatter/extension_review.rb +35 -15
  55. data/lib/rubocop/sketchup/inject.rb +1 -1
  56. data/lib/rubocop/sketchup/namespace.rb +1 -0
  57. data/lib/rubocop/sketchup/namespace_checker.rb +4 -1
  58. data/lib/rubocop/sketchup/no_comment_disable.rb +1 -1
  59. data/lib/rubocop/sketchup/range_help.rb +52 -0
  60. data/lib/rubocop/sketchup/sketchup_version.rb +4 -2
  61. data/lib/rubocop/sketchup/tool_checker.rb +43 -0
  62. data/lib/rubocop/sketchup/version.rb +1 -1
  63. data/lib/rubocop/sketchup.rb +1 -1
  64. data/lib/rubocop-sketchup.rb +9 -0
  65. data/rubocop-sketchup.gemspec +8 -11
  66. metadata +18 -6
  67. data/lib/rubocop/sketchup/cop/suggestions/sketchup_require.rb +0 -67
@@ -3,6 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module SketchupRequirements
6
+ # Do not modify the load path. Modifying `$LOAD_PATH` is bad practice
7
+ # because it can cause extensions to inadvertently load the wrong file.
6
8
  class LoadPath < SketchUp::Cop
7
9
 
8
10
  include SketchUp::NoCommentDisable
@@ -16,11 +18,11 @@ module RuboCop
16
18
  )
17
19
  PATTERN
18
20
 
19
- LOAD_PATH_ALIASES = %i(
21
+ LOAD_PATH_ALIASES = %i[
20
22
  $: $LOAD_PATH
21
- )
23
+ ].freeze
22
24
 
23
- MUTATORS = %i(
25
+ MUTATORS = %i[
24
26
  <<
25
27
  []=
26
28
  clear
@@ -51,7 +53,7 @@ module RuboCop
51
53
  sort_by!
52
54
  uniq!
53
55
  unshift
54
- )
56
+ ].freeze
55
57
 
56
58
  def load_path?(sym)
57
59
  LOAD_PATH_ALIASES.include?(sym)
@@ -63,15 +65,16 @@ module RuboCop
63
65
 
64
66
  def on_gvasgn(node)
65
67
  global_var, = *node
68
+ return unless load_path?(global_var)
66
69
 
67
- add_offense(node, location: :name, severity: :error) if load_path?(global_var)
70
+ add_offense(node, location: :expression)
68
71
  end
69
72
 
70
73
  def on_send(node)
71
74
  method_name = load_path_mutator?(node)
72
75
  return unless method_name
73
76
 
74
- add_offense(node, location: :expression, severity: :error)
77
+ add_offense(node, location: :expression)
75
78
  end
76
79
 
77
80
  end
@@ -7,12 +7,33 @@ module RuboCop
7
7
  module SketchupRequirements
8
8
  # Don't load extension files in the root file registering the extension.
9
9
  # Extensions should not load additional files when it's disabled.
10
+ #
11
+ # @example Bad - Extension will always load.
12
+ # module Example
13
+ # require 'example/main' # BAD! This will load even when extension
14
+ # # is disabled.
15
+ # unless file_loaded?(__FILE__)
16
+ # extension = SketchupExtension.new('Hello World', 'example/main')
17
+ # Sketchup.register_extension(extension, true)
18
+ # file_loaded(__FILE__)
19
+ # end
20
+ # end
21
+ #
22
+ # @example Good - Extension doesn't load anything unless its enabled.
23
+ # module Example
24
+ # unless file_loaded?(__FILE__)
25
+ # extension = SketchupExtension.new('Hello World', 'example/main')
26
+ # Sketchup.register_extension(extension, true)
27
+ # file_loaded(__FILE__)
28
+ # end
29
+ # end
10
30
  class MinimalRegistration < SketchUp::Cop
11
31
 
12
32
  include SketchUp::NoCommentDisable
13
33
  include SketchUp::ExtensionProject
14
34
 
15
- MSG = "Don't load extension files in the root file registering the extension.".freeze
35
+ MSG = "Don't load extension files in the root file registering the "\
36
+ 'extension.'.freeze
16
37
 
17
38
  # Reference: http://rubocop.readthedocs.io/en/latest/node_pattern/
18
39
  def_node_matcher :require_filename, <<-PATTERN
@@ -31,16 +52,19 @@ module RuboCop
31
52
 
32
53
  def extension_file?(filename)
33
54
  return false unless filename.include?('/')
55
+
34
56
  first_directory = filename.split('/').first
35
57
  @extension_basename.casecmp(first_directory) == 0
36
58
  end
37
59
 
38
60
  def on_send(node)
39
61
  return unless @extension_basename
62
+
40
63
  filename = require_filename(node)
41
64
  return if filename.nil?
42
65
  return unless extension_file?(filename)
43
- add_offense(node, severity: :error)
66
+
67
+ add_offense(node)
44
68
  end
45
69
 
46
70
  end
@@ -3,6 +3,30 @@
3
3
  module RuboCop
4
4
  module Cop
5
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
6
30
  class ObserversStartOperation < SketchUp::Cop
7
31
 
8
32
  include SketchUp::NoCommentDisable
@@ -95,16 +119,18 @@ module RuboCop
95
119
  onToolStateChanged
96
120
 
97
121
  onViewChanged
98
- ]
122
+ ].freeze
99
123
 
100
124
  def on_def(node)
101
125
  return unless observer_event?(node)
126
+
102
127
  operations = start_operation(node)
103
128
  operations.each { |operation|
104
129
  _name, _disable_ui, _next_tr, transparent = operation.arguments
105
130
  next unless transparent.nil? || transparent.falsey_literal?
131
+
106
132
  location = operation_location(operation)
107
- add_offense(operation, location: location, severity: :error)
133
+ add_offense(operation, location: location)
108
134
  }
109
135
  end
110
136
 
@@ -5,6 +5,15 @@ module RuboCop
5
5
  module SketchupRequirements
6
6
  # Always register extensions to load by default. Otherwise it might
7
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
8
17
  class RegisterExtension < SketchUp::Cop
9
18
 
10
19
  include SketchUp::NoCommentDisable
@@ -20,12 +29,13 @@ module RuboCop
20
29
  def on_send(node)
21
30
  sketchup_register_extension(node).each { |args|
22
31
  if args.size < 2
23
- add_offense(node, severity: :error)
32
+ add_offense(node, location: :selector)
24
33
  next
25
34
  end
26
35
  load_arg = args[1]
27
36
  next if load_arg.true_type?
28
- add_offense(load_arg, severity: :error)
37
+
38
+ add_offense(load_arg)
29
39
  }
30
40
  end
31
41
 
@@ -3,6 +3,12 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module SketchupRequirements
6
+ # Extensions in SketchUp all share the same Ruby environment on the user's
7
+ # machine. Because of this it's important that each extension isolate
8
+ # itself to avoid clashing with other extensions.
9
+ #
10
+ # Extensions submitted to Extension Warehouse is expected to not modify
11
+ # core Ruby functionality.
6
12
  class RubyCoreNamespace < SketchUp::Cop
7
13
 
8
14
  include SketchUp::NoCommentDisable
@@ -13,7 +19,7 @@ module RuboCop
13
19
  # We check only against the top level namespaces. The core define more
14
20
  # objects, but they are under one of the top level namespaces listed.
15
21
 
16
- NAMESPACES_RUBY_186 = %w(
22
+ NAMESPACES_RUBY_186 = %w[
17
23
  ArgumentError
18
24
  Array
19
25
  Bignum
@@ -84,9 +90,9 @@ module RuboCop
84
90
  TypeError
85
91
  UnboundMethod
86
92
  ZeroDivisionError
87
- ).freeze
93
+ ].freeze
88
94
 
89
- NAMESPACES_RUBY_200 = %w(
95
+ NAMESPACES_RUBY_200 = %w[
90
96
  ARGF
91
97
  ArgumentError
92
98
  Array
@@ -172,9 +178,9 @@ module RuboCop
172
178
  TypeError
173
179
  UnboundMethod
174
180
  ZeroDivisionError
175
- ).freeze
181
+ ].freeze
176
182
 
177
- NAMESPACES_RUBY_220 = %w(
183
+ NAMESPACES_RUBY_220 = %w[
178
184
  ArgumentError
179
185
  Array
180
186
  BasicObject
@@ -263,15 +269,15 @@ module RuboCop
263
269
  UnboundMethod
264
270
  UncaughtThrowError
265
271
  ZeroDivisionError
266
- ).freeze
272
+ ].freeze
267
273
 
268
274
  NAMESPACES = (
269
275
  (
270
276
  NAMESPACES_RUBY_186 |
271
277
  NAMESPACES_RUBY_200 |
272
278
  NAMESPACES_RUBY_220
273
- # Remove Object because this is the global namespace and there are
274
- # other checks for this.
279
+ # Remove Object because this is the global namespace and there are
280
+ # other checks for this.
275
281
  ) - ['Object']
276
282
  ).freeze
277
283