rubocop-sketchup 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d69761990813abecd3a20633643a490c07df1a341c0ba6f36131d6aedf682fe3
4
- data.tar.gz: 40ccb6f930c97bb0a716ac72d36c4963849dd40f9cd4e69f3bc3d26b86e3c6d7
3
+ metadata.gz: e9935671119993e41eef012a5f69fca2709a59d7db06d28c2e89ff9ea5721aa7
4
+ data.tar.gz: 05cba02d5fa27e8eab8b32cae46d586c68d5fec8922b959febf89ebd36660ced
5
5
  SHA512:
6
- metadata.gz: 23b2fc55403fa6bc471e2769d7121418944901d0d30b75fa36bb7aa49c0bbdd1aa95dc1f26248cbfe5ddd1a29f88c807dcbf022612a78ff3e4029449920f1337
7
- data.tar.gz: 7c389ffdda8af9df21dd805086af0a2e5863415296f9922c69c12a132402dfc5f188fca09486089bc4fb2a1c01560fd825748ac3abe7050229141f9bdf002352
6
+ metadata.gz: 06e197b228db557e7d1b0ab9eeec6550e9a70a8e64fa4079f6f4e093249f0057390f9ce6f4270d15e1be956e36b684ff66f5e926a55d0a2b862e33d113a8a3c2
7
+ data.tar.gz: 54242ae1e4bb983394e9976f02893d98794ae46971755751bdbcea1b4ecdfd9e1c6e3c9e4dde6cd995e7977b788d8ec5fa3dab693723bdd84f30dd3717b8a590
data/Gemfile CHANGED
@@ -9,6 +9,8 @@ group :test do
9
9
  gem 'rake', '~> 12.0', require: false
10
10
  gem 'rspec', '~> 3.7', require: false
11
11
  gem 'rubocop-performance', '~> 1.11.0', require: false
12
+ gem 'rubocop-rake', '~> 0.6.0', require: false
13
+ gem 'rubocop-rspec', require: false
12
14
  gem 'simplecov', '~> 0.10', require: false
13
15
  end
14
16
 
@@ -4,6 +4,35 @@ module RuboCop
4
4
  module SketchUp
5
5
  module NamespaceChecker
6
6
 
7
+ extend NodePattern::Macros
8
+
9
+ # Example:
10
+ # Array.include(Example)
11
+ def_node_matcher :klass_include, <<-PATTERN
12
+ (send
13
+ (const nil? $_) { :include | :extend } _)
14
+ PATTERN
15
+
16
+ # Example:
17
+ # class Array
18
+ # include Example
19
+ # end
20
+ def_node_matcher :klass_scope_include, <<-PATTERN
21
+ (
22
+ {
23
+ class (const nil? $_) nil? |
24
+ module (const nil? $_)
25
+ }
26
+ (send nil? { :include | :extend } _))
27
+ PATTERN
28
+
29
+ # Example:
30
+ # include Example
31
+ def_node_matcher :include_call?, <<-PATTERN
32
+ (send nil? { :include | :extend } _)
33
+ PATTERN
34
+
35
+
7
36
  def on_class(node)
8
37
  check_namespace(node)
9
38
  end
@@ -22,12 +51,40 @@ module RuboCop
22
51
  check_namespace(node)
23
52
  end
24
53
 
54
+ def on_send(node)
55
+ klass = klass_include(node) || klass_scope_include(node.parent)
56
+
57
+ if klass
58
+ namespace = SketchUp::Namespace.new(klass.to_s)
59
+ return unless namespaces.include?(namespace.first)
60
+ else
61
+ # If klass is `nil` we either don't have a `include` call or we're in
62
+ # global namespace.
63
+ return unless top_level_include?(node)
64
+ end
65
+
66
+ add_offense(node, location: :selector, severity: :error)
67
+ end
68
+
25
69
  def check_namespace(node)
26
70
  return unless in_namespace?(node)
27
71
 
28
72
  add_offense(node, location: :name, severity: :error)
29
73
  end
30
74
 
75
+ def top_level?(node)
76
+ # parent_module_name might return nil if for instance a method is
77
+ # defined within a block. (Apparently that is possible...)
78
+ return false if node.parent_module_name.nil?
79
+
80
+ namespace = SketchUp::Namespace.new(node.parent_module_name)
81
+ namespace.top_level?
82
+ end
83
+
84
+ def top_level_include?(node)
85
+ include_call?(node) && top_level?(node)
86
+ end
87
+
31
88
  def in_namespace?(node)
32
89
  # parent_module_name might return nil if for instance a method is
33
90
  # defined within a block. (Apparently that is possible...)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module SketchUp
5
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-sketchup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trimble Inc, SketchUp Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-25 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop