rubocop-ast 1.39.0 → 1.40.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 +23 -15
- data/lib/rubocop/ast/builder_prism.rb +11 -0
- data/lib/rubocop/ast/processed_source.rb +28 -17
- data/lib/rubocop/ast/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 572b1323e4358215b5e093fa0326fb04dc3d7986746143b75bd0d58223d2dc9e
|
4
|
+
data.tar.gz: 96d40dd742d28e480ca3be7dd7fd16bf9f410e7631373d4c441a74530bfc0314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd75e5325a907aead5239937ee34447d16da764f1fe2a31d140c9d4f5398b4c4a81c5f88a697bb62149845fc24691b53d526cc5ac05b1060472e92fceaceefae
|
7
|
+
data.tar.gz: d04d2d4dcf76bd6b23e9f6b2a44af18562d8bed8d9767b0511e58feabe762f90fba42f73869500fbe8c34ec1d0e4b6bebe74e7b3bbee18a83b284a97c05d477c
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -2,20 +2,13 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module AST
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# builder = RuboCop::AST::Builder.new
|
13
|
-
# require 'parser/ruby25'
|
14
|
-
# parser = Parser::Ruby25.new(builder)
|
15
|
-
# root_node = parser.parse(buffer)
|
16
|
-
class Builder < Parser::Builders::Default
|
17
|
-
self.emit_forward_arg = true if respond_to?(:emit_forward_arg=)
|
18
|
-
self.emit_match_pattern = true if respond_to?(:emit_match_pattern=)
|
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
|
19
12
|
|
20
13
|
# @api private
|
21
14
|
NODE_MAP = {
|
@@ -107,7 +100,7 @@ module RuboCop
|
|
107
100
|
node_klass(type).new(type, children, location: source_map)
|
108
101
|
end
|
109
102
|
|
110
|
-
#
|
103
|
+
# Overwrite the base method to allow strings with invalid encoding
|
111
104
|
# More details here https://github.com/whitequark/parser/issues/283
|
112
105
|
def string_value(token)
|
113
106
|
value(token)
|
@@ -119,5 +112,20 @@ module RuboCop
|
|
119
112
|
NODE_MAP[type] || Node
|
120
113
|
end
|
121
114
|
end
|
115
|
+
|
116
|
+
# `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
|
117
|
+
# generate ASTs with {RuboCop::AST::Node}.
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# buffer = Parser::Source::Buffer.new('(string)')
|
121
|
+
# buffer.source = 'puts :foo'
|
122
|
+
#
|
123
|
+
# builder = RuboCop::AST::Builder.new
|
124
|
+
# require 'parser/ruby25'
|
125
|
+
# parser = Parser::Ruby25.new(builder)
|
126
|
+
# root_node = parser.parse(buffer)
|
127
|
+
class Builder < Parser::Builders::Default
|
128
|
+
include BuilderExtensions
|
129
|
+
end
|
122
130
|
end
|
123
131
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A parser builder, based on the one provided by prism,
|
6
|
+
# which is capable of emitting AST for more recent Rubies.
|
7
|
+
class BuilderPrism < Prism::Translation::Parser::Builder
|
8
|
+
include BuilderExtensions
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -314,10 +314,10 @@ module RuboCop
|
|
314
314
|
|
315
315
|
case ruby_version
|
316
316
|
when 3.3
|
317
|
-
|
317
|
+
require 'prism/translation/parser33'
|
318
318
|
Prism::Translation::Parser33
|
319
319
|
when 3.4
|
320
|
-
|
320
|
+
require 'prism/translation/parser34'
|
321
321
|
Prism::Translation::Parser34
|
322
322
|
else
|
323
323
|
raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
|
@@ -326,34 +326,45 @@ module RuboCop
|
|
326
326
|
end
|
327
327
|
end
|
328
328
|
|
329
|
+
def builder_class(parser_engine)
|
330
|
+
case parser_engine
|
331
|
+
when :parser_whitequark
|
332
|
+
RuboCop::AST::Builder
|
333
|
+
when :parser_prism
|
334
|
+
require_prism
|
335
|
+
require_relative 'builder_prism'
|
336
|
+
RuboCop::AST::BuilderPrism
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
329
340
|
# Prism is a native extension, a `LoadError` will be raised if linked to an incompatible
|
330
341
|
# Ruby version. Only raise if it really was caused by Prism not being present.
|
342
|
+
# rubocop:disable Metrics/MethodLength
|
331
343
|
def require_prism
|
332
344
|
require 'prism'
|
345
|
+
required_prism_version = '1.4.0'
|
346
|
+
if required_prism_version > Prism::VERSION
|
347
|
+
# While Prism is not yet a dependency, users may run with outdated versions that
|
348
|
+
# don't have all the parsers.
|
349
|
+
warn <<~MESSAGE
|
350
|
+
Error: Prism version #{Prism::VERSION} was loaded, but rubocop-ast requires #{required_prism_version}.
|
351
|
+
* If you're using Bundler and don't yet have `gem 'prism'` as a dependency, add it now.
|
352
|
+
* If you're using Bundler and already have `gem 'prism'` as a dependency, update it to the most recent version.
|
353
|
+
* If you don't use Bundler, run `gem update prism`.
|
354
|
+
MESSAGE
|
355
|
+
exit!
|
356
|
+
end
|
333
357
|
rescue LoadError => e
|
334
358
|
raise unless e.path == 'prism'
|
335
359
|
|
336
360
|
warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
|
337
361
|
exit!
|
338
362
|
end
|
339
|
-
|
340
|
-
# While Prism is not yet a dependency, users may run with outdated versions that
|
341
|
-
# don't have all the parsers.
|
342
|
-
def require_prism_translation_parser(version)
|
343
|
-
require "prism/translation/parser#{version.to_s.delete('.')}"
|
344
|
-
rescue LoadError
|
345
|
-
warn <<~MESSAGE
|
346
|
-
Error: Unable to load Prism parser for Ruby #{version}.
|
347
|
-
* If you're using Bundler and don't yet have `gem 'prism'` as a dependency, add it now.
|
348
|
-
* If you're using Bundler and already have `gem 'prism'` as a dependency, update it to the most recent version.
|
349
|
-
* If you don't use Bundler, run `gem update prism`.
|
350
|
-
MESSAGE
|
351
|
-
exit!
|
352
|
-
end
|
363
|
+
# rubocop:enable Metrics/MethodLength
|
353
364
|
|
354
365
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
355
366
|
def create_parser(ruby_version, parser_engine, prism_result)
|
356
|
-
builder =
|
367
|
+
builder = builder_class(parser_engine).new
|
357
368
|
|
358
369
|
parser_class = parser_class(ruby_version, parser_engine)
|
359
370
|
|
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: 1.
|
4
|
+
version: 1.40.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: 2025-03-
|
13
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parser
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/rubocop-ast.rb
|
40
40
|
- lib/rubocop/ast.rb
|
41
41
|
- lib/rubocop/ast/builder.rb
|
42
|
+
- lib/rubocop/ast/builder_prism.rb
|
42
43
|
- lib/rubocop/ast/ext/range.rb
|
43
44
|
- lib/rubocop/ast/node.rb
|
44
45
|
- lib/rubocop/ast/node/alias_node.rb
|