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.

Version 3.8.0 comma-dangle breaks Flowtype annotations when a object rest parameter is used

See original GitHub issue

Tell us about your environment

  • ESLint Version: v3.8.0
  • Node Version: v6.7.0
  • npm Version: 3.10.3

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

Please show your full configuration:

.eslintrc.js

module.exports = {
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module"
    },
    "env": {
        "es6": true,
        "node": true
    },
    "plugins": [
        "flowtype",
        "flow-vars"
    ],
    "extends": "eslint:recommended",
    "rules": {
        "comma-dangle": [
            "error",
            "always-multiline"
        ],
    }
};

.babelrc

{
  "plugins": [
    "transform-flow-comments",
    "transform-function-bind",
    "transform-async-to-generator",
    "transform-exponentiation-operator",
    "transform-class-properties",
    "transform-es2015-destructuring",
    "transform-es2015-spread",
    "transform-es2015-parameters",
    "transform-object-rest-spread",
    "transform-es2015-classes",
    "transform-es2015-modules-commonjs"
  ]
}

What did you do? Please include the actual source code causing the issue. I created a “minimal” demo to reproduce the problem. My impression is that since 3.8.0 (it works on 3.7.1) comma-dangle (set to always-multiline) reports a comma in a flow annotation when a object rest parameter is used before.

Complete demo code: https://gist.github.com/mormahr/e6af53438a9bae9b9fe8905cc938b77d

export default class AntragsEvent {
    id: ?string
    rest: any

    constructor({
        id,
        ...rest, // <- this (the object rest spread) is causing
    }: {
        id?: string, // <- this comma to be reported by comma-dangle
    }) {
        this.id = id
        this.rest = rest
    }
}

What did you expect to happen? No report of an unexpected comma

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

[PRIVATE]/CommaDangleBug/test.js 9:14 error Unexpected trailing comma comma-dangle

✖ 1 problem (1 error, 0 warnings)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Oct 17, 2016

I understand that you’re using babel, but a trailing comma after a rest property is not valid syntax even according to the current proposal spec, because there is nothing that could follow a rest property.

The same thing applies with the already-standardized rest elements:

const [
  foo,
  ...bar, // <-- This is a syntax error in ES6
] = baz;

In order to be more compliant with the spec, babel’s parser temporarily reported this as a syntax error, but it was later reverted due to breakage.

The fix in this case is to simply remove the comma, so that it becomes valid syntax according to the Stage 3 proposal.

1reaction
not-an-aardvarkcommented, Oct 15, 2016

For what it’s worth, I think your syntax is invalid based on the current version of the rest/spread spec; trailing commas aren’t allowed after rest properties, since no property could actually be added after it. (See https://github.com/eslint/eslint/issues/7297 for more info.)

class Foo {
  constructor ({
    bar,
    ...baz, // <-- trailing comma is not allowed here according to rest/spread spec
  }) {}
}

Does the problem go away if you remove that comma?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Annotations | Flow
Adding type annotations is an important part of your interaction with Flow. Flow has a powerful ability to infer the types of your...
Read more >
eslint - UNPKG
... fix linebreaks between versions in changelog (#13488) (Milos Djermanovic) ... Fix: remove type arguments in prefer-object-spread (fixes #13058) (#13063) ...
Read more >
typeerror: cannot read property 'location' of undefined jest
I have managed to find a solution to run the test successfully. The test's code is as follows (with notes for referencing):.
Read more >
Asking for required annotations - Medium
The next release of Flow, version 0.85.0, includes an important bug fix that ... If a module exports a function, its parameters are...
Read more >
Test-Driven React - Library
Many of the designations used by manufacturers and sellers to distinguish their ... major version when making any breaking change. ... + enzyme@3.8.0....
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