Browse Source

No trailing comma after generator in lists

This fix another edgecase where adding a trailing comma after the last
item (a generator) in a list results in invalid code. Fixes #151.
pull/152/head
Fredrik Ekre 5 months ago
parent
commit
a5bff799e6
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 5
      CHANGELOG.md
  2. 3
      src/runestone.jl
  3. 2
      test/runtests.jl

5
CHANGELOG.md

@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.4.4] - 2025-07-24
### Fixed
- Fix another edgecase where adding a trailing comma after the last item in a list results
in invalid code. ([#151], [#152]).
## [v1.4.3] - 2025-02-28 ## [v1.4.3] - 2025-02-28
### Fixed ### Fixed
- Fix formatting of floating point literals that use `−` (Unicode U+2212) instead of the - Fix formatting of floating point literals that use `−` (Unicode U+2212) instead of the

3
src/runestone.jl

@ -340,6 +340,9 @@ function spaces_in_listlike(ctx::Context, node::Node)
allow_trailing_comma = multiline allow_trailing_comma = multiline
if kind(node) in KSet"call dotcall macrocall" if kind(node) in KSet"call dotcall macrocall"
require_trailing_comma = false require_trailing_comma = false
elseif n_items > 0 && kind(kids[last_item_idx::Int]) === K"generator"
# https://github.com/fredrikekre/Runic.jl/issues/151
require_trailing_comma = false
elseif implicit_tuple elseif implicit_tuple
# Trailing commas in implicit tuples in the LHS of an assignment, e.g. `x, = 1, 2`, # Trailing commas in implicit tuples in the LHS of an assignment, e.g. `x, = 1, 2`,
# is required for single item tuples and allowed for multiple items (to allow e.g. # is required for single item tuples and allowed for multiple items (to allow e.g.

2
test/runtests.jl

@ -447,6 +447,8 @@ end
# Edge case with comment and no items # Edge case with comment and no items
@test format_string("[# a\n]") == "[# a\n]" @test format_string("[# a\n]") == "[# a\n]"
@test format_string("[ # a\n]") == "[ # a\n]" @test format_string("[ # a\n]") == "[ # a\n]"
# https://github.com/fredrikekre/Runic.jl/issues/151
@test format_string("(\n a, b for b in B\n)") == "(\n a, b for b in B\n)"
end end
@testset "whitespace in let" begin @testset "whitespace in let" begin

Loading…
Cancel
Save