Skip to content

Commit fc38aa3

Browse files
authored
Fix trailing comma in YAS (#1226)
Closes #1225
1 parent f4ba32c commit fc38aa3

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

HISTORY_v2.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.11.2
2+
3+
Fixed a bug where YASStyle would insert a trailing comma for a function call with zero arguments, which is invalid Julia syntax. (#1225, #1226)
4+
15
# v2.11.1
26

37
Fixed a bug where formatting a do-block with no argument after the `do` would cause YASStyle to crash. (#1219, #1221)

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "JuliaFormatter"
22
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
3-
version = "2.11.1"
3+
version = "2.11.2"
44
authors = ["Dominique Luna <dluna132@gmail.com> and contributors"]
55

66
[workspace]

src/styles/yas/pretty.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,12 @@ function p_call(
362362
# case where the last argument is followed by a comment, the closing paren will
363363
# be placed on the next line, and in that case we want to allow a trailing
364364
# comma.
365-
k === K")" && add_node!(t, TrailingComma(), s)
365+
# If `i == first_arg_idx`, then the function call is empty. In such cases adding
366+
# a trailing comma causes a syntax error, so don't do it
367+
if k === K")" && i != first_arg_idx
368+
add_node!(t, TrailingComma(), s)
369+
end
370+
366371
add_node!(
367372
t,
368373
n,

test/issues.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,27 @@ end
35813581
end"""
35823582
test_format(s, s, YASStyle(); margin=30)
35833583
end
3584+
3585+
@testset "1225 YAS trailing comma with zero args" begin
3586+
s_ = """
3587+
f(
3588+
# Hi
3589+
)"""
3590+
s = """
3591+
f(
3592+
# Hi
3593+
)"""
3594+
test_format(s_, s, YASStyle())
3595+
3596+
s_ = """
3597+
f(
3598+
#= Hi =#
3599+
)"""
3600+
s = """
3601+
f(
3602+
#= Hi =#)"""
3603+
test_format(s_, s, YASStyle())
3604+
end
35843605
end
35853606

35863607
end

0 commit comments

Comments
 (0)