question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make `trailingComma` option more granular

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

21reactions
tabazevedocommented, Jan 31, 2017

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).

9reactions
joefiorinicommented, Feb 3, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found