Gathering a bunch of syntaxes where we don't allow trailing commas. Feel free to add yours here
let animal: NotHuman.animal = {
id: None,
};
Error: 2539: <UNKNOWN SYNTAX ERROR>
type foo = myType(
a,
);
type foo = myType(
a,
b,
);
let bar = {
a,
};
let bar = {
a: a,
};
let bar = {
"a": a,
};
let bar = {
"a": a,
"b": b,
};
let bar = {
.
a: a,
};
let bar = {
..
a: a,
};
let baz = (
a,
) => 1;
let baz = (
a,
b,
) => 1;
let baz = (
type a,
) => 1;
let baz = (
type a,
type b,
) => 1;
Option 1: Better error messages:
Options 2: Leniently parse them, even if removed upon print.
Any other ideas?
@jordwalke is there any way to allow and enforce trailing commas?
Definitely option 2. No error message is better than having error + manual correction.
@bsansouci Yes, we can allow and enforce them. You'd typically only want the trailing comma if it immediately preceeds a line break. Our formatting utilities don't provide facilities for those kinds of conditional separators, but the solution is surprisingly easy. You insert some dummy text that you replace in a final post-processing stage. However, I'd like to make sure that doesn't slow down refmt printing significantly by adding another pass over the output. Either way, first step would be to parse it (and print it as it currently prints).
I didn't see function calls yet.
let foo = baz(
a,
b,
);
Does it make sense to allow them in ConstructorExpr(1,2,3,)?
If they're allowed in function calls, I'd want them to also be allowed in Ctor instantiation. It's least surprising that way.
Lists would be nice too
let foo = [
'a',
'b',
'c',
];
All solved.
Most helpful comment
Definitely option 2. No error message is better than having error + manual correction.