Make `trailingComma` option more granular
See original GitHub issueThis code:
a(b.map(function(c) { return c; }));
is formatted like this:
a(
b.map(function(c) {
return c;
}),
);
with extra comma in a function call.
Demo: https://jlongster.github.io/prettier/#{"content"%3A"a(b.map(function(c) { return c%3B }))%3B%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Atrue%2C%22trailingComma%22%3Atrue%2C%22bracketSpacing%22%3Atrue%7D%7D
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How to force jscodeshift/recast to keep trailing commas in ...
Recast has a trailing comma option: ... toSource({trailingComma: true}); ... you can also use it this way for more granularity:
Read more >Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >Configuring Rustfmt
Controls how imports are structured in use statements. Imports will be merged or split to the configured level of granularity. Similar to other...
Read more >Define a Log Inspection rule for use in policies | Deep Security
The easiest way to define a rule is to select Basic Rule and use the options provided to define the rule. If you...
Read more >tslint | Yarn - Package Manager
Please see https://github.com/palantir/tslint/issues/4534 for more information. An extensible static analysis linter for the TypeScript language.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d lean towards the
--trailing-commas
option just not adding them to function calls. The benefit of trailing commas is mostly apparent when adding elements to a list or reordering them and having better git diffs.Its quite rare that you have a lot of instances in a codebase where there are enough arguments in a function call to warrant that they be on multiple lines and that you’ll change those arguments often enough to reap the benefits of trailing commas (vs. the pain of having to manually edit/ignore files from the formatting).
Ran into a good reason not to add trailing commas to function params: the node LTS doesn’t support it! It’s all well and good that babel transpiles my web code es2017, but I’ve purposefully stuck with es2015 in my node code so I don’t have to introduce that complexity.