Skip to content

Commit

Permalink
Breaking: comma-dangle enable functions: "never" (fixes #11502) (#11519)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add authored and not-an-aardvark committed Apr 4, 2019
1 parent 12f256f commit 4e7cdca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 1 addition & 4 deletions docs/rules/comma-dangle.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ This rule has a string option or an object option:
"objects": "never",
"imports": "never",
"exports": "never",
"functions": "ignore"
"functions": "never"
}]
}
```
Expand All @@ -58,8 +58,6 @@ This rule has a string option or an object option:
* `"always-multiline"` requires trailing commas when the last element or property is in a *different* line than the closing `]` or `}` and disallows trailing commas when the last element or property is on the *same* line as the closing `]` or `}`
* `"only-multiline"` allows (but does not require) trailing commas when the last element or property is in a *different* line than the closing `]` or `}` and disallows trailing commas when the last element or property is on the *same* line as the closing `]` or `}`

Trailing commas in function declarations and function calls are valid syntax since ECMAScript 2017; however, the string option does not check these situations for backwards compatibility.

You can also use an object option to configure this rule for each type of syntax.
Each of the following options can be set to `"never"`, `"always"`, `"always-multiline"`, `"only-multiline"`, or `"ignore"`.
The default for each option is `"never"` unless otherwise specified.
Expand All @@ -69,7 +67,6 @@ The default for each option is `"never"` unless otherwise specified.
* `imports` is for import declarations of ES Modules. (e.g. `import {a,} from "foo";`)
* `exports` is for export declarations of ES Modules. (e.g. `export {a,};`)
* `functions` is for function declarations and function calls. (e.g. `(function(a,){ })(b,);`)
* `functions` is set to `"ignore"` by default for consistency with the string option.
* `functions` should only be enabled when linting ECMAScript 2017 or higher.

### never
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/comma-dangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DEFAULT_OPTIONS = Object.freeze({
objects: "never",
imports: "never",
exports: "never",
functions: "ignore"
functions: "never"
});

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-eslint/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rules:
camelcase: "error"
callback-return: ["error", ["cb", "callback", "next"]]
class-methods-use-this: "error"
comma-dangle: ["error", { functions: "never" }]
comma-dangle: "error"
comma-spacing: "error"
comma-style: ["error", "last"]
computed-property-spacing: "error"
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/comma-dangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,14 @@ let d = 0;export {d,};
options: [{ functions: "never" }],
parser: parser("return-type-2"),
errors: [{ messageId: "unexpected" }]
},

// https://github.com/eslint/eslint/issues/11502
{
code: "foo(a,)",
output: "foo(a)",
parserOptions: { ecmaVersion: 8 },
errors: [{ messageId: "unexpected" }]
}
]
});

0 comments on commit 4e7cdca

Please sign in to comment.