rubocop-sketchup 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +20 -19
- data/assets/output.html.erb +301 -301
- data/config/default.yml +379 -379
- data/lib/rubocop/sketchup/config.rb +63 -63
- data/lib/rubocop/sketchup/cop/bugs/material_name.rb +108 -108
- data/lib/rubocop/sketchup/cop/bugs/render_mode.rb +72 -72
- data/lib/rubocop/sketchup/cop/bugs/uniform_scaling.rb +36 -36
- data/lib/rubocop/sketchup/cop/deprecations/add_separator_to_menu.rb +25 -25
- data/lib/rubocop/sketchup/cop/deprecations/operation_next_transparent.rb +30 -30
- data/lib/rubocop/sketchup/cop/deprecations/require_all.rb +27 -27
- data/lib/rubocop/sketchup/cop/deprecations/set_texture_projection.rb +26 -26
- data/lib/rubocop/sketchup/cop/deprecations/show_ruby_panel.rb +25 -25
- data/lib/rubocop/sketchup/cop/deprecations/sketchup_set.rb +30 -30
- data/lib/rubocop/sketchup/cop/performance/openssl.rb +41 -41
- data/lib/rubocop/sketchup/cop/performance/operation_disable_ui.rb +33 -33
- data/lib/rubocop/sketchup/cop/performance/selection_bulk.rb +79 -79
- data/lib/rubocop/sketchup/cop/performance/type_check.rb +63 -63
- data/lib/rubocop/sketchup/cop/performance/typename.rb +24 -24
- data/lib/rubocop/sketchup/cop/requirements/api_namespace.rb +30 -30
- data/lib/rubocop/sketchup/cop/requirements/exit.rb +33 -33
- data/lib/rubocop/sketchup/cop/requirements/extension_namespace.rb +125 -125
- data/lib/rubocop/sketchup/cop/requirements/file_structure.rb +97 -97
- data/lib/rubocop/sketchup/cop/requirements/gem_install.rb +45 -45
- data/lib/rubocop/sketchup/cop/requirements/get_extension_license.rb +95 -95
- data/lib/rubocop/sketchup/cop/requirements/global_constants.rb +38 -38
- data/lib/rubocop/sketchup/cop/requirements/global_include.rb +42 -42
- data/lib/rubocop/sketchup/cop/requirements/global_methods.rb +65 -65
- data/lib/rubocop/sketchup/cop/requirements/global_variables.rb +95 -95
- data/lib/rubocop/sketchup/cop/requirements/language_handler_globals.rb +46 -46
- data/lib/rubocop/sketchup/cop/requirements/load_path.rb +83 -83
- data/lib/rubocop/sketchup/cop/requirements/minimal_registration.rb +73 -73
- data/lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb +161 -161
- data/lib/rubocop/sketchup/cop/requirements/register_extension.rb +45 -45
- data/lib/rubocop/sketchup/cop/requirements/ruby_core_namespace.rb +291 -291
- data/lib/rubocop/sketchup/cop/requirements/ruby_stdlib_namespace.rb +634 -634
- data/lib/rubocop/sketchup/cop/requirements/shipped_extensions_namespace.rb +61 -61
- data/lib/rubocop/sketchup/cop/requirements/sketchup_extension.rb +119 -119
- data/lib/rubocop/sketchup/cop/requirements/sketchup_require.rb +150 -149
- data/lib/rubocop/sketchup/cop/suggestions/add_group.rb +49 -49
- data/lib/rubocop/sketchup/cop/suggestions/compatibility.rb +128 -128
- data/lib/rubocop/sketchup/cop/suggestions/dc_internals.rb +34 -34
- data/lib/rubocop/sketchup/cop/suggestions/file_encoding.rb +78 -78
- data/lib/rubocop/sketchup/cop/suggestions/model_entities.rb +58 -58
- data/lib/rubocop/sketchup/cop/suggestions/monkey_patched_api.rb +45 -45
- data/lib/rubocop/sketchup/cop/suggestions/operation_name.rb +137 -137
- data/lib/rubocop/sketchup/cop/suggestions/sketchup_find_support_file.rb +39 -39
- data/lib/rubocop/sketchup/cop/suggestions/tool_drawing_bounds.rb +45 -45
- data/lib/rubocop/sketchup/cop/suggestions/tool_invalidate.rb +68 -68
- data/lib/rubocop/sketchup/cop/suggestions/tool_user_input.rb +41 -41
- data/lib/rubocop/sketchup/cop/suggestions/toolbar_timer.rb +65 -65
- data/lib/rubocop/sketchup/cop.rb +110 -110
- data/lib/rubocop/sketchup/dc_globals.rb +24 -24
- data/lib/rubocop/sketchup/dc_methods.rb +130 -130
- data/lib/rubocop/sketchup/extension_project.rb +65 -65
- data/lib/rubocop/sketchup/features.rb +1477 -1420
- data/lib/rubocop/sketchup/formatter/extension_review.rb +269 -269
- data/lib/rubocop/sketchup/inject.rb +19 -19
- data/lib/rubocop/sketchup/namespace.rb +49 -49
- data/lib/rubocop/sketchup/namespace_checker.rb +103 -46
- data/lib/rubocop/sketchup/no_comment_disable.rb +17 -17
- data/lib/rubocop/sketchup/range_help.rb +52 -52
- data/lib/rubocop/sketchup/sketchup_target_range.rb +75 -75
- data/lib/rubocop/sketchup/sketchup_version.rb +129 -128
- data/lib/rubocop/sketchup/tool_checker.rb +41 -43
- data/lib/rubocop/sketchup/version.rb +7 -7
- data/lib/rubocop/sketchup.rb +14 -14
- data/lib/rubocop-sketchup.rb +53 -53
- data/rubocop-sketchup.gemspec +29 -29
- metadata +8 -8
@@ -1,45 +1,45 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module SketchupRequirements
|
6
|
-
# It's tempting to use gems in an extension. However, there are issues if
|
7
|
-
# consuming them via Gem.install;
|
8
|
-
#
|
9
|
-
# * Net::HTTP is unreliable. (SSL certificate issues, OpenSSL performance
|
10
|
-
# freeze under Windows)
|
11
|
-
# * Compiled extensions cannot be installed like this as they require
|
12
|
-
# DevKit.
|
13
|
-
# * While downloading and installing SketchUp freezes. (Bad thing if done
|
14
|
-
# automatically upon loading the extensions - especially without user
|
15
|
-
# notice. It's easy to think SU have stopped working)
|
16
|
-
# * Version collisions. If multiple extensions want to use different
|
17
|
-
# versions of a gem they will clash if the versions aren't compatible
|
18
|
-
# with the features they use.
|
19
|
-
#
|
20
|
-
# They only way to ensure extensions doesn't clash is to namespace
|
21
|
-
# everything into extension namespace. This means making a copy of the
|
22
|
-
# gem you want to use and wrap it in your own namespace.
|
23
|
-
class GemInstall < SketchUp::Cop
|
24
|
-
|
25
|
-
include RangeHelp
|
26
|
-
include SketchUp::NoCommentDisable
|
27
|
-
|
28
|
-
MSG = '`Gem.install` is unreliable in SketchUp, and can cause '\
|
29
|
-
'extensions to clash.'
|
30
|
-
|
31
|
-
# Reference: http://rubocop.readthedocs.io/en/latest/development/
|
32
|
-
def_node_matcher :gem_install?, <<-PATTERN
|
33
|
-
(send (const nil? :Gem) :install ...)
|
34
|
-
PATTERN
|
35
|
-
|
36
|
-
def on_send(node)
|
37
|
-
return unless gem_install?(node)
|
38
|
-
|
39
|
-
range = range_with_receiver(node)
|
40
|
-
add_offense(node, location: range)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module SketchupRequirements
|
6
|
+
# It's tempting to use gems in an extension. However, there are issues if
|
7
|
+
# consuming them via Gem.install;
|
8
|
+
#
|
9
|
+
# * Net::HTTP is unreliable. (SSL certificate issues, OpenSSL performance
|
10
|
+
# freeze under Windows)
|
11
|
+
# * Compiled extensions cannot be installed like this as they require
|
12
|
+
# DevKit.
|
13
|
+
# * While downloading and installing SketchUp freezes. (Bad thing if done
|
14
|
+
# automatically upon loading the extensions - especially without user
|
15
|
+
# notice. It's easy to think SU have stopped working)
|
16
|
+
# * Version collisions. If multiple extensions want to use different
|
17
|
+
# versions of a gem they will clash if the versions aren't compatible
|
18
|
+
# with the features they use.
|
19
|
+
#
|
20
|
+
# They only way to ensure extensions doesn't clash is to namespace
|
21
|
+
# everything into extension namespace. This means making a copy of the
|
22
|
+
# gem you want to use and wrap it in your own namespace.
|
23
|
+
class GemInstall < SketchUp::Cop
|
24
|
+
|
25
|
+
include RangeHelp
|
26
|
+
include SketchUp::NoCommentDisable
|
27
|
+
|
28
|
+
MSG = '`Gem.install` is unreliable in SketchUp, and can cause ' \
|
29
|
+
'extensions to clash.'
|
30
|
+
|
31
|
+
# Reference: http://rubocop.readthedocs.io/en/latest/development/
|
32
|
+
def_node_matcher :gem_install?, <<-PATTERN
|
33
|
+
(send (const nil? :Gem) :install ...)
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_send(node)
|
37
|
+
return unless gem_install?(node)
|
38
|
+
|
39
|
+
range = range_with_receiver(node)
|
40
|
+
add_offense(node, location: range)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,95 +1,95 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module SketchupRequirements
|
6
|
-
# Don't attempt to kill the Ruby interpreter by calling `exit` or `exit!`.
|
7
|
-
# SketchUp will trap `exit` and prevent that, with a message in the
|
8
|
-
# console. But `exit!` is not trapped and with terminate SketchUp without
|
9
|
-
# shutting down cleanly.
|
10
|
-
#
|
11
|
-
# Use `return`, `next`, `break` or `raise` instead.
|
12
|
-
class GetExtensionLicense < SketchUp::Cop
|
13
|
-
|
14
|
-
include RangeHelp
|
15
|
-
include SketchUp::NoCommentDisable
|
16
|
-
|
17
|
-
MSG_INVALID = 'Invalid extension GUID'
|
18
|
-
|
19
|
-
MSG_WRONG_TYPE = 'Only pass in extension GUID from local string '\
|
20
|
-
'literals.'
|
21
|
-
|
22
|
-
MSG_TRAILING_SPACE = 'Extra space in extension GUID'
|
23
|
-
|
24
|
-
def_node_matcher :get_extension_license, <<-PATTERN
|
25
|
-
(send
|
26
|
-
(const
|
27
|
-
(const nil? :Sketchup) :Licensing) :get_extension_license
|
28
|
-
$_)
|
29
|
-
PATTERN
|
30
|
-
|
31
|
-
# rubocop:disable Layout/LineLength
|
32
|
-
EXTENSION_ID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.freeze
|
33
|
-
# rubocop:enable Layout/LineLength
|
34
|
-
|
35
|
-
def on_send(node)
|
36
|
-
argument = get_extension_license(node)
|
37
|
-
return unless argument
|
38
|
-
|
39
|
-
if argument.lvar_type?
|
40
|
-
variable_name = argument.children.first
|
41
|
-
assignment_node = find_assignment(node, variable_name)
|
42
|
-
argument = assignment_node.children.last if assignment_node
|
43
|
-
end
|
44
|
-
|
45
|
-
if argument.str_type?
|
46
|
-
validate_extension_id(argument)
|
47
|
-
else
|
48
|
-
location = argument.loc.expression
|
49
|
-
add_offense(node, location: location, message: MSG_WRONG_TYPE)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def find_assignment(node, variable_name)
|
56
|
-
scope = node
|
57
|
-
until scope.parent.nil?
|
58
|
-
scope = scope.parent
|
59
|
-
scope.each_child_node { |child|
|
60
|
-
# next unless child.is_a?(RuboCop::AST::Node)
|
61
|
-
next unless child.lvasgn_type?
|
62
|
-
next unless child.children.first == variable_name
|
63
|
-
|
64
|
-
return child
|
65
|
-
}
|
66
|
-
end
|
67
|
-
nil
|
68
|
-
end
|
69
|
-
|
70
|
-
def validate_extension_id(node)
|
71
|
-
extension_id = node.str_content
|
72
|
-
|
73
|
-
# Trailing spaces
|
74
|
-
if extension_id.rstrip.size < extension_id.size
|
75
|
-
end_pos = node.loc.end.begin_pos
|
76
|
-
begin_pos = node.loc.begin.end_pos + extension_id.rstrip.size
|
77
|
-
range = range_between(begin_pos, end_pos)
|
78
|
-
add_offense(node, location: range, message: MSG_TRAILING_SPACE)
|
79
|
-
return false
|
80
|
-
end
|
81
|
-
|
82
|
-
# Invalid format.
|
83
|
-
unless EXTENSION_ID_PATTERN.match?(extension_id)
|
84
|
-
range = string_contents_range(node)
|
85
|
-
add_offense(node, location: range, message: MSG_INVALID)
|
86
|
-
return false
|
87
|
-
end
|
88
|
-
|
89
|
-
true
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module SketchupRequirements
|
6
|
+
# Don't attempt to kill the Ruby interpreter by calling `exit` or `exit!`.
|
7
|
+
# SketchUp will trap `exit` and prevent that, with a message in the
|
8
|
+
# console. But `exit!` is not trapped and with terminate SketchUp without
|
9
|
+
# shutting down cleanly.
|
10
|
+
#
|
11
|
+
# Use `return`, `next`, `break` or `raise` instead.
|
12
|
+
class GetExtensionLicense < SketchUp::Cop
|
13
|
+
|
14
|
+
include RangeHelp
|
15
|
+
include SketchUp::NoCommentDisable
|
16
|
+
|
17
|
+
MSG_INVALID = 'Invalid extension GUID'
|
18
|
+
|
19
|
+
MSG_WRONG_TYPE = 'Only pass in extension GUID from local string ' \
|
20
|
+
'literals.'
|
21
|
+
|
22
|
+
MSG_TRAILING_SPACE = 'Extra space in extension GUID'
|
23
|
+
|
24
|
+
def_node_matcher :get_extension_license, <<-PATTERN
|
25
|
+
(send
|
26
|
+
(const
|
27
|
+
(const nil? :Sketchup) :Licensing) :get_extension_license
|
28
|
+
$_)
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
# rubocop:disable Layout/LineLength
|
32
|
+
EXTENSION_ID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.freeze
|
33
|
+
# rubocop:enable Layout/LineLength
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
argument = get_extension_license(node)
|
37
|
+
return unless argument
|
38
|
+
|
39
|
+
if argument.lvar_type?
|
40
|
+
variable_name = argument.children.first
|
41
|
+
assignment_node = find_assignment(node, variable_name)
|
42
|
+
argument = assignment_node.children.last if assignment_node
|
43
|
+
end
|
44
|
+
|
45
|
+
if argument.str_type?
|
46
|
+
validate_extension_id(argument)
|
47
|
+
else
|
48
|
+
location = argument.loc.expression
|
49
|
+
add_offense(node, location: location, message: MSG_WRONG_TYPE)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def find_assignment(node, variable_name)
|
56
|
+
scope = node
|
57
|
+
until scope.parent.nil?
|
58
|
+
scope = scope.parent
|
59
|
+
scope.each_child_node { |child|
|
60
|
+
# next unless child.is_a?(RuboCop::AST::Node)
|
61
|
+
next unless child.lvasgn_type?
|
62
|
+
next unless child.children.first == variable_name
|
63
|
+
|
64
|
+
return child
|
65
|
+
}
|
66
|
+
end
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate_extension_id(node)
|
71
|
+
extension_id = node.str_content
|
72
|
+
|
73
|
+
# Trailing spaces
|
74
|
+
if extension_id.rstrip.size < extension_id.size
|
75
|
+
end_pos = node.loc.end.begin_pos
|
76
|
+
begin_pos = node.loc.begin.end_pos + extension_id.rstrip.size
|
77
|
+
range = range_between(begin_pos, end_pos)
|
78
|
+
add_offense(node, location: range, message: MSG_TRAILING_SPACE)
|
79
|
+
return false
|
80
|
+
end
|
81
|
+
|
82
|
+
# Invalid format.
|
83
|
+
unless EXTENSION_ID_PATTERN.match?(extension_id)
|
84
|
+
range = string_contents_range(node)
|
85
|
+
add_offense(node, location: range, message: MSG_INVALID)
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
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 define
|
11
|
-
# global constants.
|
12
|
-
class GlobalConstants < SketchUp::Cop
|
13
|
-
|
14
|
-
include SketchUp::NoCommentDisable
|
15
|
-
include SketchUp
|
16
|
-
|
17
|
-
MSG = 'Do not introduce global constants.'
|
18
|
-
|
19
|
-
def_node_matcher :namespaced_constant?, <<-PATTERN
|
20
|
-
(casgn
|
21
|
-
(const _ _) ...
|
22
|
-
)
|
23
|
-
PATTERN
|
24
|
-
|
25
|
-
# Constant assignment.
|
26
|
-
def on_casgn(node)
|
27
|
-
return if namespaced_constant?(node)
|
28
|
-
|
29
|
-
namespace = Namespace.new(node.parent_module_name)
|
30
|
-
return unless namespace.top_level?
|
31
|
-
|
32
|
-
add_offense(node, location: :name)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
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 define
|
11
|
+
# global constants.
|
12
|
+
class GlobalConstants < SketchUp::Cop
|
13
|
+
|
14
|
+
include SketchUp::NoCommentDisable
|
15
|
+
include SketchUp
|
16
|
+
|
17
|
+
MSG = 'Do not introduce global constants.'
|
18
|
+
|
19
|
+
def_node_matcher :namespaced_constant?, <<-PATTERN
|
20
|
+
(casgn
|
21
|
+
(const _ _) ...
|
22
|
+
)
|
23
|
+
PATTERN
|
24
|
+
|
25
|
+
# Constant assignment.
|
26
|
+
def on_casgn(node)
|
27
|
+
return if namespaced_constant?(node)
|
28
|
+
|
29
|
+
namespace = Namespace.new(node.parent_module_name)
|
30
|
+
return unless namespace.top_level?
|
31
|
+
|
32
|
+
add_offense(node, location: :name)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
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 pollute
|
11
|
-
# the global namespace by including mix-in modules.
|
12
|
-
class GlobalInclude < SketchUp::Cop
|
13
|
-
|
14
|
-
include SketchUp::NoCommentDisable
|
15
|
-
include SketchUp
|
16
|
-
|
17
|
-
MSG = 'Do not include into global namespace.'
|
18
|
-
|
19
|
-
def_node_matcher :is_include?, <<-PATTERN
|
20
|
-
(send nil? :include ...)
|
21
|
-
PATTERN
|
22
|
-
|
23
|
-
def on_send(node)
|
24
|
-
return unless global_include?(node)
|
25
|
-
|
26
|
-
add_offense(node, location: :selector)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def global_include?(node)
|
32
|
-
is_include?(node) && global_namespace?(node)
|
33
|
-
end
|
34
|
-
|
35
|
-
def global_namespace?(node)
|
36
|
-
%w[Kernel Object].include?(node.parent_module_name)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
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 pollute
|
11
|
+
# the global namespace by including mix-in modules.
|
12
|
+
class GlobalInclude < SketchUp::Cop
|
13
|
+
|
14
|
+
include SketchUp::NoCommentDisable
|
15
|
+
include SketchUp
|
16
|
+
|
17
|
+
MSG = 'Do not include into global namespace.'
|
18
|
+
|
19
|
+
def_node_matcher :is_include?, <<-PATTERN
|
20
|
+
(send nil? :include ...)
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
return unless global_include?(node)
|
25
|
+
|
26
|
+
add_offense(node, location: :selector)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def global_include?(node)
|
32
|
+
is_include?(node) && global_namespace?(node)
|
33
|
+
end
|
34
|
+
|
35
|
+
def global_namespace?(node)
|
36
|
+
%w[Kernel Object].include?(node.parent_module_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
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 define
|
11
|
-
# global methods.
|
12
|
-
class GlobalMethods < SketchUp::Cop
|
13
|
-
|
14
|
-
include SketchUp::NoCommentDisable
|
15
|
-
include SketchUp
|
16
|
-
|
17
|
-
MSG = 'Do not introduce global methods.'
|
18
|
-
|
19
|
-
# Reference: http://www.rubydoc.info/gems/rubocop/RuboCop/NodePattern
|
20
|
-
#
|
21
|
-
# Matchers for methods defined with this syntax:
|
22
|
-
#
|
23
|
-
# def Example.foo
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# def (Example::Foo).bar
|
27
|
-
# end
|
28
|
-
|
29
|
-
def_node_matcher :class_method?, <<-PATTERN
|
30
|
-
(defs
|
31
|
-
(const _ _) ...
|
32
|
-
)
|
33
|
-
PATTERN
|
34
|
-
|
35
|
-
def_node_matcher :class_method, <<-PATTERN
|
36
|
-
(defs
|
37
|
-
{
|
38
|
-
(const nil? $_)
|
39
|
-
(const (const nil? $_) ...)
|
40
|
-
}
|
41
|
-
...
|
42
|
-
)
|
43
|
-
PATTERN
|
44
|
-
|
45
|
-
def on_def(node)
|
46
|
-
if class_method?(node)
|
47
|
-
class_method_parent = class_method(node)
|
48
|
-
namespace = Namespace.new(class_method_parent.to_s)
|
49
|
-
else
|
50
|
-
# If a method is defined inside a block then parent_module_name
|
51
|
-
# will return nil.
|
52
|
-
return if node.parent_module_name.nil?
|
53
|
-
|
54
|
-
namespace = Namespace.new(node.parent_module_name)
|
55
|
-
end
|
56
|
-
return unless namespace.top_level?
|
57
|
-
|
58
|
-
add_offense(node, location: :name)
|
59
|
-
end
|
60
|
-
alias on_defs on_def
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
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 define
|
11
|
+
# global methods.
|
12
|
+
class GlobalMethods < SketchUp::Cop
|
13
|
+
|
14
|
+
include SketchUp::NoCommentDisable
|
15
|
+
include SketchUp
|
16
|
+
|
17
|
+
MSG = 'Do not introduce global methods.'
|
18
|
+
|
19
|
+
# Reference: http://www.rubydoc.info/gems/rubocop/RuboCop/NodePattern
|
20
|
+
#
|
21
|
+
# Matchers for methods defined with this syntax:
|
22
|
+
#
|
23
|
+
# def Example.foo
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# def (Example::Foo).bar
|
27
|
+
# end
|
28
|
+
|
29
|
+
def_node_matcher :class_method?, <<-PATTERN
|
30
|
+
(defs
|
31
|
+
(const _ _) ...
|
32
|
+
)
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher :class_method, <<-PATTERN
|
36
|
+
(defs
|
37
|
+
{
|
38
|
+
(const nil? $_)
|
39
|
+
(const (const nil? $_) ...)
|
40
|
+
}
|
41
|
+
...
|
42
|
+
)
|
43
|
+
PATTERN
|
44
|
+
|
45
|
+
def on_def(node)
|
46
|
+
if class_method?(node)
|
47
|
+
class_method_parent = class_method(node)
|
48
|
+
namespace = Namespace.new(class_method_parent.to_s)
|
49
|
+
else
|
50
|
+
# If a method is defined inside a block then parent_module_name
|
51
|
+
# will return nil.
|
52
|
+
return if node.parent_module_name.nil?
|
53
|
+
|
54
|
+
namespace = Namespace.new(node.parent_module_name)
|
55
|
+
end
|
56
|
+
return unless namespace.top_level?
|
57
|
+
|
58
|
+
add_offense(node, location: :name)
|
59
|
+
end
|
60
|
+
alias on_defs on_def
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|