rubocop-ast 1.42.0 → 1.44.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/node/mixin/method_dispatch_node.rb +2 -3
- data/lib/rubocop/ast/node.rb +7 -0
- data/lib/rubocop/ast/processed_source.rb +2 -36
- data/lib/rubocop/ast/version.rb +1 -1
- data/lib/rubocop/ast.rb +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c81addbafdef9eafbc9cff169bf71dd053d5afac7b5f60a048b4c2f03f3660a
|
4
|
+
data.tar.gz: cae0da568f2f9a1d29876369cc1a5158879148a3fd3d773fd73f0fe765836efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a05ff6ffe86fc1fe0376f541f48df20d6f6df15bf0236757358f9c1c7b8231feff8efc6bd9b6aaff5f44c5eee8787c5540cde7ec14a85f346e832cc41ebe079
|
7
|
+
data.tar.gz: f02aba449bf7a41ad37dbd4b6efb0781555a908e3cba6459c2f88f182f36e9385ef13747e9af94740ad7c6d46d27ab5bf635231baedaa711a704a3f7ff8e8d52
|
@@ -200,8 +200,7 @@ module RuboCop
|
|
200
200
|
arg = node.children[2]
|
201
201
|
|
202
202
|
return unless node.send_type? && node.receiver.nil? && arg.is_a?(::AST::Node)
|
203
|
-
|
204
|
-
return arg if arg.type?(:def, :defs)
|
203
|
+
return arg if arg.any_def_type?
|
205
204
|
|
206
205
|
def_modifier(arg)
|
207
206
|
end
|
@@ -271,7 +270,7 @@ module RuboCop
|
|
271
270
|
|
272
271
|
# @!method adjacent_def_modifier?(node = self)
|
273
272
|
def_node_matcher :adjacent_def_modifier?, <<~PATTERN
|
274
|
-
(send nil? _ (
|
273
|
+
(send nil? _ (any_def ...))
|
275
274
|
PATTERN
|
276
275
|
|
277
276
|
# @!method bare_access_modifier_declaration?(node = self)
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -87,6 +87,9 @@ module RuboCop
|
|
87
87
|
|
88
88
|
# @api private
|
89
89
|
GROUP_FOR_TYPE = {
|
90
|
+
def: :any_def,
|
91
|
+
defs: :any_def,
|
92
|
+
|
90
93
|
arg: :argument,
|
91
94
|
optarg: :argument,
|
92
95
|
restarg: :argument,
|
@@ -513,6 +516,10 @@ module RuboCop
|
|
513
516
|
parent&.send_type? && parent.arguments.include?(self)
|
514
517
|
end
|
515
518
|
|
519
|
+
def any_def_type?
|
520
|
+
GROUP_FOR_TYPE[type] == :any_def
|
521
|
+
end
|
522
|
+
|
516
523
|
def argument_type?
|
517
524
|
GROUP_FOR_TYPE[type] == :argument
|
518
525
|
end
|
@@ -307,8 +307,6 @@ module RuboCop
|
|
307
307
|
"`parser`. Specified target Ruby version: #{ruby_version.inspect}"
|
308
308
|
end
|
309
309
|
when :parser_prism
|
310
|
-
require_prism
|
311
|
-
|
312
310
|
case ruby_version
|
313
311
|
when 3.3
|
314
312
|
require 'prism/translation/parser33'
|
@@ -331,49 +329,17 @@ module RuboCop
|
|
331
329
|
when :parser_whitequark
|
332
330
|
RuboCop::AST::Builder
|
333
331
|
when :parser_prism
|
334
|
-
require_prism
|
335
|
-
require_relative 'builder_prism'
|
336
332
|
RuboCop::AST::BuilderPrism
|
337
333
|
end
|
338
334
|
end
|
339
335
|
|
340
|
-
# Prism is a native extension, a `LoadError` will be raised if linked to an incompatible
|
341
|
-
# Ruby version. Only raise if it really was caused by Prism not being present.
|
342
|
-
# rubocop:disable Metrics/MethodLength
|
343
|
-
def require_prism
|
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
|
357
|
-
rescue LoadError => e
|
358
|
-
raise unless e.path == 'prism'
|
359
|
-
|
360
|
-
warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
|
361
|
-
exit!
|
362
|
-
end
|
363
|
-
# rubocop:enable Metrics/MethodLength
|
364
|
-
|
365
336
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
366
337
|
def create_parser(ruby_version, parser_engine, prism_result)
|
367
338
|
builder = builder_class(parser_engine).new
|
368
339
|
|
369
340
|
parser_class = parser_class(ruby_version, parser_engine)
|
370
341
|
|
371
|
-
|
372
|
-
# The `:parser` keyword argument cannot be used to switch parsers because older versions of
|
373
|
-
# Prism do not support it.
|
374
|
-
parser_switch_available = parser_class.instance_method(:initialize).parameters.assoc(:key)
|
375
|
-
|
376
|
-
parser_instance = if prism_result && parser_switch_available
|
342
|
+
parser_instance = if prism_result
|
377
343
|
# NOTE: Since it is intended for use with Ruby LSP, it targets only Prism.
|
378
344
|
# If there is no reuse of a pre-parsed result, such as in Ruby LSP,
|
379
345
|
# regular parsing with Prism occurs, and `else` branch will be executed.
|
@@ -415,7 +381,7 @@ module RuboCop
|
|
415
381
|
# It is also not fully compatible with Ruby 3.4 but for
|
416
382
|
# now respects using parser for backwards compatibility.
|
417
383
|
def default_parser_engine(ruby_version)
|
418
|
-
if ruby_version >= 3.
|
384
|
+
if ruby_version >= 3.4
|
419
385
|
:parser_prism
|
420
386
|
else
|
421
387
|
:parser_whitequark
|
data/lib/rubocop/ast/version.rb
CHANGED
data/lib/rubocop/ast.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'parser'
|
4
|
+
require 'prism'
|
4
5
|
require 'forwardable'
|
5
6
|
require 'set'
|
6
7
|
|
@@ -92,6 +93,7 @@ require_relative 'ast/node/when_node'
|
|
92
93
|
require_relative 'ast/node/while_node'
|
93
94
|
require_relative 'ast/node/yield_node'
|
94
95
|
require_relative 'ast/builder'
|
96
|
+
require_relative 'ast/builder_prism'
|
95
97
|
require_relative 'ast/processed_source'
|
96
98
|
require_relative 'ast/rubocop_compatibility'
|
97
99
|
require_relative 'ast/token'
|
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.44.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Yuji Nakayama
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-03
|
12
|
+
date: 2025-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.3.7.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: prism
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.4'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.4'
|
28
42
|
description: " RuboCop's Node and NodePattern classes.\n"
|
29
43
|
email: rubocop@googlegroups.com
|
30
44
|
executables: []
|