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,45 +1,45 @@
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 ' \
33
- 'clipped.'
34
-
35
- def on_tool_class(class_node, body_methods)
36
- return unless find_method(body_methods, :draw)
37
- return if find_method(body_methods, :getExtents)
38
-
39
- add_offense(class_node, message: MSG_MISSING_GET_EXTENTS)
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 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 ' \
33
+ 'clipped.'
34
+
35
+ def on_tool_class(class_node, body_methods)
36
+ return unless find_method(body_methods, :draw)
37
+ return if find_method(body_methods, :getExtents)
38
+
39
+ add_offense(class_node, message: MSG_MISSING_GET_EXTENTS)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,68 +1,68 @@
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` ' \
35
- 'calls `view.invalidate`.'
36
-
37
- MSG_MISSING_INVALIDATE = 'When drawing to the viewport, make sure to ' \
38
- 'call `view.invalidate` when the tool ' \
39
- 'becomes inactive.'
40
-
41
- def_node_search :view_invalidate?, <<-PATTERN
42
- (send (lvar :view) :invalidate ...)
43
- PATTERN
44
-
45
- def on_tool_class(class_node, body_methods)
46
- return unless find_method(body_methods, :draw)
47
-
48
- check_method_invalidate(:deactivate, body_methods, class_node)
49
- check_method_invalidate(:suspend, body_methods, class_node)
50
- end
51
-
52
- private
53
-
54
- def check_method_invalidate(method_name, body_methods, class_node)
55
- method_node = find_method(body_methods, method_name)
56
- if method_node
57
- return if view_invalidate?(method_node)
58
-
59
- add_offense(method_node, message: MSG_MISSING_INVALIDATE)
60
- else
61
- add_offense(class_node, message: MSG_MISSING_INVALIDATE_METHOD)
62
- end
63
- end
64
-
65
- end
66
- end
67
- end
68
- 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` ' \
35
+ 'calls `view.invalidate`.'
36
+
37
+ MSG_MISSING_INVALIDATE = 'When drawing to the viewport, make sure to ' \
38
+ 'call `view.invalidate` when the tool ' \
39
+ 'becomes inactive.'
40
+
41
+ def_node_search :view_invalidate?, <<-PATTERN
42
+ (send (lvar :view) :invalidate ...)
43
+ PATTERN
44
+
45
+ def on_tool_class(class_node, body_methods)
46
+ return unless find_method(body_methods, :draw)
47
+
48
+ check_method_invalidate(:deactivate, body_methods, class_node)
49
+ check_method_invalidate(:suspend, body_methods, class_node)
50
+ end
51
+
52
+ private
53
+
54
+ def check_method_invalidate(method_name, body_methods, class_node)
55
+ method_node = find_method(body_methods, method_name)
56
+ if method_node
57
+ return if view_invalidate?(method_node)
58
+
59
+ add_offense(method_node, message: MSG_MISSING_INVALIDATE)
60
+ else
61
+ add_offense(class_node, message: MSG_MISSING_INVALIDATE_METHOD)
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ 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?`.'
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?`.'
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.'
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&.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.'
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&.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,110 +1,110 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module SketchUp
5
-
6
- WorkaroundCop = RuboCop::Cop::Cop.dup
7
-
8
- # Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
9
- # the inherited method without breaking functionality
10
- class WorkaroundCop
11
- # Remove the Cop.inherited method to be a noop. Our SketchUp::Cop
12
- # class will invoke the inherited hook instead
13
- class << self
14
- undef inherited
15
- def inherited(*) end # rubocop:disable Lint/MissingSuper
16
- end
17
-
18
- # Special case `Module#<` so that the rspec support rubocop exports
19
- # is compatible with our subclass
20
- def self.<(other)
21
- other.equal?(RuboCop::Cop::Cop) || super
22
- end
23
- end
24
- private_constant(:WorkaroundCop)
25
-
26
- # @abstract parent class to SketchUp cops
27
- #
28
- # The criteria for whether rubocop-sketchup analyzes a certain ruby file
29
- # is configured via `AllCops/SketchUp`. For example, if you want to
30
- # customize your project to scan all files within a `test/` directory
31
- # then you could add this to your configuration:
32
- #
33
- # @example configuring analyzed paths
34
- #
35
- # AllCops:
36
- # SketchUp:
37
- # SketchupDeprecations:
38
- # Exclude:
39
- # - '_test.rb$'
40
- # - '(?:^|/)test/'
41
- class Cop < WorkaroundCop
42
-
43
- include SketchUp::Config
44
-
45
- SKETCHUP_DEPARTMENT_SEVERITY = {
46
- SketchupRequirements: :error,
47
- SketchupDeprecations: :warning,
48
- SketchupPerformance: :warning,
49
- SketchupBugs: :warning,
50
- SketchupSuggestions: :convention,
51
- }.freeze
52
-
53
- # Invoke the original inherited hook so our cops are recognized
54
- def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
55
- RuboCop::Cop::Cop.inherited(subclass)
56
- end
57
-
58
- def relevant_file?(file)
59
- relevant_rubocop_sketchup_file?(file) && super
60
- end
61
-
62
- private
63
-
64
- def default_severity
65
- sketchup_severity || super
66
- end
67
-
68
- def sketchup_severity
69
- SKETCHUP_DEPARTMENT_SEVERITY[self.class.department]
70
- end
71
-
72
- def department_name
73
- self.class.department.to_s
74
- end
75
-
76
- def relevant_rubocop_sketchup_file?(file)
77
- !sketchup_excluded?(file)
78
- end
79
-
80
- def sketchup_excluded?(file)
81
- matches_file?(file, sketchup_exclude_pattern) ||
82
- matches_file?(file, sketchup_department_exclude_pattern)
83
- end
84
-
85
- def matches_file?(file, patterns)
86
- path = nil
87
- patterns.any? do |pattern|
88
- # Try to match the absolute path, as Exclude properties are absolute.
89
- next true if match_path?(pattern, file)
90
-
91
- # Try with relative path.
92
- path ||= config.path_relative_to_config(file)
93
- match_path?(pattern, path)
94
- end
95
- end
96
-
97
- def sketchup_department_exclude_pattern
98
- sketchup_cops_config
99
- .fetch(department_name, {})
100
- .fetch('Exclude', [])
101
- end
102
-
103
- def sketchup_exclude_pattern
104
- sketchup_cops_config
105
- .fetch('Exclude', [])
106
- end
107
-
108
- end
109
- end
110
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module SketchUp
5
+
6
+ WorkaroundCop = RuboCop::Cop::Cop.dup
7
+
8
+ # Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
9
+ # the inherited method without breaking functionality
10
+ class WorkaroundCop
11
+ # Remove the Cop.inherited method to be a noop. Our SketchUp::Cop
12
+ # class will invoke the inherited hook instead
13
+ class << self
14
+ undef inherited
15
+ def inherited(*) end # rubocop:disable Lint/MissingSuper
16
+ end
17
+
18
+ # Special case `Module#<` so that the rspec support rubocop exports
19
+ # is compatible with our subclass
20
+ def self.<(other)
21
+ other.equal?(RuboCop::Cop::Cop) || super
22
+ end
23
+ end
24
+ private_constant(:WorkaroundCop)
25
+
26
+ # @abstract parent class to SketchUp cops
27
+ #
28
+ # The criteria for whether rubocop-sketchup analyzes a certain ruby file
29
+ # is configured via `AllCops/SketchUp`. For example, if you want to
30
+ # customize your project to scan all files within a `test/` directory
31
+ # then you could add this to your configuration:
32
+ #
33
+ # @example configuring analyzed paths
34
+ #
35
+ # AllCops:
36
+ # SketchUp:
37
+ # SketchupDeprecations:
38
+ # Exclude:
39
+ # - '_test.rb$'
40
+ # - '(?:^|/)test/'
41
+ class Cop < WorkaroundCop
42
+
43
+ include SketchUp::Config
44
+
45
+ SKETCHUP_DEPARTMENT_SEVERITY = {
46
+ SketchupRequirements: :error,
47
+ SketchupDeprecations: :warning,
48
+ SketchupPerformance: :warning,
49
+ SketchupBugs: :warning,
50
+ SketchupSuggestions: :convention,
51
+ }.freeze
52
+
53
+ # Invoke the original inherited hook so our cops are recognized
54
+ def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
55
+ RuboCop::Cop::Cop.inherited(subclass)
56
+ end
57
+
58
+ def relevant_file?(file)
59
+ relevant_rubocop_sketchup_file?(file) && super
60
+ end
61
+
62
+ private
63
+
64
+ def default_severity
65
+ sketchup_severity || super
66
+ end
67
+
68
+ def sketchup_severity
69
+ SKETCHUP_DEPARTMENT_SEVERITY[self.class.department]
70
+ end
71
+
72
+ def department_name
73
+ self.class.department.to_s
74
+ end
75
+
76
+ def relevant_rubocop_sketchup_file?(file)
77
+ !sketchup_excluded?(file)
78
+ end
79
+
80
+ def sketchup_excluded?(file)
81
+ matches_file?(file, sketchup_exclude_pattern) ||
82
+ matches_file?(file, sketchup_department_exclude_pattern)
83
+ end
84
+
85
+ def matches_file?(file, patterns)
86
+ path = nil
87
+ patterns.any? do |pattern|
88
+ # Try to match the absolute path, as Exclude properties are absolute.
89
+ next true if match_path?(pattern, file)
90
+
91
+ # Try with relative path.
92
+ path ||= config.path_relative_to_config(file)
93
+ match_path?(pattern, path)
94
+ end
95
+ end
96
+
97
+ def sketchup_department_exclude_pattern
98
+ sketchup_cops_config
99
+ .fetch(department_name, {})
100
+ .fetch('Exclude', [])
101
+ end
102
+
103
+ def sketchup_exclude_pattern
104
+ sketchup_cops_config
105
+ .fetch('Exclude', [])
106
+ end
107
+
108
+ end
109
+ end
110
+ end