rubocop-ast 1.51.0 → 1.52.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/builder.rb +2 -113
- data/lib/rubocop/ast/builder_extensions.rb +118 -0
- data/lib/rubocop/ast/node.rb +1 -1
- data/lib/rubocop/ast/node_pattern/lexer.rex.rb +1 -1
- data/lib/rubocop/ast/node_pattern/parser.racc.rb +1 -1
- data/lib/rubocop/ast/parser_source.rb +76 -0
- data/lib/rubocop/ast/prism_compiler.rb +2106 -0
- data/lib/rubocop/ast/prism_lexer.rb +779 -0
- data/lib/rubocop/ast/prism_parser.rb +211 -0
- data/lib/rubocop/ast/processed_source.rb +26 -27
- data/lib/rubocop/ast/sexp.rb +1 -1
- data/lib/rubocop/ast/vendor/parser/LICENSE.txt +26 -0
- data/lib/rubocop/ast/vendor/parser/ast/node.rb +40 -0
- data/lib/rubocop/ast/vendor/parser/clobbering_error.rb +13 -0
- data/lib/rubocop/ast/vendor/parser/deprecation.rb +13 -0
- data/lib/rubocop/ast/vendor/parser/diagnostic/engine.rb +104 -0
- data/lib/rubocop/ast/vendor/parser/diagnostic.rb +163 -0
- data/lib/rubocop/ast/vendor/parser/messages.rb +125 -0
- data/lib/rubocop/ast/vendor/parser/meta.rb +48 -0
- data/lib/rubocop/ast/vendor/parser/source/buffer.rb +369 -0
- data/lib/rubocop/ast/vendor/parser/source/comment/associator.rb +233 -0
- data/lib/rubocop/ast/vendor/parser/source/comment.rb +134 -0
- data/lib/rubocop/ast/vendor/parser/source/map/collection.rb +18 -0
- data/lib/rubocop/ast/vendor/parser/source/map/condition.rb +21 -0
- data/lib/rubocop/ast/vendor/parser/source/map/constant.rb +32 -0
- data/lib/rubocop/ast/vendor/parser/source/map/definition.rb +23 -0
- data/lib/rubocop/ast/vendor/parser/source/map/for.rb +19 -0
- data/lib/rubocop/ast/vendor/parser/source/map/heredoc.rb +19 -0
- data/lib/rubocop/ast/vendor/parser/source/map/index.rb +33 -0
- data/lib/rubocop/ast/vendor/parser/source/map/keyword.rb +20 -0
- data/lib/rubocop/ast/vendor/parser/source/map/method_definition.rb +25 -0
- data/lib/rubocop/ast/vendor/parser/source/map/objc_kwarg.rb +19 -0
- data/lib/rubocop/ast/vendor/parser/source/map/operator.rb +17 -0
- data/lib/rubocop/ast/vendor/parser/source/map/rescue_body.rb +21 -0
- data/lib/rubocop/ast/vendor/parser/source/map/send.rb +36 -0
- data/lib/rubocop/ast/vendor/parser/source/map/ternary.rb +18 -0
- data/lib/rubocop/ast/vendor/parser/source/map/variable.rb +31 -0
- data/lib/rubocop/ast/vendor/parser/source/map.rb +186 -0
- data/lib/rubocop/ast/vendor/parser/source/range.rb +326 -0
- data/lib/rubocop/ast/vendor/parser/source/tree_rewriter/action.rb +243 -0
- data/lib/rubocop/ast/vendor/parser/source/tree_rewriter.rb +431 -0
- data/lib/rubocop/ast/vendor/parser/syntax_error.rb +21 -0
- data/lib/rubocop/ast/vendor/parser/unknown_encoding_in_magic_comment_error.rb +15 -0
- data/lib/rubocop/ast/vendor/parser/version.rb +5 -0
- data/lib/rubocop/ast/version.rb +1 -1
- data/lib/rubocop/ast.rb +10 -3
- metadata +68 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10a0427201ac1703c7cd4860649d1021132e5829adb6b8bb56a42b5d618567c5
|
|
4
|
+
data.tar.gz: 1aaf7f176cc37142421011a587ad5030b410441758b9af4ae5fd86ca3c8fad2f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2dc127a53b8f8f4a1d72ab4a39e6e7e4697f02f142ea94e3b5d8d5e8fb3dfc2ef375b18e8f0628da81e2a46c48813cd1f0d3e113fc920afce5be344996b99284
|
|
7
|
+
data.tar.gz: a429f0e43ae4c558aa166bacca175b78174cf330beee74a231f994b70ef88663194c05f77f4731fbd962a117b500ebfb70caa5d301c3eceffe44676d769cda67
|
data/lib/rubocop/ast/builder.rb
CHANGED
|
@@ -1,120 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'parser'
|
|
4
|
+
|
|
3
5
|
module RuboCop
|
|
4
6
|
module AST
|
|
5
|
-
# Common functionality between the parser and prism builder
|
|
6
|
-
# @api private
|
|
7
|
-
module BuilderExtensions
|
|
8
|
-
def self.included(base)
|
|
9
|
-
base.emit_forward_arg = true
|
|
10
|
-
base.emit_match_pattern = true
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# @api private
|
|
14
|
-
NODE_MAP = {
|
|
15
|
-
and: AndNode,
|
|
16
|
-
and_asgn: AndAsgnNode,
|
|
17
|
-
alias: AliasNode,
|
|
18
|
-
arg: ArgNode,
|
|
19
|
-
blockarg: ArgNode,
|
|
20
|
-
forward_arg: ArgNode,
|
|
21
|
-
kwarg: ArgNode,
|
|
22
|
-
kwoptarg: ArgNode,
|
|
23
|
-
kwrestarg: ArgNode,
|
|
24
|
-
optarg: ArgNode,
|
|
25
|
-
restarg: ArgNode,
|
|
26
|
-
shadowarg: ArgNode,
|
|
27
|
-
args: ArgsNode,
|
|
28
|
-
array: ArrayNode,
|
|
29
|
-
lvasgn: AsgnNode,
|
|
30
|
-
ivasgn: AsgnNode,
|
|
31
|
-
cvasgn: AsgnNode,
|
|
32
|
-
gvasgn: AsgnNode,
|
|
33
|
-
block: BlockNode,
|
|
34
|
-
numblock: BlockNode,
|
|
35
|
-
itblock: BlockNode,
|
|
36
|
-
break: BreakNode,
|
|
37
|
-
case_match: CaseMatchNode,
|
|
38
|
-
casgn: CasgnNode,
|
|
39
|
-
case: CaseNode,
|
|
40
|
-
class: ClassNode,
|
|
41
|
-
complex: ComplexNode,
|
|
42
|
-
const: ConstNode,
|
|
43
|
-
def: DefNode,
|
|
44
|
-
defined?: DefinedNode,
|
|
45
|
-
defs: DefNode,
|
|
46
|
-
dstr: DstrNode,
|
|
47
|
-
ensure: EnsureNode,
|
|
48
|
-
for: ForNode,
|
|
49
|
-
forward_args: ForwardArgsNode,
|
|
50
|
-
forwarded_kwrestarg: KeywordSplatNode,
|
|
51
|
-
float: FloatNode,
|
|
52
|
-
hash: HashNode,
|
|
53
|
-
if: IfNode,
|
|
54
|
-
in_pattern: InPatternNode,
|
|
55
|
-
int: IntNode,
|
|
56
|
-
index: IndexNode,
|
|
57
|
-
indexasgn: IndexasgnNode,
|
|
58
|
-
irange: RangeNode,
|
|
59
|
-
erange: RangeNode,
|
|
60
|
-
kwargs: HashNode,
|
|
61
|
-
kwbegin: KeywordBeginNode,
|
|
62
|
-
kwsplat: KeywordSplatNode,
|
|
63
|
-
lambda: LambdaNode,
|
|
64
|
-
masgn: MasgnNode,
|
|
65
|
-
mlhs: MlhsNode,
|
|
66
|
-
module: ModuleNode,
|
|
67
|
-
next: NextNode,
|
|
68
|
-
op_asgn: OpAsgnNode,
|
|
69
|
-
or_asgn: OrAsgnNode,
|
|
70
|
-
or: OrNode,
|
|
71
|
-
pair: PairNode,
|
|
72
|
-
procarg0: Procarg0Node,
|
|
73
|
-
rational: RationalNode,
|
|
74
|
-
regexp: RegexpNode,
|
|
75
|
-
rescue: RescueNode,
|
|
76
|
-
resbody: ResbodyNode,
|
|
77
|
-
return: ReturnNode,
|
|
78
|
-
csend: CsendNode,
|
|
79
|
-
send: SendNode,
|
|
80
|
-
str: StrNode,
|
|
81
|
-
xstr: StrNode,
|
|
82
|
-
sclass: SelfClassNode,
|
|
83
|
-
super: SuperNode,
|
|
84
|
-
zsuper: SuperNode,
|
|
85
|
-
sym: SymbolNode,
|
|
86
|
-
until: UntilNode,
|
|
87
|
-
until_post: UntilNode,
|
|
88
|
-
lvar: VarNode,
|
|
89
|
-
ivar: VarNode,
|
|
90
|
-
cvar: VarNode,
|
|
91
|
-
gvar: VarNode,
|
|
92
|
-
when: WhenNode,
|
|
93
|
-
while: WhileNode,
|
|
94
|
-
while_post: WhileNode,
|
|
95
|
-
yield: YieldNode
|
|
96
|
-
}.freeze
|
|
97
|
-
|
|
98
|
-
# Generates {Node} from the given information.
|
|
99
|
-
#
|
|
100
|
-
# @return [Node] the generated node
|
|
101
|
-
def n(type, children, source_map)
|
|
102
|
-
node_klass(type).new(type, children, location: source_map)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
# Overwrite the base method to allow strings with invalid encoding
|
|
106
|
-
# More details here https://github.com/whitequark/parser/issues/283
|
|
107
|
-
def string_value(token)
|
|
108
|
-
value(token)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
private
|
|
112
|
-
|
|
113
|
-
def node_klass(type)
|
|
114
|
-
NODE_MAP[type] || Node
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
7
|
# `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
|
|
119
8
|
# generate ASTs with {RuboCop::AST::Node}.
|
|
120
9
|
#
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module AST
|
|
5
|
+
# Common functionality between the parser and prism builder
|
|
6
|
+
# @api private
|
|
7
|
+
module BuilderExtensions
|
|
8
|
+
def self.included(base)
|
|
9
|
+
base.emit_forward_arg = true
|
|
10
|
+
base.emit_match_pattern = true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @api private
|
|
14
|
+
NODE_MAP = {
|
|
15
|
+
and: AndNode,
|
|
16
|
+
and_asgn: AndAsgnNode,
|
|
17
|
+
alias: AliasNode,
|
|
18
|
+
arg: ArgNode,
|
|
19
|
+
blockarg: ArgNode,
|
|
20
|
+
forward_arg: ArgNode,
|
|
21
|
+
kwarg: ArgNode,
|
|
22
|
+
kwoptarg: ArgNode,
|
|
23
|
+
kwrestarg: ArgNode,
|
|
24
|
+
optarg: ArgNode,
|
|
25
|
+
restarg: ArgNode,
|
|
26
|
+
shadowarg: ArgNode,
|
|
27
|
+
args: ArgsNode,
|
|
28
|
+
array: ArrayNode,
|
|
29
|
+
lvasgn: AsgnNode,
|
|
30
|
+
ivasgn: AsgnNode,
|
|
31
|
+
cvasgn: AsgnNode,
|
|
32
|
+
gvasgn: AsgnNode,
|
|
33
|
+
block: BlockNode,
|
|
34
|
+
numblock: BlockNode,
|
|
35
|
+
itblock: BlockNode,
|
|
36
|
+
break: BreakNode,
|
|
37
|
+
case_match: CaseMatchNode,
|
|
38
|
+
casgn: CasgnNode,
|
|
39
|
+
case: CaseNode,
|
|
40
|
+
class: ClassNode,
|
|
41
|
+
complex: ComplexNode,
|
|
42
|
+
const: ConstNode,
|
|
43
|
+
def: DefNode,
|
|
44
|
+
defined?: DefinedNode,
|
|
45
|
+
defs: DefNode,
|
|
46
|
+
dstr: DstrNode,
|
|
47
|
+
ensure: EnsureNode,
|
|
48
|
+
for: ForNode,
|
|
49
|
+
forward_args: ForwardArgsNode,
|
|
50
|
+
forwarded_kwrestarg: KeywordSplatNode,
|
|
51
|
+
float: FloatNode,
|
|
52
|
+
hash: HashNode,
|
|
53
|
+
if: IfNode,
|
|
54
|
+
in_pattern: InPatternNode,
|
|
55
|
+
int: IntNode,
|
|
56
|
+
index: IndexNode,
|
|
57
|
+
indexasgn: IndexasgnNode,
|
|
58
|
+
irange: RangeNode,
|
|
59
|
+
erange: RangeNode,
|
|
60
|
+
kwargs: HashNode,
|
|
61
|
+
kwbegin: KeywordBeginNode,
|
|
62
|
+
kwsplat: KeywordSplatNode,
|
|
63
|
+
lambda: LambdaNode,
|
|
64
|
+
masgn: MasgnNode,
|
|
65
|
+
mlhs: MlhsNode,
|
|
66
|
+
module: ModuleNode,
|
|
67
|
+
next: NextNode,
|
|
68
|
+
op_asgn: OpAsgnNode,
|
|
69
|
+
or_asgn: OrAsgnNode,
|
|
70
|
+
or: OrNode,
|
|
71
|
+
pair: PairNode,
|
|
72
|
+
procarg0: Procarg0Node,
|
|
73
|
+
rational: RationalNode,
|
|
74
|
+
regexp: RegexpNode,
|
|
75
|
+
rescue: RescueNode,
|
|
76
|
+
resbody: ResbodyNode,
|
|
77
|
+
return: ReturnNode,
|
|
78
|
+
csend: CsendNode,
|
|
79
|
+
send: SendNode,
|
|
80
|
+
str: StrNode,
|
|
81
|
+
xstr: StrNode,
|
|
82
|
+
sclass: SelfClassNode,
|
|
83
|
+
super: SuperNode,
|
|
84
|
+
zsuper: SuperNode,
|
|
85
|
+
sym: SymbolNode,
|
|
86
|
+
until: UntilNode,
|
|
87
|
+
until_post: UntilNode,
|
|
88
|
+
lvar: VarNode,
|
|
89
|
+
ivar: VarNode,
|
|
90
|
+
cvar: VarNode,
|
|
91
|
+
gvar: VarNode,
|
|
92
|
+
when: WhenNode,
|
|
93
|
+
while: WhileNode,
|
|
94
|
+
while_post: WhileNode,
|
|
95
|
+
yield: YieldNode
|
|
96
|
+
}.freeze
|
|
97
|
+
|
|
98
|
+
# Generates {Node} from the given information.
|
|
99
|
+
#
|
|
100
|
+
# @return [Node] the generated node
|
|
101
|
+
def n(type, children, source_map)
|
|
102
|
+
node_klass(type).new(type, children, location: source_map)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Overwrite the base method to allow strings with invalid encoding
|
|
106
|
+
# More details here https://github.com/whitequark/parser/issues/283
|
|
107
|
+
def string_value(token)
|
|
108
|
+
value(token)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
def node_klass(type)
|
|
114
|
+
NODE_MAP[type] || Node
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
data/lib/rubocop/ast/node.rb
CHANGED
|
@@ -246,7 +246,7 @@ module RuboCop
|
|
|
246
246
|
# part of it is changed.
|
|
247
247
|
def updated(type = nil, children = nil, properties = {})
|
|
248
248
|
properties[:location] ||= @location
|
|
249
|
-
klass =
|
|
249
|
+
klass = BuilderExtensions::NODE_MAP[type || @type] || Node
|
|
250
250
|
klass.new(type || @type, children || @children, properties)
|
|
251
251
|
end
|
|
252
252
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ast'
|
|
4
|
+
|
|
5
|
+
module RuboCop
|
|
6
|
+
module AST
|
|
7
|
+
# Loads the part of the `parser` gem that every parser engine needs: the
|
|
8
|
+
# node base class, the source layer (buffers, ranges, comments, source
|
|
9
|
+
# maps, the tree rewriter) and the diagnostics.
|
|
10
|
+
#
|
|
11
|
+
# They come from the gem when it is installed, because its parsers and
|
|
12
|
+
# builders create objects of the very same classes. Without the gem, a
|
|
13
|
+
# copy of those files that ships with this gem is loaded instead, which is
|
|
14
|
+
# all that the `prism` parser engine needs.
|
|
15
|
+
# @api private
|
|
16
|
+
module ParserSource
|
|
17
|
+
FILES = %w[
|
|
18
|
+
version messages deprecation ast/node meta
|
|
19
|
+
source/buffer source/range source/comment source/comment/associator
|
|
20
|
+
source/tree_rewriter source/tree_rewriter/action
|
|
21
|
+
source/map source/map/operator source/map/collection source/map/constant
|
|
22
|
+
source/map/variable source/map/keyword source/map/definition
|
|
23
|
+
source/map/method_definition source/map/send source/map/index
|
|
24
|
+
source/map/condition source/map/ternary source/map/for
|
|
25
|
+
source/map/rescue_body source/map/heredoc source/map/objc_kwarg
|
|
26
|
+
syntax_error clobbering_error unknown_encoding_in_magic_comment_error
|
|
27
|
+
diagnostic diagnostic/engine
|
|
28
|
+
].freeze
|
|
29
|
+
|
|
30
|
+
VENDOR_DIR = File.join(__dir__, 'vendor', 'parser')
|
|
31
|
+
|
|
32
|
+
VENDORED = begin
|
|
33
|
+
require 'parser/version'
|
|
34
|
+
false
|
|
35
|
+
rescue LoadError
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
private_constant :VENDORED
|
|
39
|
+
|
|
40
|
+
# Whether the classes come from the copy that ships with this gem,
|
|
41
|
+
# which is the case when the `parser` gem is not installed.
|
|
42
|
+
def self.vendored?
|
|
43
|
+
VENDORED
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.ensure_parser_gem(parser_engine)
|
|
47
|
+
return unless vendored?
|
|
48
|
+
|
|
49
|
+
raise LoadError, "The `#{parser_engine}` parser engine needs the `parser` gem. Add it " \
|
|
50
|
+
'to your Gemfile, or use the `prism` parser engine, which supports ' \
|
|
51
|
+
'target Ruby versions 3.3 and above.'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
begin
|
|
55
|
+
FILES.each { |file| require vendored? ? File.join(VENDOR_DIR, file) : "parser/#{file}" }
|
|
56
|
+
rescue LoadError
|
|
57
|
+
# A version of `parser` that lays out its files in another way.
|
|
58
|
+
require 'parser'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Loads the rest of `parser` when something refers to a constant that
|
|
62
|
+
# is not part of the files above, like `Parser::Base` or
|
|
63
|
+
# `Parser::Builders::Default`.
|
|
64
|
+
module LazyConstants
|
|
65
|
+
def const_missing(name)
|
|
66
|
+
return super unless require('parser') && const_defined?(name, false)
|
|
67
|
+
|
|
68
|
+
const_get(name, false)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
lazy = vendored? ? [] : [::Parser, ::Parser::AST, ::Parser::Source]
|
|
73
|
+
lazy.each { |mod| mod.extend(LazyConstants) }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|