Eslint: comma-dangle auto fix introduces syntax error

Created on 12 Dec 2016  路  3Comments  路  Source: eslint/eslint

Tell us about your environment

  • ESLint Version: 3.11.1
  • Node Version: 7.2.1
  • npm Version: 4.0.3
  • eslint-config-airbnb-base Version 10.0.1

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

root: true
extends: airbnb-base

What did you do? Please include the actual source code causing the issue.

I let ESLint fix the issues.

#!/usr/bin/env node

console.log(
  'spam'
);

What did you expect to happen? Nothing

What actually happened? Please include the actual, raw output from ESLint.

Autofix added a comma after 'spam'. This is the resulting script:

#!/usr/bin/env node

console.log(
  'spam',
);

When running the "fixed" script using NodeJS throws a syntax error.

$ ./asd.js ./asd.js:5 ); ^ SyntaxError: Unexpected token ) at Object.exports.runInThisContext (vm.js:78:16) at Module._compile (module.js:543:28) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.runMain (module.js:605:10) at run (bootstrap_node.js:420:7) at startup (bootstrap_node.js:139:9) at bootstrap_node.js:535:3

archived due to age question

Most helpful comment

Hi, thanks for the report.

This is happening because you have the functions: true option enabled (via the airbnb-base config). Trailing function commas are valid syntax according to the latest spec, but they haven't been implemented in Node yet. Since the functions: true configuration requires these commas to be present, I think the autofixer is working as intended in this case.

To avoid the syntax error, you will probably want to disable the functions: option in your config with something like:

rules:
  comma-dangle: [error, always, {functions: never}]

All 3 comments

Hi, thanks for the report.

This is happening because you have the functions: true option enabled (via the airbnb-base config). Trailing function commas are valid syntax according to the latest spec, but they haven't been implemented in Node yet. Since the functions: true configuration requires these commas to be present, I think the autofixer is working as intended in this case.

To avoid the syntax error, you will probably want to disable the functions: option in your config with something like:

rules:
  comma-dangle: [error, always, {functions: never}]

oh ok, thanks!

Actually what you have to do to override aribnb-base is this:

rules:
  comma-dangle: [error, always-multiline, {functions: never}]

As they use config always-multiline.
https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js#L42

Was this page helpful?
0 / 5 - 0 ratings