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.

"comma-dangle": [2, "always-multiline"] should not add trailing commas to function arguments

See original GitHub issue

http://eslint.org/docs/rules/comma-dangle#options

According to the eslint docs, “always-multiline” ignores functions by default. I believe that means that prettier-eslint should set prettier’s --trailing-comma option to es5 rather than all, unless functions: "always" is specified in eslint.

Relevant eslint config:

{
  "rules": {
    "comma-dangle": [2, "always-multiline"],
  }
}

Prettier command:

prettier --single-quote --no-semi --trailing-comma es5

Unformatted:

function someFunction(longParamater1, longParamater2, longParamater3, longParamater4) {
  return ''
}

Prettier + eslint --fix output:

function someFunction(
  longParamater1,
  longParamater2,
  longParamater3,
  longParamater4 // no comma
) {
  return ''
}

Prettier-eslint output:

function someFunction(
  longParamater1,
  longParamater2,
  longParamater3,
  longParamater4, // comma
) {
  return ''
}

Edit: It is possible to fix it using prettier-eslint --prettier.trailing-comma es5, but those options aren’t available when using prettier-atom.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

9reactions
echenleycommented, May 10, 2017

@enriquecaballero Are you trying to get trailing commas for all function arguments? If so, you need to set your eslint config to:

{
  "rules": {
    "comma-dangle": [2, {
      "arrays": "always-multiline",
      "objects": "always-multiline",
      "imports": "always-multiline",
      "exports": "always-multiline",
      "functions": "always-multiline"
    }]
  }
}

Either of the following will give you trailing commas for everything EXCEPT functions:

{
  "rules": {
    "comma-dangle": [2, "always-multiline"]
  }
}

// OR

{
  "rules": {
    "comma-dangle": [2, {
      "arrays": "always-multiline",
      "objects": "always-multiline",
      "imports": "always-multiline",
      "exports": "always-multiline",
      "functions": "ignore"
    }]
  }
}

Pretty sure setting this in your eslintrc should get you the same results for both prettier-eslint and prettier-eslint-cli. Could be wrong though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

comma-dangle - ESLint - Pluggable JavaScript Linter
Trailing commas simplify adding and removing items to objects and arrays, since only the lines you are modifying must be touched. Another argument...
Read more >
Why you should enforce Dangling Commas for Multiline ...
Personally, I prefer ESLint for JavaScript. Fortunately ESLint has the comma-dangle rule which allows you to enforce dangling commas for multiline statements.
Read more >
Why does this trigger comma-dangle rule in eslint?
Based on the airbnb config the rule is setup like this comma-dangle: [2, "always-multiline"] . Acoording to this, The expected code is
Read more >
Best practices for using trailing commas in JavaScript
We'll start with the common data types, like arrays and objects, where you can safely add a trailing comma to the end of...
Read more >
How to Allow Trailing Commas (Comma-Dangle) With ...
You can lint your TypeScript code and also require formatting rules using the ESLint config file. This config file is typically a .eslintrc...
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