From ed2b880da247f20f9330b6da4fc502d7affd4c4b Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 23 Jul 2026 17:26:35 +0800 Subject: [PATCH 1/2] Fix YAS trailing comma --- src/styles/yas/pretty.jl | 7 ++++++- test/issues.jl | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/styles/yas/pretty.jl b/src/styles/yas/pretty.jl index 8dca57fe9..6af8403de 100644 --- a/src/styles/yas/pretty.jl +++ b/src/styles/yas/pretty.jl @@ -362,7 +362,12 @@ function p_call( # case where the last argument is followed by a comment, the closing paren will # be placed on the next line, and in that case we want to allow a trailing # comma. - k === K")" && add_node!(t, TrailingComma(), s) + # If `i == first_arg_idx`, then the function call is empty. In such cases adding + # a trailing comma causes a syntax error, so don't do it + if k === K")" && i != first_arg_idx + add_node!(t, TrailingComma(), s) + end + add_node!( t, n, diff --git a/test/issues.jl b/test/issues.jl index ab1c393fb..a331f4fc0 100644 --- a/test/issues.jl +++ b/test/issues.jl @@ -3581,6 +3581,27 @@ end end""" test_format(s, s, YASStyle(); margin=30) end + + @testset "1225 YAS trailing comma with zero args" begin + s_ = """ + f( + # Hi + )""" + s = """ + f( + # Hi + )""" + test_format(s_, s, YASStyle()) + + s_ = """ + f( + #= Hi =# + )""" + s = """ + f( + #= Hi =#)""" + test_format(s_, s, YASStyle()) + end end end From ee71252339ec7ea273a03e3f7a622ae215677eb7 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 23 Jul 2026 17:27:20 +0800 Subject: [PATCH 2/2] Patch and changelog --- HISTORY_v2.md | 4 ++++ Project.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY_v2.md b/HISTORY_v2.md index af993b1c2..dd6a550f6 100644 --- a/HISTORY_v2.md +++ b/HISTORY_v2.md @@ -1,3 +1,7 @@ +# v2.11.2 + +Fixed a bug where YASStyle would insert a trailing comma for a function call with zero arguments, which is invalid Julia syntax. (#1225, #1226) + # v2.11.1 Fixed a bug where formatting a do-block with no argument after the `do` would cause YASStyle to crash. (#1219, #1221) diff --git a/Project.toml b/Project.toml index 259f5715b..81de24161 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "JuliaFormatter" uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899" -version = "2.11.1" +version = "2.11.2" authors = ["Dominique Luna and contributors"] [workspace]