rfmt 1.7.0-x86_64-linux → 2.0.0.beta1-x86_64-linux
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/CHANGELOG.md +25 -0
- data/README.md +32 -28
- data/ext/rfmt/tests/fixtures/parity/comments_mixed.rb +9 -0
- data/ext/rfmt/tests/fixtures/parity/constructs.rb +50 -0
- data/ext/rfmt/tests/fixtures/parity/embdoc.rb +12 -0
- data/ext/rfmt/tests/fixtures/parity/heredoc_assign.rb +15 -0
- data/ext/rfmt/tests/fixtures/parity/heredoc_call_args.rb +17 -0
- data/ext/rfmt/tests/fixtures/parity/metadata_classes.rb +30 -0
- data/ext/rfmt/tests/fixtures/parity/metadata_conditionals.rb +14 -0
- data/ext/rfmt/tests/fixtures/parity/metadata_defs.rb +33 -0
- data/ext/rfmt/tests/fixtures/parity/multibyte.rb +14 -0
- data/ext/rfmt/tests/fixtures/parity/numeric.rb +6 -0
- data/ext/rfmt/tests/fixtures/parity/plain.rb +31 -0
- data/lib/rfmt/3.3/rfmt.so +0 -0
- data/lib/rfmt/3.4/rfmt.so +0 -0
- data/lib/rfmt/cli.rb +37 -7
- data/lib/rfmt/configuration.rb +2 -20
- data/lib/rfmt/version.rb +1 -1
- data/lib/rfmt.rb +47 -19
- metadata +13 -18
- data/lib/rfmt/prism_bridge.rb +0 -529
- data/lib/rfmt/prism_node_extractor.rb +0 -115
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Rfmt
|
|
4
|
-
# PrismNodeExtractor provides safe methods to extract information from Prism nodes
|
|
5
|
-
# This module encapsulates the logic for accessing Prism node properties,
|
|
6
|
-
# making the code resilient to Prism API changes
|
|
7
|
-
module PrismNodeExtractor
|
|
8
|
-
# Extract the name from a node
|
|
9
|
-
# @param node [Prism::Node] The node to extract name from
|
|
10
|
-
# @return [String, nil] The node name or nil if not available
|
|
11
|
-
def extract_node_name(node)
|
|
12
|
-
return nil unless node.respond_to?(:name)
|
|
13
|
-
|
|
14
|
-
node.name.to_s
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Extract full name from class or module node (handles namespaced names like Foo::Bar::Baz)
|
|
18
|
-
# @param node [Prism::ClassNode, Prism::ModuleNode] The class or module node
|
|
19
|
-
# @return [String, nil] The full name or nil if not available
|
|
20
|
-
def extract_class_or_module_name(node)
|
|
21
|
-
return nil unless node.respond_to?(:constant_path)
|
|
22
|
-
|
|
23
|
-
cp = node.constant_path
|
|
24
|
-
return node.name.to_s if cp.nil?
|
|
25
|
-
|
|
26
|
-
case cp
|
|
27
|
-
when Prism::ConstantReadNode
|
|
28
|
-
cp.name.to_s
|
|
29
|
-
when Prism::ConstantPathNode
|
|
30
|
-
if cp.respond_to?(:full_name)
|
|
31
|
-
cp.full_name.to_s
|
|
32
|
-
elsif cp.respond_to?(:slice)
|
|
33
|
-
cp.slice
|
|
34
|
-
else
|
|
35
|
-
cp.location.slice
|
|
36
|
-
end
|
|
37
|
-
else
|
|
38
|
-
node.name.to_s
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Extract superclass name from a class node
|
|
43
|
-
# @param class_node [Prism::ClassNode] The class node
|
|
44
|
-
# @return [String, nil] The superclass name or nil if not available
|
|
45
|
-
def extract_superclass_name(class_node)
|
|
46
|
-
return nil unless class_node.respond_to?(:superclass)
|
|
47
|
-
|
|
48
|
-
sc = class_node.superclass
|
|
49
|
-
return nil if sc.nil?
|
|
50
|
-
|
|
51
|
-
case sc
|
|
52
|
-
when Prism::ConstantReadNode
|
|
53
|
-
sc.name.to_s
|
|
54
|
-
when Prism::ConstantPathNode
|
|
55
|
-
# Try full_name first, fall back to slice for original source
|
|
56
|
-
if sc.respond_to?(:full_name)
|
|
57
|
-
sc.full_name.to_s
|
|
58
|
-
elsif sc.respond_to?(:slice)
|
|
59
|
-
sc.slice
|
|
60
|
-
else
|
|
61
|
-
sc.location.slice
|
|
62
|
-
end
|
|
63
|
-
when Prism::CallNode
|
|
64
|
-
# Handle cases like ActiveRecord::Migration[8.1]
|
|
65
|
-
# Use slice to get the original source text
|
|
66
|
-
sc.slice
|
|
67
|
-
else
|
|
68
|
-
# Fallback: try to get original source text
|
|
69
|
-
if sc.respond_to?(:slice)
|
|
70
|
-
sc.slice
|
|
71
|
-
else
|
|
72
|
-
sc.location.slice
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Extract parameter count from a method definition node
|
|
78
|
-
# @param def_node [Prism::DefNode] The method definition node
|
|
79
|
-
# @return [Integer] The number of parameters (0 if none)
|
|
80
|
-
def extract_parameter_count(def_node)
|
|
81
|
-
return 0 unless def_node.respond_to?(:parameters)
|
|
82
|
-
return 0 if def_node.parameters.nil?
|
|
83
|
-
return 0 unless def_node.parameters.respond_to?(:child_nodes)
|
|
84
|
-
|
|
85
|
-
def_node.parameters.child_nodes.compact.length
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Extract message name from a call node
|
|
89
|
-
# @param call_node [Prism::CallNode] The call node
|
|
90
|
-
# @return [String, nil] The message name or nil if not available
|
|
91
|
-
def extract_message_name(call_node)
|
|
92
|
-
return nil unless call_node.respond_to?(:message)
|
|
93
|
-
|
|
94
|
-
call_node.message.to_s
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# Extract content from a string node
|
|
98
|
-
# @param string_node [Prism::StringNode] The string node
|
|
99
|
-
# @return [String, nil] The string content or nil if not available
|
|
100
|
-
def extract_string_content(string_node)
|
|
101
|
-
return nil unless string_node.respond_to?(:content)
|
|
102
|
-
|
|
103
|
-
string_node.content
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# Extract value from a literal node (Integer, Float, Symbol)
|
|
107
|
-
# @param node [Prism::Node] The literal node
|
|
108
|
-
# @return [String, nil] The value as string or nil if not available
|
|
109
|
-
def extract_literal_value(node)
|
|
110
|
-
return nil unless node.respond_to?(:value)
|
|
111
|
-
|
|
112
|
-
node.value.to_s
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|