syntax_tree 2.1.1 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd341a51ce36b230703bfbe86078641e7670058a3e41d0dbb125548c0821a65a
4
- data.tar.gz: 9ebdca60f2956e24f83a58749266c89eb0eed88003a06699432956a0ecfa735a
3
+ metadata.gz: 5855cfed255d36a243d697083688e553ae02aa5373ec08af6bc730eea66ab995
4
+ data.tar.gz: 15da5f28c3cff6953eb1204abbd42ac22b2c5ea78546242f543034360b39fb62
5
5
  SHA512:
6
- metadata.gz: b8292d8020afa5ece8afdbaa60e959902357e769f098c75894d2b85686a20f824cf510563b2cd31e86b3f8f781f74cf8aaafac76e0e156e26897999ccb72ae36
7
- data.tar.gz: 968a355401a9bd1ca6a3e67d60e5587485de9ad3ad2a5f9e8cbe7add95622364e4c094a757035482c35377ab75cb14926af1f5ab8a0df0e5069ba69f7bed1851
6
+ metadata.gz: 49bd5ad54611d46c9379e98f53c0ae789949d5104b225af51a54e7d4780e274a9a9bbcff1322c5af641dadd4c5d8d633b94b1271436ef1767bd9eb869dcb6be5
7
+ data.tar.gz: 12cd7e5be2218aeaf9a0833dd95ce40be9d2ee248933962e3f24e854ab5335dd25b2a86b9f6ecb2c6a7e24759dcf316a9db0e8aca8841a5365e6c8030882ac76
data/CHANGELOG.md CHANGED
@@ -6,6 +6,46 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.3.1] - 2022-04-22
10
+
11
+ ### Changed
12
+
13
+ - `SyntaxTree::If` nodes inside of `SyntaxTree::Command` arguments should include a space before if they are flat.
14
+
15
+ ## [2.3.0] - 2022-04-22
16
+
17
+ ### Added
18
+
19
+ - [#52](https://github.com/ruby-syntax-tree/syntax_tree/pull/52) - `SyntaxTree::Formatter.format` for formatting an already parsed node.
20
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - `if` and `unless` can now be transformed into ternaries if they're simple enough.
21
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - Nicely format call chains by one indentation.
22
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - Handle trailing operators in call chains when they are necessary because of comments.
23
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - Add some specialized formatting for Sorbet `sig` blocks to make them appear nicer.
24
+
25
+ ### Changed
26
+
27
+ - [#53](https://github.com/ruby-syntax-tree/syntax_tree/pull/53) - Optional keyword arguments on method declarations have a value of `nil` now instead of `false`. This makes it easier to use the visitor.
28
+ - [#54](https://github.com/ruby-syntax-tree/syntax_tree/pull/54) - Flow control operators can now skip parentheses for simple, individual arguments. e.g., `break(1)` becomes `break 1`.
29
+ - [#54](https://github.com/ruby-syntax-tree/syntax_tree/pull/54) - Don't allow modifier conditionals to modify ternaries.
30
+ - [#55](https://github.com/ruby-syntax-tree/syntax_tree/pull/55) - Skip parentheses and brackets on arrays for flow control operators. e.g., `break([1, 2, 3])` becomes `break 1, 2, 3`.
31
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - Don't add parentheses to method calls if you don't need them.
32
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - Format comments on empty parameter sets. e.g., `def foo # bar` should keeps its comment.
33
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - `%s[]` symbols on assignments should not indent to the next line.
34
+ - [#56](https://github.com/ruby-syntax-tree/syntax_tree/pull/56) - Empty hash and array literals with comments inside of them should be formatted correctly.
35
+
36
+ ## [2.2.0] - 2022-04-19
37
+
38
+ ### Added
39
+
40
+ - [#51](https://github.com/ruby-syntax-tree/syntax_tree/pull/51) - `SyntaxTree::Location` nodes now have pattern matching.
41
+ - [#51](https://github.com/ruby-syntax-tree/syntax_tree/pull/51) - `SyntaxTree::Heredoc` now have a `dedent` field that indicates the number of spaces to strip from the beginning of the string content.
42
+
43
+ ### Changed
44
+
45
+ - [#51](https://github.com/ruby-syntax-tree/syntax_tree/pull/51) - `SyntaxTree::HshPtn` will now add a `then` if you use a bare `**` and `SyntaxTree::AryPtn` will do the same for a bare `*` on the end.
46
+ - [#51](https://github.com/ruby-syntax-tree/syntax_tree/pull/51) - `SyntaxTree::MLHSParen` now has a comma field in case a trailing comma has been added to a parenthesis destructuring, as in `((foo,))`.
47
+ - [#51](https://github.com/ruby-syntax-tree/syntax_tree/pull/51) - `SyntaxTree::FndPtn` has much improved parsing now.
48
+
9
49
  ## [2.1.1] - 2022-04-16
10
50
 
11
51
  ### Changed
@@ -153,7 +193,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
153
193
 
154
194
  - 🎉 Initial release! 🎉
155
195
 
156
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.1.1...HEAD
196
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.3.0...HEAD
197
+ [2.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.2.0...v2.3.0
198
+ [2.2.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.1.1...v2.2.0
157
199
  [2.1.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.1.0...v2.1.1
158
200
  [2.1.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.0.1...v2.1.0
159
201
  [2.0.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.0.0...v2.0.1
data/Gemfile CHANGED
@@ -3,8 +3,3 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
-
7
- gem "benchmark-ips"
8
- gem "parser"
9
- gem "ruby_parser"
10
- gem "stackprof"
data/Gemfile.lock CHANGED
@@ -1,28 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree (2.1.1)
4
+ syntax_tree (2.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.2)
10
- benchmark-ips (2.10.0)
11
9
  docile (1.4.0)
12
10
  minitest (5.15.0)
13
- parser (3.1.2.0)
14
- ast (~> 2.4.1)
15
11
  rake (13.0.6)
16
- ruby_parser (3.19.1)
17
- sexp_processor (~> 4.16)
18
- sexp_processor (4.16.0)
19
12
  simplecov (0.21.2)
20
13
  docile (~> 1.1)
21
14
  simplecov-html (~> 0.11)
22
15
  simplecov_json_formatter (~> 0.1)
23
16
  simplecov-html (0.12.3)
24
- simplecov_json_formatter (0.1.3)
25
- stackprof (0.2.19)
17
+ simplecov_json_formatter (0.1.4)
26
18
 
27
19
  PLATFORMS
28
20
  arm64-darwin-21
@@ -32,15 +24,11 @@ PLATFORMS
32
24
  x86_64-linux
33
25
 
34
26
  DEPENDENCIES
35
- benchmark-ips
36
27
  bundler
37
28
  minitest
38
- parser
39
29
  rake
40
- ruby_parser
41
30
  simplecov
42
- stackprof
43
31
  syntax_tree!
44
32
 
45
33
  BUNDLED WITH
46
- 2.2.31
34
+ 2.3.6
data/bin/bench CHANGED
@@ -1,12 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "benchmark/ips"
4
+ require "bundler/inline"
6
5
 
7
- require_relative "../lib/syntax_tree"
8
- require "ruby_parser"
9
- require "parser/current"
6
+ gemfile do
7
+ source "https://rubygems.org"
8
+ gem "benchmark-ips"
9
+ gem "parser", require: "parser/current"
10
+ gem "ruby_parser"
11
+ end
12
+
13
+ $:.unshift(File.expand_path("../lib", __dir__))
14
+ require "syntax_tree"
10
15
 
11
16
  def compare(filepath)
12
17
  prefix = "#{File.expand_path("..", __dir__)}/"
@@ -30,7 +35,7 @@ filepaths = ARGV
30
35
  if filepaths.empty?
31
36
  filepaths = [
32
37
  File.expand_path("bench", __dir__),
33
- File.expand_path("../lib/syntax_tree.rb", __dir__)
38
+ File.expand_path("../lib/syntax_tree/node.rb", __dir__)
34
39
  ]
35
40
  end
36
41
 
data/bin/profile CHANGED
@@ -1,19 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "stackprof"
4
+ require "bundler/inline"
6
5
 
7
- filepath = File.expand_path("../lib/syntax_tree", __dir__)
8
- require_relative filepath
6
+ gemfile do
7
+ source "https://rubygems.org"
8
+ gem "stackprof"
9
+ end
10
+
11
+ $:.unshift(File.expand_path("../lib", __dir__))
12
+ require "syntax_tree"
9
13
 
10
14
  GC.disable
11
15
 
12
16
  StackProf.run(mode: :cpu, out: "tmp/profile.dump", raw: true) do
13
- SyntaxTree.format(File.read("#{filepath}.rb"))
17
+ filepath = File.expand_path("../lib/syntax_tree/node.rb", __dir__)
18
+ SyntaxTree.format(File.read(filepath))
14
19
  end
15
20
 
16
21
  GC.enable
17
22
 
18
- `bundle exec stackprof --d3-flamegraph tmp/profile.dump > tmp/flamegraph.html`
19
- puts "open tmp/flamegraph.html"
23
+ File.open("tmp/flamegraph.html", "w") do |file|
24
+ report = Marshal.load(IO.binread("tmp/profile.dump"))
25
+ StackProf::Report.new(report).print_d3_flamegraph(file)
26
+ end
27
+
28
+ `open tmp/flamegraph.html`
@@ -17,6 +17,13 @@ module SyntaxTree
17
17
  @quote = "\""
18
18
  end
19
19
 
20
+ def self.format(source, node)
21
+ formatter = new(source, [])
22
+ node.format(formatter)
23
+ formatter.flush
24
+ formatter.output.join
25
+ end
26
+
20
27
  def format(node, stackable: true)
21
28
  stack << node if stackable
22
29
  doc = nil
@@ -43,7 +50,7 @@ module SyntaxTree
43
50
  # Print all comments that were found after the node.
44
51
  trailing.each do |comment|
45
52
  line_suffix(priority: COMMENT_PRIORITY) do
46
- text(" ")
53
+ comment.inline? ? text(" ") : breakable
47
54
  comment.format(self)
48
55
  break_parent
49
56
  end