syntax_tree 3.6.1 → 3.6.2

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: bd7e771d65269c131d28cd381186bb1e437e677d823f1219bc99a04d96d318c9
4
- data.tar.gz: 9be18db6c8108ce433ec1acc07d4bc5d47969cc8aeca04786b92911c6e9e11c8
3
+ metadata.gz: 2feb5b8df043a9d8c8a75e6cf16f42ef1b4f84877d64ad7fe91725e4f1c4f013
4
+ data.tar.gz: e1eca9750c08fca80ada1bc3d7831a996dc01fd9f8651cd4f1d6b8c9decff0ea
5
5
  SHA512:
6
- metadata.gz: f195700c3fbb9cd65ddf5a041e1fff5454aa4dc589b712d74205c126dd807b21e108e4c3d072a5af222f0cb22d1f9f45cf0cb70189498e86fbe6c80013f25622
7
- data.tar.gz: c85dcdff58830ec44d96cf66f7814df8549646c7e0d3a9ebcf2dee364f45e7a0a3c3b46198fb6f0791eed2fc87f0d0be973dcd4008d60ba17e2a50c6026d5de1
6
+ metadata.gz: d3e061694d3ae39053ee7b6a9ff41e1230cf714e23d037da307c720fccebd2f674505c15f74eb515e4b6b45050e665792039b8f897f8594ac7fbadc0142e4d6e
7
+ data.tar.gz: c81f87007866892f47afaa41cfe053c9af44126641fad5605e5130356791ee76fcf9bbc95082cb63bc64e4daf90051de3faeb40ec5a672d1717a7858bd830165
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.6.2] - 2022-10-04
10
+
11
+ ### Changed
12
+
13
+ - [#165](https://github.com/ruby-syntax-tree/syntax_tree/pull/165) - Conditionals (`if`/`unless`), loops (`for`/`while`/`until`) and lambdas all had issues when comments immediately succeeded the declaration of the node where the comment could potentially be dropped. That has now been fixed.
14
+ - [#166](https://github.com/ruby-syntax-tree/syntax_tree/pull/166) - Blocks can now be formatted even if they are the top node of the tree. Previously they were looking to their parent for some additional metadata, so we now handle the case where the parent is nil.
15
+
9
16
  ## [3.6.1] - 2022-09-28
10
17
 
11
18
  ### Changed
@@ -357,7 +364,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
357
364
 
358
365
  - 🎉 Initial release! 🎉
359
366
 
360
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.1...HEAD
367
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.2...HEAD
368
+ [3.6.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.1...v3.6.2
361
369
  [3.6.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.0...v3.6.1
362
370
  [3.6.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.5.0...v3.6.0
363
371
  [3.5.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.4.0...v3.5.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree (3.6.1)
4
+ syntax_tree (3.6.2)
5
5
  prettier_print
6
6
 
7
7
  GEM
@@ -1955,11 +1955,12 @@ module SyntaxTree
1955
1955
  # If the receiver of this block a Command or CommandCall node, then there
1956
1956
  # are no parentheses around the arguments to that command, so we need to
1957
1957
  # break the block.
1958
- receiver = q.parent.call
1959
- if receiver.is_a?(Command) || receiver.is_a?(CommandCall)
1958
+ case q.parent
1959
+ in { call: Command | CommandCall }
1960
1960
  q.break_parent
1961
1961
  format_break(q, break_opening, break_closing)
1962
1962
  return
1963
+ else
1963
1964
  end
1964
1965
 
1965
1966
  q.group do
@@ -1978,16 +1979,26 @@ module SyntaxTree
1978
1979
  # If we hit a statements, then we're safe to use whatever since we
1979
1980
  # know for certain we're going to get split over multiple lines
1980
1981
  # anyway.
1981
- break false if parent.is_a?(Statements) || parent.is_a?(ArgParen)
1982
-
1983
- [Command, CommandCall].include?(parent.class)
1982
+ case parent
1983
+ in Statements | ArgParen
1984
+ break false
1985
+ in Command | CommandCall
1986
+ true
1987
+ else
1988
+ false
1989
+ end
1984
1990
  end
1985
1991
  end
1986
1992
 
1987
1993
  # If we're a sibling of a control-flow keyword, then we're going to have to
1988
1994
  # use the do..end bounds.
1989
1995
  def forced_do_end_bounds?(q)
1990
- [Break, Next, Return, Super].include?(q.parent.call.class)
1996
+ case q.parent
1997
+ in { call: Break | Next | Return | Super }
1998
+ true
1999
+ else
2000
+ false
2001
+ end
1991
2002
  end
1992
2003
 
1993
2004
  # If we're the predicate of a loop or conditional, then we're going to have
@@ -2314,7 +2325,8 @@ module SyntaxTree
2314
2325
  end
2315
2326
 
2316
2327
  def format(q)
2317
- if operator == :"::" || (operator.is_a?(Op) && operator.value == "::")
2328
+ case operator
2329
+ in :"::" | Op[value: "::"]
2318
2330
  q.text(".")
2319
2331
  else
2320
2332
  operator.format(q)
@@ -6004,6 +6016,8 @@ module SyntaxTree
6004
6016
  q.group(0, "->") do
6005
6017
  if params.is_a?(Paren)
6006
6018
  q.format(params) unless params.contents.empty?
6019
+ elsif params.empty? && params.comments.any?
6020
+ q.format(params)
6007
6021
  elsif !params.empty?
6008
6022
  q.group do
6009
6023
  q.text("(")
@@ -302,8 +302,8 @@ module SyntaxTree
302
302
  def on_BEGIN(statements)
303
303
  lbrace = find_token(LBrace)
304
304
  rbrace = find_token(RBrace)
305
- start_char = find_next_statement_start(lbrace.location.end_char)
306
305
 
306
+ start_char = find_next_statement_start(lbrace.location.end_char)
307
307
  statements.bind(
308
308
  start_char,
309
309
  start_char - line_counts[lbrace.location.start_line - 1].start,
@@ -340,8 +340,8 @@ module SyntaxTree
340
340
  def on_END(statements)
341
341
  lbrace = find_token(LBrace)
342
342
  rbrace = find_token(RBrace)
343
- start_char = find_next_statement_start(lbrace.location.end_char)
344
343
 
344
+ start_char = find_next_statement_start(lbrace.location.end_char)
345
345
  statements.bind(
346
346
  start_char,
347
347
  start_char - line_counts[lbrace.location.start_line - 1].start,
@@ -831,8 +831,8 @@ module SyntaxTree
831
831
  lbrace = find_token(LBrace)
832
832
  rbrace = find_token(RBrace)
833
833
  location = (block_var || lbrace).location
834
- start_char = find_next_statement_start(location.end_char)
835
834
 
835
+ start_char = find_next_statement_start(location.end_char)
836
836
  statements.bind(
837
837
  start_char,
838
838
  start_char - line_counts[location.start_line - 1].start,
@@ -1329,8 +1329,8 @@ module SyntaxTree
1329
1329
 
1330
1330
  node = tokens[index]
1331
1331
  ending = node.value == "end" ? tokens.delete_at(index) : node
1332
- start_char = find_next_statement_start(keyword.location.end_char)
1333
1332
 
1333
+ start_char = find_next_statement_start(keyword.location.end_char)
1334
1334
  statements.bind(
1335
1335
  start_char,
1336
1336
  start_char - line_counts[keyword.location.start_line - 1].start,
@@ -1355,9 +1355,10 @@ module SyntaxTree
1355
1355
  beginning = find_token(Kw, "elsif")
1356
1356
  ending = consequent || find_token(Kw, "end")
1357
1357
 
1358
+ start_char = find_next_statement_start(predicate.location.end_char)
1358
1359
  statements.bind(
1359
- predicate.location.end_char,
1360
- predicate.location.end_column,
1360
+ start_char,
1361
+ start_char - line_counts[predicate.location.start_line - 1].start,
1361
1362
  ending.location.start_char,
1362
1363
  ending.location.start_column
1363
1364
  )
@@ -1598,9 +1599,12 @@ module SyntaxTree
1598
1599
  tokens.delete(keyword)
1599
1600
  end
1600
1601
 
1602
+ start_char =
1603
+ find_next_statement_start((keyword || collection).location.end_char)
1601
1604
  statements.bind(
1602
- (keyword || collection).location.end_char,
1603
- (keyword || collection).location.end_column,
1605
+ start_char,
1606
+ start_char -
1607
+ line_counts[(keyword || collection).location.end_line - 1].start,
1604
1608
  ending.location.start_char,
1605
1609
  ending.location.start_column
1606
1610
  )
@@ -1778,9 +1782,10 @@ module SyntaxTree
1778
1782
  beginning = find_token(Kw, "if")
1779
1783
  ending = consequent || find_token(Kw, "end")
1780
1784
 
1785
+ start_char = find_next_statement_start(predicate.location.end_char)
1781
1786
  statements.bind(
1782
- predicate.location.end_char,
1783
- predicate.location.end_column,
1787
+ start_char,
1788
+ start_char - line_counts[predicate.location.end_line - 1].start,
1784
1789
  ending.location.start_char,
1785
1790
  ending.location.start_column
1786
1791
  )
@@ -2024,9 +2029,10 @@ module SyntaxTree
2024
2029
  closing = find_token(Kw, "end")
2025
2030
  end
2026
2031
 
2032
+ start_char = find_next_statement_start(opening.location.end_char)
2027
2033
  statements.bind(
2028
- opening.location.end_char,
2029
- opening.location.end_column,
2034
+ start_char,
2035
+ start_char - line_counts[opening.location.end_line - 1].start,
2030
2036
  closing.location.start_char,
2031
2037
  closing.location.start_column
2032
2038
  )
@@ -3456,9 +3462,10 @@ module SyntaxTree
3456
3462
  beginning = find_token(Kw, "unless")
3457
3463
  ending = consequent || find_token(Kw, "end")
3458
3464
 
3465
+ start_char = find_next_statement_start(predicate.location.end_char)
3459
3466
  statements.bind(
3460
- predicate.location.end_char,
3461
- predicate.location.end_column,
3467
+ start_char,
3468
+ start_char - line_counts[predicate.location.end_line - 1].start,
3462
3469
  ending.location.start_char,
3463
3470
  ending.location.start_column
3464
3471
  )
@@ -3498,9 +3505,10 @@ module SyntaxTree
3498
3505
  end
3499
3506
 
3500
3507
  # Update the Statements location information
3508
+ start_char = find_next_statement_start(predicate.location.end_char)
3501
3509
  statements.bind(
3502
- predicate.location.end_char,
3503
- predicate.location.end_column,
3510
+ start_char,
3511
+ start_char - line_counts[predicate.location.end_line - 1].start,
3504
3512
  ending.location.start_char,
3505
3513
  ending.location.start_column
3506
3514
  )
@@ -3633,9 +3641,10 @@ module SyntaxTree
3633
3641
  end
3634
3642
 
3635
3643
  # Update the Statements location information
3644
+ start_char = find_next_statement_start(predicate.location.end_char)
3636
3645
  statements.bind(
3637
- predicate.location.end_char,
3638
- predicate.location.end_column,
3646
+ start_char,
3647
+ start_char - line_counts[predicate.location.end_line - 1].start,
3639
3648
  ending.location.start_char,
3640
3649
  ending.location.start_column
3641
3650
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxTree
4
- VERSION = "3.6.1"
4
+ VERSION = "3.6.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.1
4
+ version: 3.6.2
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-09-28 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prettier_print