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.

ESLint doesn't support spread operator in objects

See original GitHub issue

Tell us about your environment

  • ESLint Version: v4.19.1
  • Node Version: v9.10.0
  • npm Version: v5.6.0

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

Please show your full configuration:

Configuration
{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true,
        "node": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "sourceType": "module"
    },
    "rules": {
        "indent": [
            "error",
            "tab"
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

passport.use(new Discord.Strategy({ passReqToCallback: true, ...config.discord }, (req, accessToken, refreshToken, profile, done) => {
	r.table('users').insert(profile, { conflict: 'replace' }).run((error) => {
		if (error) return done(error, null);
		done(null, profile);
	});
}));
eslint .

What did you expect to happen? I expected ESLint not to throw an error, as JavaScript allows using the spread operator inside of an object.

What actually happened? Please include the actual, raw output from ESLint. ESLint threw an error at me.

/Users/jacobgunther/Documents/equinoxbot.xyz/src/auth.js
  12:63  error  Parsing error: Unexpected token ..

Just to let you know, this is what the spread operator is used for:

const object = {
    a: 1,
    b: 2,
    c: 3
};

console.log({ d: 4, ...object }); // { a: 1, b: 2, c: 3, d: 4}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
platinumazurecommented, May 3, 2018

Hi @PassTheMayo, thanks for the issue.

ESLint does support object rest/spread, but you have to opt in via configuration. You can either set your ecmaVersion to 2018 (in parserOptions), or set ecmaFeatures.experimentalObjectRestSpread to true (also in parserOptions, note the need to create an ecmaFeatures object).

6reactions
loginov-rockscommented, Jun 29, 2018

Here https://eslint.org/docs/user-guide/configuring it’s specified the following:

ecmaVersion - set to 3, 5 (default), 6, 7, 8, or 9 to specify the version of ECMAScript syntax you want to use. You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), or 2018 (same as 9) to use the year-based naming.

Setting ecmaVersion to 9 or 2018 with ESLint 5.0.1 doesn’t help:

{
  "extends": [
    "eslint:recommended",
    "google"
  ],
  "parserOptions": {
    "ecmaVersion": 9,
    "sourceType": "module"
  }
}

provides:

   6:47  error  'Set' is not defined                                 no-undef
  36:10  error  Expected parentheses around arrow function argument  arrow-parens
  37:13  error  Expected parentheses around arrow function argument  arrow-parens

like 9 or 2018 versions are not recognized. What can be the reason?

UPD: Had to add env.eslint like so:

{
  "env": {
    "es6": true
  },
  "extends": [
    "eslint:recommended",
    "google"
  ],
  "parserOptions": {
    "ecmaVersion": 9,
    "sourceType": "module"
  }
}

and it helped.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spread operator and EsLint - javascript
I want to copy object and change one of ...
Read more >
rest-spread-spacing - ESLint - Pluggable JavaScript Linter
This rule aims to enforce consistent spacing between rest and spread operators and their expressions. The rule also supports object rest and spread ......
Read more >
ESLint equivalents in Elm
disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead. Elm doesn't support ...
Read more >
Airbnb JavaScript Style Guide()
3.8 Prefer the object spread operator over Object.assign to shallow-copy objects. ... 6.5 Do not unnecessarily escape characters in strings. eslint: ...
Read more >
Why using object spread with reduce probably a bad idea
Not going too deep into the implementation details of how it works, but when you use the spread operator like the above example, ......
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