rubocop-ast 0.4.0 → 0.6.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/lib/rubocop/ast.rb +1 -0
- data/lib/rubocop/ast/node.rb +13 -1
- data/lib/rubocop/ast/node/const_node.rb +2 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +14 -24
- data/lib/rubocop/ast/node/regexp_node.rb +8 -4
- data/lib/rubocop/ast/processed_source.rb +5 -4
- data/lib/rubocop/ast/rubocop_compatibility.rb +31 -0
- data/lib/rubocop/ast/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f0c94d6021f2223c413d1751c4e816346b740cf01663e5444325256ba987aa
|
4
|
+
data.tar.gz: 010a37da8da2e08bea4785821709b9e10cdedb02e133f33b1b8a12051939517e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac8387283324c91278d848e1411cdede002cda15d00e20d2a889a5f7b4b37eed217e05e5538cfc99dfd2022ea68afae87eb4698db9d58aef2e08f15f3e5930e2
|
7
|
+
data.tar.gz: 3505c65f6921744d681f226f9f2e476a662c2da564db8f2534dd53a5cd17d15a4eadf839e7bf8d9e4bd8d769f0351527ad1a53c7da5a11cc3dc6f4e760a7c955
|
data/lib/rubocop/ast.rb
CHANGED
@@ -63,6 +63,7 @@ require_relative 'ast/node/while_node'
|
|
63
63
|
require_relative 'ast/node/yield_node'
|
64
64
|
require_relative 'ast/builder'
|
65
65
|
require_relative 'ast/processed_source'
|
66
|
+
require_relative 'ast/rubocop_compatibility'
|
66
67
|
require_relative 'ast/token'
|
67
68
|
require_relative 'ast/traversal'
|
68
69
|
require_relative 'ast/version'
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -92,6 +92,16 @@ module RuboCop
|
|
92
92
|
@mutable_attributes[:parent] = node
|
93
93
|
end
|
94
94
|
|
95
|
+
# @return [Boolean]
|
96
|
+
def parent?
|
97
|
+
!!parent
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [Boolean]
|
101
|
+
def root?
|
102
|
+
!parent
|
103
|
+
end
|
104
|
+
|
95
105
|
def complete!
|
96
106
|
@mutable_attributes.freeze
|
97
107
|
each_child_node(&:complete!)
|
@@ -299,8 +309,10 @@ module RuboCop
|
|
299
309
|
self
|
300
310
|
end
|
301
311
|
|
312
|
+
# Note: Some rare nodes may have no source, like `s(:args)` in `foo {}`
|
313
|
+
# @return [String, nil]
|
302
314
|
def source
|
303
|
-
loc.expression
|
315
|
+
loc.expression&.source
|
304
316
|
end
|
305
317
|
|
306
318
|
def source_range
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
#
|
43
43
|
# @return [Boolean] whether the dispatched method is a macro method
|
44
44
|
def macro?
|
45
|
-
!receiver &&
|
45
|
+
!receiver && in_macro_scope?
|
46
46
|
end
|
47
47
|
|
48
48
|
# Checks whether the dispatched method is an access modifier.
|
@@ -222,31 +222,21 @@ module RuboCop
|
|
222
222
|
|
223
223
|
private
|
224
224
|
|
225
|
-
def_node_matcher :
|
226
|
-
{
|
227
|
-
|
228
|
-
|
229
|
-
|
225
|
+
def_node_matcher :in_macro_scope?, <<~PATTERN
|
226
|
+
{
|
227
|
+
root? # Either a root node,
|
228
|
+
^{ # or the parent is...
|
229
|
+
sclass class module class_constructor? # a class-like node
|
230
|
+
[ { # or some "wrapper"
|
231
|
+
kwbegin begin block
|
232
|
+
(if _condition <%0 _>) # note: we're excluding the condition of `if` nodes
|
233
|
+
}
|
234
|
+
#in_macro_scope? # that is itself in a macro scope
|
235
|
+
]
|
236
|
+
}
|
237
|
+
}
|
230
238
|
PATTERN
|
231
239
|
|
232
|
-
# Check if a node's parent is a kwbegin wrapper within a macro scope
|
233
|
-
#
|
234
|
-
# @param parent [Node] parent of the node being checked
|
235
|
-
#
|
236
|
-
# @return [Boolean] true if the parent is a kwbegin in a macro scope
|
237
|
-
def macro_kwbegin_wrapper?(parent)
|
238
|
-
parent.kwbegin_type? && macro_scope?(parent)
|
239
|
-
end
|
240
|
-
|
241
|
-
# Check if a node does not have a parent
|
242
|
-
#
|
243
|
-
# @param node [Node]
|
244
|
-
#
|
245
|
-
# @return [Boolean] if the parent is nil
|
246
|
-
def root_node?(node)
|
247
|
-
node.parent.nil?
|
248
|
-
end
|
249
|
-
|
250
240
|
def_node_matcher :adjacent_def_modifier?, <<~PATTERN
|
251
241
|
(send nil? _ ({def defs} ...))
|
252
242
|
PATTERN
|
@@ -14,12 +14,9 @@ module RuboCop
|
|
14
14
|
o: 0
|
15
15
|
}.freeze
|
16
16
|
|
17
|
-
# Note: The 'o' option is ignored.
|
18
|
-
#
|
19
17
|
# @return [Regexp] a regexp of this node
|
20
18
|
def to_regexp
|
21
|
-
|
22
|
-
Regexp.new(content, option)
|
19
|
+
Regexp.new(content, options)
|
23
20
|
end
|
24
21
|
|
25
22
|
# @return [RuboCop::AST::Node] a regopt node
|
@@ -27,6 +24,13 @@ module RuboCop
|
|
27
24
|
children.last
|
28
25
|
end
|
29
26
|
|
27
|
+
# Note: The 'o' option is ignored.
|
28
|
+
#
|
29
|
+
# @return [Integer] the Regexp option bits as returned by Regexp#options
|
30
|
+
def options
|
31
|
+
regopt.children.map { |opt| OPTIONS.fetch(opt) }.inject(0, :|)
|
32
|
+
end
|
33
|
+
|
30
34
|
# @return [String] a string of regexp content
|
31
35
|
def content
|
32
36
|
children.select(&:str_type?).map(&:str_content).join
|
@@ -229,9 +229,9 @@ module RuboCop
|
|
229
229
|
when 2.7
|
230
230
|
require 'parser/ruby27'
|
231
231
|
Parser::Ruby27
|
232
|
-
when 2.8
|
233
|
-
require 'parser/
|
234
|
-
Parser::
|
232
|
+
when 2.8, 3.0
|
233
|
+
require 'parser/ruby30'
|
234
|
+
Parser::Ruby30
|
235
235
|
else
|
236
236
|
raise ArgumentError,
|
237
237
|
"RuboCop found unknown Ruby version: #{ruby_version.inspect}"
|
@@ -269,7 +269,8 @@ module RuboCop
|
|
269
269
|
# is passed as a method argument. In this case tokens are interleaved by
|
270
270
|
# heredoc contents' tokens.
|
271
271
|
def sorted_tokens
|
272
|
-
|
272
|
+
# Use stable sort.
|
273
|
+
@sorted_tokens ||= tokens.sort_by.with_index { |token, i| [token.begin_pos, i] }
|
273
274
|
end
|
274
275
|
|
275
276
|
def source_range(range_or_node)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# ...
|
5
|
+
module AST
|
6
|
+
# Responsible for compatibility with main gem
|
7
|
+
# @api private
|
8
|
+
module RuboCopCompatibility
|
9
|
+
INCOMPATIBLE_COPS = {
|
10
|
+
'0.89.0' => 'Layout/LineLength',
|
11
|
+
'0.92.0' => 'Style/MixinUsage'
|
12
|
+
}.freeze
|
13
|
+
def rubocop_loaded
|
14
|
+
loaded = Gem::Version.new(RuboCop::Version::STRING)
|
15
|
+
incompatible = INCOMPATIBLE_COPS.select do |k, _v|
|
16
|
+
loaded < Gem::Version.new(k)
|
17
|
+
end.values
|
18
|
+
return if incompatible.empty?
|
19
|
+
|
20
|
+
warn <<~WARNING
|
21
|
+
*** WARNING – Incompatible versions of `rubocop` and `rubocop-ast`
|
22
|
+
You may encounter issues with the following \
|
23
|
+
Cop#{'s' if incompatible.size > 1}: #{incompatible.join(', ')}
|
24
|
+
Please upgrade rubocop to at least v#{INCOMPATIBLE_COPS.keys.last}
|
25
|
+
WARNING
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
extend RuboCopCompatibility
|
30
|
+
end
|
31
|
+
end
|
data/lib/rubocop/ast/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-09-
|
13
|
+
date: 2020-09-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.7.1.
|
21
|
+
version: 2.7.1.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 2.7.1.
|
28
|
+
version: 2.7.1.5
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: bundler
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/rubocop/ast/node/yield_node.rb
|
117
117
|
- lib/rubocop/ast/node_pattern.rb
|
118
118
|
- lib/rubocop/ast/processed_source.rb
|
119
|
+
- lib/rubocop/ast/rubocop_compatibility.rb
|
119
120
|
- lib/rubocop/ast/sexp.rb
|
120
121
|
- lib/rubocop/ast/token.rb
|
121
122
|
- lib/rubocop/ast/traversal.rb
|