rubocop-require_tools 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +86 -36
- data/README.md +2 -2
- data/lib/rubocop/cop/require/missing_require_statement.rb +25 -2
- data/lib/rubocop/helper/state.rb +48 -13
- data/lib/rubocop/require_tools/version.rb +1 -1
- data/rubocop-require_tools.gemspec +2 -2
- metadata +7 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92a502fba8cea8224ca73240fca61774a3a3c7dd9a572ba902da7cd5cdce804a
|
|
4
|
+
data.tar.gz: 7dcd0456375b56dfeaff84693ee49988e0b59efcb228622fbab249704645b99c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abcd24dd207443eeba31b9a7ab62444dea88c2df9bf619980136622570bc1eaa6aa935f5aa0cf1a220519f6fa105e21ced27f6510dd78521ce2edfad020444b5
|
|
7
|
+
data.tar.gz: 1c5570d3ff8bc845f313d9825a4d6b63f03b1fdfccd3b6cca0ee7a16b7cb9cea4a4f4882c2f65a7841348841f377c93c0fc76cd8ae4a42bd169770ea68f7effa
|
data/Gemfile.lock
CHANGED
|
@@ -1,57 +1,107 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-require_tools (0.
|
|
5
|
-
rubocop (
|
|
4
|
+
rubocop-require_tools (0.2.0)
|
|
5
|
+
rubocop (>= 0.49.1)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
ast (2.3
|
|
11
|
-
coderay (1.1.
|
|
12
|
-
diff-lcs (1.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
10
|
+
ast (2.4.3)
|
|
11
|
+
coderay (1.1.3)
|
|
12
|
+
diff-lcs (1.6.2)
|
|
13
|
+
io-console (0.8.2)
|
|
14
|
+
json (2.19.5)
|
|
15
|
+
language_server-protocol (3.17.0.5)
|
|
16
|
+
lint_roller (1.1.0)
|
|
17
|
+
method_source (1.1.0)
|
|
18
|
+
parallel (2.1.0)
|
|
19
|
+
parser (3.3.11.1)
|
|
20
|
+
ast (~> 2.4.1)
|
|
21
|
+
racc
|
|
22
|
+
prism (1.9.0)
|
|
23
|
+
pry (0.16.0)
|
|
24
|
+
coderay (~> 1.1)
|
|
25
|
+
method_source (~> 1.0)
|
|
26
|
+
reline (>= 0.6.0)
|
|
27
|
+
racc (1.8.1)
|
|
28
|
+
rainbow (3.1.1)
|
|
29
|
+
rake (13.4.2)
|
|
30
|
+
regexp_parser (2.12.0)
|
|
31
|
+
reline (0.6.3)
|
|
32
|
+
io-console (~> 0.5)
|
|
33
|
+
rspec (3.13.2)
|
|
34
|
+
rspec-core (~> 3.13.0)
|
|
35
|
+
rspec-expectations (~> 3.13.0)
|
|
36
|
+
rspec-mocks (~> 3.13.0)
|
|
37
|
+
rspec-core (3.13.6)
|
|
38
|
+
rspec-support (~> 3.13.0)
|
|
39
|
+
rspec-expectations (3.13.5)
|
|
30
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
-
rspec-support (~> 3.
|
|
32
|
-
rspec-mocks (3.
|
|
41
|
+
rspec-support (~> 3.13.0)
|
|
42
|
+
rspec-mocks (3.13.8)
|
|
33
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
|
-
rspec-support (~> 3.
|
|
35
|
-
rspec-support (3.7
|
|
36
|
-
rubocop (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
rspec-support (~> 3.13.0)
|
|
45
|
+
rspec-support (3.13.7)
|
|
46
|
+
rubocop (1.86.2)
|
|
47
|
+
json (~> 2.3)
|
|
48
|
+
language_server-protocol (~> 3.17.0.2)
|
|
49
|
+
lint_roller (~> 1.1.0)
|
|
50
|
+
parallel (>= 1.10)
|
|
51
|
+
parser (>= 3.3.0.2)
|
|
40
52
|
rainbow (>= 2.2.2, < 4.0)
|
|
53
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
54
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
41
55
|
ruby-progressbar (~> 1.7)
|
|
42
|
-
unicode-display_width (
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
57
|
+
rubocop-ast (1.49.1)
|
|
58
|
+
parser (>= 3.3.7.2)
|
|
59
|
+
prism (~> 1.7)
|
|
60
|
+
ruby-progressbar (1.13.0)
|
|
61
|
+
unicode-display_width (3.2.0)
|
|
62
|
+
unicode-emoji (~> 4.1)
|
|
63
|
+
unicode-emoji (4.2.0)
|
|
45
64
|
|
|
46
65
|
PLATFORMS
|
|
66
|
+
arm64-darwin-25
|
|
47
67
|
ruby
|
|
48
68
|
|
|
49
69
|
DEPENDENCIES
|
|
50
|
-
bundler (~>
|
|
70
|
+
bundler (~> 4.0)
|
|
51
71
|
pry
|
|
52
|
-
rake (~>
|
|
72
|
+
rake (~> 13.0)
|
|
53
73
|
rspec (~> 3.0)
|
|
54
74
|
rubocop-require_tools!
|
|
55
75
|
|
|
76
|
+
CHECKSUMS
|
|
77
|
+
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
|
|
78
|
+
coderay (1.1.3) sha256=dc530018a4684512f8f38143cd2a096c9f02a1fc2459edcfe534787a7fc77d4b
|
|
79
|
+
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
|
80
|
+
io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
|
|
81
|
+
json (2.19.5) sha256=218a18553e4801d579ca7e0f5bc72bafd776d7397238a1fb4e74db5b0a812c59
|
|
82
|
+
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
|
|
83
|
+
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
84
|
+
method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
|
|
85
|
+
parallel (2.1.0) sha256=b35258865c2e31134c5ecb708beaaf6772adf9d5efae28e93e99260877b09356
|
|
86
|
+
parser (3.3.11.1) sha256=d17ace7aabe3e72c3cc94043714be27cc6f852f104d81aa284c2281aecc65d54
|
|
87
|
+
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
|
|
88
|
+
pry (0.16.0) sha256=d76c69065698ed1f85e717bd33d7942c38a50868f6b0673c636192b3d1b6054e
|
|
89
|
+
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
|
|
90
|
+
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
|
|
91
|
+
rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
|
|
92
|
+
regexp_parser (2.12.0) sha256=35a916a1d63190ab5c9009457136ae5f3c0c7512d60291d0d1378ba18ce08ebb
|
|
93
|
+
reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
|
|
94
|
+
rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
|
|
95
|
+
rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
|
|
96
|
+
rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
|
|
97
|
+
rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
|
|
98
|
+
rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
|
|
99
|
+
rubocop (1.86.2) sha256=bb2e97f635eda42c448f2588f4a6ff78f221b8bdfdf65b1e9b07fbd57521b45d
|
|
100
|
+
rubocop-ast (1.49.1) sha256=4412f3ee70f6fe4546cc489548e0f6fcf76cafcfa80fa03af67098ffed755035
|
|
101
|
+
rubocop-require_tools (0.2.0)
|
|
102
|
+
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
|
|
103
|
+
unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
|
|
104
|
+
unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
|
|
105
|
+
|
|
56
106
|
BUNDLED WITH
|
|
57
|
-
|
|
107
|
+
4.0.10
|
data/README.md
CHANGED
|
@@ -17,7 +17,7 @@ And then execute:
|
|
|
17
17
|
Then, require this extension in your project's `.rubocop.yml`:
|
|
18
18
|
|
|
19
19
|
```YAML
|
|
20
|
-
require: rubocop
|
|
20
|
+
require: rubocop/require_tools
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Development
|
|
@@ -36,4 +36,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
36
36
|
|
|
37
37
|
## Code of Conduct
|
|
38
38
|
|
|
39
|
-
Everyone interacting in the rubocop-require_tools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
|
39
|
+
Everyone interacting in the rubocop-require_tools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/milch/rubocop-require_tools/blob/master/CODE_OF_CONDUCT.md).
|
|
@@ -63,6 +63,19 @@ module RuboCop
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
def add_offense(node, location: nil, message:)
|
|
67
|
+
# Work around breaking API changes between rubocop 0.49.1 and later (...)
|
|
68
|
+
signature_old = %i[node loc message severity]
|
|
69
|
+
param_info = RuboCop::Cop::Cop.instance_method(:add_offense).parameters
|
|
70
|
+
if param_info.map(&:last) == signature_old
|
|
71
|
+
super(node, location || :expression, message)
|
|
72
|
+
elsif location
|
|
73
|
+
super(node, location: location, message: message)
|
|
74
|
+
else
|
|
75
|
+
super(node, message: message)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
66
79
|
def_node_matcher :extract_inner_const, <<-PATTERN
|
|
67
80
|
(const $!nil? _)
|
|
68
81
|
PATTERN
|
|
@@ -103,7 +116,17 @@ module RuboCop
|
|
|
103
116
|
const_assign_name = extract_const_assignment(node)
|
|
104
117
|
return unless const_assign_name
|
|
105
118
|
|
|
106
|
-
|
|
119
|
+
# When the assigned value is itself a constant reference, the assignment is an
|
|
120
|
+
# alias (e.g. `Foo = Bar::Baz`). Track the target so member access through the
|
|
121
|
+
# alias (`Foo::QUX`) can be resolved to the real constant later.
|
|
122
|
+
value_node = node.children[2]
|
|
123
|
+
alias_target = nil
|
|
124
|
+
if value_node.kind_of?(RuboCop::AST::Node) && value_node.type == :const
|
|
125
|
+
consts = find_consts(value_node)
|
|
126
|
+
alias_target = consts.join('::') if consts
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
self.timeline << { event: :const_assign, name: const_assign_name, alias_target: alias_target }
|
|
107
130
|
|
|
108
131
|
{ skip: node.children }
|
|
109
132
|
end
|
|
@@ -183,7 +206,7 @@ module RuboCop
|
|
|
183
206
|
when :const_undef
|
|
184
207
|
state.undefine_const(const_name: event[:name])
|
|
185
208
|
when :const_assign
|
|
186
|
-
state.const_assigned(const_name: event[:name])
|
|
209
|
+
state.const_assigned(const_name: event[:name], alias_target: event[:alias_target])
|
|
187
210
|
|
|
188
211
|
previous_errors = err_indices.map { |e| timeline[e] }
|
|
189
212
|
outdated = outdated_errors(previous_errors, state)
|
data/lib/rubocop/helper/state.rb
CHANGED
|
@@ -4,10 +4,12 @@ module RuboCop
|
|
|
4
4
|
class State
|
|
5
5
|
attr_accessor :defined_constants
|
|
6
6
|
attr_accessor :const_stack
|
|
7
|
+
attr_accessor :aliases
|
|
7
8
|
|
|
8
9
|
def initialize
|
|
9
10
|
self.defined_constants = []
|
|
10
11
|
self.const_stack = []
|
|
12
|
+
self.aliases = {}
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def require(file: nil)
|
|
@@ -29,19 +31,12 @@ module RuboCop
|
|
|
29
31
|
def access_const(const_name: nil, local_only: false)
|
|
30
32
|
name = const_name.to_s.sub(/^:*/, '').sub(/:*$/, '') # Strip leading/trailing ::
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
prefixes = self.const_stack.reduce([]) { |a, c| a << [a.last, c].compact.join('::') }
|
|
34
|
+
result = resolve_const(name, local_only: local_only)
|
|
34
35
|
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
result
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
result ||= self.defined_constants.find { |c| name == c } # Defined in this file, other module/class
|
|
42
|
-
prefixes.each do |prefix|
|
|
43
|
-
result ||= self.defined_constants.find { |c| [name, "#{prefix}::#{name}"].include? c } # Defined in this file, other module/class
|
|
44
|
-
result ||= prefix == name # Defined in this file, in current module/class
|
|
36
|
+
# If the name (or its leading segment) is an alias, resolve the alias target and
|
|
37
|
+
# retry. e.g. with `Foo = Bar::Baz`, accessing `Foo::QUX` resolves `Bar::Baz::QUX`.
|
|
38
|
+
if !result && (aliased = expand_alias(name))
|
|
39
|
+
result = resolve_const(aliased, local_only: local_only)
|
|
45
40
|
end
|
|
46
41
|
|
|
47
42
|
return result
|
|
@@ -63,10 +58,50 @@ module RuboCop
|
|
|
63
58
|
self.const_stack.pop
|
|
64
59
|
end
|
|
65
60
|
|
|
66
|
-
def const_assigned(const_name: nil)
|
|
61
|
+
def const_assigned(const_name: nil, alias_target: nil)
|
|
67
62
|
full_name = (self.const_stack + [const_name]).join('::')
|
|
68
63
|
self.defined_constants << full_name
|
|
69
64
|
self.defined_constants.uniq!
|
|
65
|
+
|
|
66
|
+
return unless alias_target
|
|
67
|
+
|
|
68
|
+
# Register the alias under both the fully-qualified name and the bare name so it can
|
|
69
|
+
# be resolved whether referenced from inside or outside its enclosing namespace.
|
|
70
|
+
self.aliases[full_name] = alias_target
|
|
71
|
+
self.aliases[const_name.to_s] = alias_target
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def resolve_const(name, local_only: false)
|
|
77
|
+
# If const_stack is ["A", "B", "C"] all of A, A::B, A::B::C are valid lookup combinations
|
|
78
|
+
prefixes = self.const_stack.reduce([]) { |a, c| a << [a.last, c].compact.join('::') }
|
|
79
|
+
|
|
80
|
+
# I use const_get here because in testing const_get and const_defined? have yielded different results
|
|
81
|
+
unless local_only
|
|
82
|
+
result = Object.const_get(name) rescue nil # Defined elsewhere, top-level
|
|
83
|
+
result ||= self.defined_constants.find { |c| Object.const_get("#{c}::#{name}") rescue nil } # Defined elsewhere, nested
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
result ||= self.defined_constants.find { |c| name == c } # Defined in this file, other module/class
|
|
87
|
+
prefixes.each do |prefix|
|
|
88
|
+
result ||= self.defined_constants.find { |c| [name, "#{prefix}::#{name}"].include? c } # Defined in this file, other module/class
|
|
89
|
+
result ||= prefix == name # Defined in this file, in current module/class
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
return result
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# If `name`'s longest leading segment is a known alias, return `name` with that segment
|
|
96
|
+
# replaced by the alias target (e.g. "Foo::QUX" => "Bar::Baz::QUX"). Returns nil otherwise.
|
|
97
|
+
def expand_alias(name)
|
|
98
|
+
segments = name.split('::')
|
|
99
|
+
segments.length.downto(1) do |i|
|
|
100
|
+
prefix = segments[0...i].join('::')
|
|
101
|
+
next unless self.aliases.key?(prefix)
|
|
102
|
+
return ([self.aliases[prefix]] + segments[i..-1]).join('::')
|
|
103
|
+
end
|
|
104
|
+
nil
|
|
70
105
|
end
|
|
71
106
|
end
|
|
72
107
|
end
|
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
|
|
31
31
|
spec.add_development_dependency 'pry'
|
|
32
32
|
|
|
33
|
-
spec.add_development_dependency 'bundler', '~>
|
|
34
|
-
spec.add_development_dependency 'rake', '~>
|
|
33
|
+
spec.add_development_dependency 'bundler', '~> 4.0'
|
|
34
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
35
35
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
36
36
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-require_tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Manu Wallner
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rubocop
|
|
@@ -44,28 +43,28 @@ dependencies:
|
|
|
44
43
|
requirements:
|
|
45
44
|
- - "~>"
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
46
|
+
version: '4.0'
|
|
48
47
|
type: :development
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - "~>"
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
53
|
+
version: '4.0'
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
55
|
name: rake
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
58
57
|
requirements:
|
|
59
58
|
- - "~>"
|
|
60
59
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
60
|
+
version: '13.0'
|
|
62
61
|
type: :development
|
|
63
62
|
prerelease: false
|
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
64
|
requirements:
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
67
|
+
version: '13.0'
|
|
69
68
|
- !ruby/object:Gem::Dependency
|
|
70
69
|
name: rspec
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -111,7 +110,6 @@ homepage: https://github.com/milch/rubocop-require_tools
|
|
|
111
110
|
licenses:
|
|
112
111
|
- MIT
|
|
113
112
|
metadata: {}
|
|
114
|
-
post_install_message:
|
|
115
113
|
rdoc_options: []
|
|
116
114
|
require_paths:
|
|
117
115
|
- lib
|
|
@@ -126,9 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
124
|
- !ruby/object:Gem::Version
|
|
127
125
|
version: '0'
|
|
128
126
|
requirements: []
|
|
129
|
-
|
|
130
|
-
rubygems_version: 2.7.4
|
|
131
|
-
signing_key:
|
|
127
|
+
rubygems_version: 4.0.10
|
|
132
128
|
specification_version: 4
|
|
133
129
|
summary: Checks require statements in your code
|
|
134
130
|
test_files: []
|