From a5bff799e644f04af35db6211b2c5ae0e73c9e28 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Thu, 24 Jul 2025 14:51:35 +0200 Subject: [PATCH] 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. --- CHANGELOG.md | 5 +++++ src/runestone.jl | 3 +++ test/runtests.jl | 2 ++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5131a3f..0e4df16 100644 --- a/CHANGELOG.md +++ b/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/), 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 ### Fixed - Fix formatting of floating point literals that use `−` (Unicode U+2212) instead of the diff --git a/src/runestone.jl b/src/runestone.jl index 5c84dd2..9373e1f 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -340,6 +340,9 @@ function spaces_in_listlike(ctx::Context, node::Node) allow_trailing_comma = multiline if kind(node) in KSet"call dotcall macrocall" 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 # 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. diff --git a/test/runtests.jl b/test/runtests.jl index 3b4ccd7..6ae26e8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -447,6 +447,8 @@ end # Edge case with comment and no items @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 @testset "whitespace in let" begin