Add a setting for adding trailing/dangling commas
See original GitHub issueDescription
Historically, certain versions of Internet Explorer did not allow trailing commas in arrays or object literals, or caused strange behaviour when they were present. These days, trailing commas are either removed by minification tools, or code is run in Internet Explorer 9 or later. As such, the advice for writing JavaScript code in many codebases has changed from removing trailing commas, to instead requiring them.
I would like to see an option, which would be off by default, for adding trailing commas to arrays and objects. (Possibly function argument lists and function calls with ES2017) Currently js-beautify will remove trailing commas, but this conflicts with the eslint
configuration which is set up in my codebase, which means that js-beautify cannot be used on the code in my codebase without also applying eslint --fix
, which isn’t the fastest thing in the world.
Input
var x = [
1,
2,
3,
];
var y = {
a: 1,
b: 2,
b: 3,
];
var missing_comma = [
1,
2
]
Expected Output
I want js-beautify
to leave my trailing commas alone, or add them.
var x = [
1,
2,
3,
];
var y = {
a: 1,
b: 2,
b: 3,
];
var missing_comma = [
1,
2,
]
Actual Output
js-beautify
instead removes all trailing/dangling commas.
var x = [
1,
2,
3
];
var y = {
a: 1,
b: 2,
b: 3
];
var missing_comma = [
1,
2
]
Steps to Reproduce
Run js-beautify
on any file containing the syntax in the example.
Environment
OS: Linux
Settings
I want a new setting for this. The current settings are irrelevant.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:26
- Comments:8 (2 by maintainers)
Top GitHub Comments
Is it possible to add this option? I went searching for it, and realised that I already added an issue a few months ago.
This seems like a moderate difficulty task.
PR’s are welcome but it will need some design discussion - this would be a change in philosophy for this project. There will also need to be extensive tests.