syntax_tree 2.4.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -586,6 +586,14 @@ module SyntaxTree
586
586
  end
587
587
  end
588
588
 
589
+ def visit_lambda_var(node)
590
+ node(node, "lambda_var") do
591
+ field("params", node.params)
592
+ list("locals", node.locals) if node.locals.any?
593
+ comments(node)
594
+ end
595
+ end
596
+
589
597
  def visit_lbrace(node)
590
598
  visit_token(node, "lbrace")
591
599
  end
@@ -22,7 +22,7 @@ module SyntaxTree
22
22
  # entire value into the output buffer.
23
23
  q.text(node.inspect)
24
24
  else
25
- q.pp(node)
25
+ node.pretty_print(q)
26
26
  end
27
27
  end
28
28
 
@@ -114,7 +114,7 @@ module SyntaxTree
114
114
  q.nest(0) do
115
115
  q.text(name)
116
116
  q.text(": ")
117
- q.pp(value)
117
+ value.pretty_print(q)
118
118
  end
119
119
  end
120
120
  end
@@ -301,6 +301,9 @@ module SyntaxTree
301
301
  # Visit a Lambda node.
302
302
  alias visit_lambda visit_child_nodes
303
303
 
304
+ # Visit a LambdaVar node.
305
+ alias visit_lambda_var visit_child_nodes
306
+
304
307
  # Visit a LBrace node.
305
308
  alias visit_lbrace visit_child_nodes
306
309
 
data/lib/syntax_tree.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "json"
4
4
  require "pp"
5
- require "prettyprint"
5
+ require "prettier_print"
6
6
  require "ripper"
7
7
  require "stringio"
8
8
 
@@ -16,30 +16,6 @@ require_relative "syntax_tree/visitor/json_visitor"
16
16
  require_relative "syntax_tree/visitor/match_visitor"
17
17
  require_relative "syntax_tree/visitor/pretty_print_visitor"
18
18
 
19
- # If PrettyPrint::Align isn't defined, then we haven't gotten the updated
20
- # version of prettyprint. In that case we'll define our own. This is going to
21
- # overwrite a bunch of methods, so silencing them as well.
22
- unless PrettyPrint.const_defined?(:Align)
23
- verbose = $VERBOSE
24
- $VERBOSE = nil
25
-
26
- begin
27
- require_relative "syntax_tree/prettyprint"
28
- ensure
29
- $VERBOSE = verbose
30
- end
31
- end
32
-
33
- # When PP is running, it expects that everything that interacts with it is going
34
- # to flow through PP.pp, since that's the main entry into the module from the
35
- # perspective of its uses in core Ruby. In doing so, it calls guard_inspect_key
36
- # at the top of the PP.pp method, which establishes some thread-local hashes to
37
- # check for cycles in the pretty printed tree. This means that if you want to
38
- # manually call pp on some object _before_ you have established these hashes,
39
- # you're going to break everything. So this call ensures that those hashes have
40
- # been set up before anything uses pp manually.
41
- PP.new(+"", 0).guard_inspect_key {}
42
-
43
19
  # Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
44
20
  # provides the ability to generate a syntax tree from source, as well as the
45
21
  # tools necessary to inspect and manipulate that syntax tree. It can be used to
@@ -64,8 +40,8 @@ module SyntaxTree
64
40
  end
65
41
 
66
42
  # Parses the given source and returns the formatted source.
67
- def self.format(source)
68
- formatter = Formatter.new(source, [])
43
+ def self.format(source, maxwidth = 80)
44
+ formatter = Formatter.new(source, [], maxwidth)
69
45
  parse(source).format(formatter)
70
46
 
71
47
  formatter.flush
data/syntax_tree.gemspec CHANGED
@@ -25,8 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = %w[lib]
27
27
 
28
+ spec.add_dependency "prettier_print"
29
+
28
30
  spec.add_development_dependency "bundler"
29
31
  spec.add_development_dependency "minitest"
30
32
  spec.add_development_dependency "rake"
33
+ spec.add_development_dependency "rubocop"
31
34
  spec.add_development_dependency "simplecov"
32
35
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-07 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prettier_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: simplecov
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -95,11 +123,17 @@ files:
95
123
  - lib/syntax_tree.rb
96
124
  - lib/syntax_tree/cli.rb
97
125
  - lib/syntax_tree/formatter.rb
126
+ - lib/syntax_tree/formatter/single_quotes.rb
127
+ - lib/syntax_tree/formatter/trailing_comma.rb
98
128
  - lib/syntax_tree/language_server.rb
99
129
  - lib/syntax_tree/language_server/inlay_hints.rb
100
130
  - lib/syntax_tree/node.rb
101
131
  - lib/syntax_tree/parser.rb
102
- - lib/syntax_tree/prettyprint.rb
132
+ - lib/syntax_tree/plugin/single_quotes.rb
133
+ - lib/syntax_tree/plugin/trailing_comma.rb
134
+ - lib/syntax_tree/rake/check_task.rb
135
+ - lib/syntax_tree/rake/write_task.rb
136
+ - lib/syntax_tree/rake_tasks.rb
103
137
  - lib/syntax_tree/version.rb
104
138
  - lib/syntax_tree/visitor.rb
105
139
  - lib/syntax_tree/visitor/field_visitor.rb