New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint doesn't support spread operator in objects #10307

Closed
PassTheMayo opened this Issue May 3, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@PassTheMayo
Copy link

PassTheMayo commented May 3, 2018

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}

@eslint eslint bot added the triage label May 3, 2018

@platinumazure

This comment has been minimized.

Copy link
Member

platinumazure commented 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).

@platinumazure platinumazure added question and removed triage labels May 3, 2018

@PassTheMayo

This comment has been minimized.

Copy link
Author

PassTheMayo commented May 3, 2018

Oh, okay thank you!

@PassTheMayo PassTheMayo closed this May 3, 2018

@mapleeit

This comment has been minimized.

Copy link

mapleeit commented May 24, 2018

Hi, @platinumazure , Object Rest/Spread Properties is a feature of ECMAScript 6.
Why setting { "env":{ "es6": true } } can't support this?
A little confused, I'll be appreciated if you give me a hint.

@platinumazure

This comment has been minimized.

Copy link
Member

platinumazure commented May 24, 2018

Hi @mapleeit, ES6 introduced array spread and function rest parameters, but object rest/spread is not part of ES6. Object rest was introduced in ES2018.

Our parser has supported an experimental syntax for rest/spread since that proposal was in Stage 2. Also, I'm sure babel-eslint has supported it for a while. However, object rest/spread did not officially enter the language until ES2018.

@mapleeit

This comment has been minimized.

Copy link

mapleeit commented May 24, 2018

Thanks!

@loginov-rocks

This comment has been minimized.

Copy link

loginov-rocks commented 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.

@eslint eslint bot locked and limited conversation to collaborators Oct 31, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.