Skip to content

disallow trailing function commas #787

Closed
@ungoldman

Description

I ran into a weird edge case where a trailing comma was introduced into a function call, like so:

foo(
  arg1,
  arg2,
)

The linter didn't catch this, and surprisingly the parser didn't catch this either (running in electron, node fork currently at 6.5.0) and it ran fine without throwing a syntax error on macOS, but then failed due to a syntax error on windows (same electron app, same version, theoretically exact same context other than OS).

This was a little surprising for a number of reasons (edit: found out after the fact this is a babel/ES2017 feature I was unaware of), but I think the only one relevant to standard is that trailing function commas are allowed with the current eslint config.

I learned that the comma-dangle rule's string option allows trailing function commas by default.

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.

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.

ref: http://eslint.org/docs/rules/comma-dangle

So if standard should disallow trailing function commas, it needs to explicitly set the comma-dangle object option like so:

"comma-dangle": ["error", {
  "arrays": "never",
  "objects": "never",
  "imports": "never",
  "exports": "never",
  "functions": "never"
}]

If you'd like me to open an issue or PR on eslint-config-standard please let me know.

Thanks!

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions