Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

trailing-comma for single line regression between 3.3.0 and 3.5.0? #999

Closed
tomduncalf opened this issue Feb 26, 2016 · 3 comments
Closed

Comments

@tomduncalf
Copy link
Contributor

Since upgrading to 3.5.0, I'm getting errors reported for single lines missing a trailing comma, even though the rules are set up like:

"trailing-comma": [true, {
  "singleline": "never",
  "multiline": "always"
}],

Here is an example line of code which now fails lint under 3.5.0, which used to pass in 3.3.0 with the same rules:

return expectBothTypesEqual(form, {
  'recurringAmount': 'recurringAmount:typeError'
})
  • it now requires a comma after the second line, which seems incorrect.

Is this a regression or a change in the spec of this rule?

@adidahiya
Copy link
Contributor

This is a change in the spec of the rule, or rather a correction of it. The intent of the trailing-comma rule is to make code diffs more precise. Multiline literals should always have trailing commas because the addition of a member should only produce a one-line diff. In your example, a 2-line diff would be produced if you added a field, like this:

return expectBothTypesEqual(form, {
  'recurringAmount': 'recurringAmount:typeError',
  'somethingElse': 'foo'
})

Full details here #856

@tomduncalf
Copy link
Contributor Author

Got ya, that makes perfect sense. I thought it was because single comma
objects should never contain more than one item, so you wouldn't need to be
there as you'd never append another item. The diff thing is actually more
useful :) Will update my code, thanks

@tomduncalf
Copy link
Contributor Author

Indeed, sorry should have closed that myself!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants