The trailingCommas option is based on esnext when Prettier is turned on. But why is this the case? Neither XO nor Prettier allow trailingComma by default.
That's an opinionated choice. Trailing comma allow to make git diff a lot clearer.
You can disable it by setting the trailingComma in your Prettier conf. That would take precedence over what XO sets.
But XO doesn't set trailingComma when used by itself?
Yes, indeed. We should have more consistency there, either by enabling both if esnext is true or disabling both.
Not sure which direction we want to go. @sindresorhus do you have a preference?
Why is it enabled when esnext is false? I think it should always be disabled since that's what xo use.
Why is it enabled when esnext is false?
Currently, it's enabled when esnext is true, disabled when it's false
The readme says esnext is enabled by default. But, as linked earlier, comma-dangle is turned off by default in xo?
Currently, it's enabled when esnext is true, disabled when it's false
Sorry, I meant the other way around. But the question still stands, why enable it at all for prettier when it's always false in xo?
This is why I said it should be consistent. Either we change the XO config to add the trailing comma when esnext is true or we change the Prettier config generated by XO to not add the comma.
The trailing comma makes git diff more readable and allow to find which git commit modified which property in an array or object more accurately, so it might make sense to enable it when esnext is true.
See https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8
The trailing comma makes git diff more readable and allow to find which git commit modified which property in an array or object more accurately, so it might make sense to enable it when esnext is true.
I'm still not personally sold on trailing commas and it would be a pretty controversial change. I kinda agree with the code manipulation argument, but it's never bothered me very much. The Git argument is just trying to fix the problem in the wrong place. The solution there is better Git diffs.
I agree with @sindresorhus and think that trailing commas should probably not be added to XO.
The current behavior, and the reason for this issue, is that trailing commas are turned on with Prettier which contradicts XO's defaults and Prettier's defaults.
Most helpful comment
I'm still not personally sold on trailing commas and it would be a pretty controversial change. I kinda agree with the code manipulation argument, but it's never bothered me very much. The Git argument is just trying to fix the problem in the wrong place. The solution there is better Git diffs.