Skip to content
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

prefer-object-spread rule should not report Object.assign({}, ...array) #10344

Closed
ehmicky opened this issue May 12, 2018 · 3 comments
Closed
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly good first issue Good for people who haven't worked on ESLint before rule Relates to ESLint's core rules

Comments

@ehmicky
Copy link

ehmicky commented May 12, 2018

Tell us about your environment

  • ESLint Version: 5.0.0-alpha.3
  • Node Version: 10.1.0
  • npm Version: 5.6.0

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

Please show your full configuration:

Configuration
root: true
parserOptions:
  ecmaVersion: 2018
  sourceType: script
rules:
  prefer-object-spread: 2

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

const objects = array.map(mapObject)
const var = Object.assign({}, ...objects)
eslint .

What did you expect to happen?
Object.assign() should not be reported as wrong. There is no way to use object spreads in this example because objects is an array of objects. It is not possible to use object spreads to concatenate an array of objects (e.g. [{ ... }, { ... }]) into a single object.

The prefer-object-spread rule should not report a linting error when one of the arguments to Object.assign() uses an array spread.

This also means the above line with --fix would be converted to { ...objects } which is incorrect.

What actually happened? Please include the actual, raw output from ESLint.
Object.assign() was reported as wrong.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label May 12, 2018
@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 12, 2018
@not-an-aardvark
Copy link
Member

Thanks for the report, I can reproduce this issue. I agree that the rule shouldn't report this case.

@not-an-aardvark not-an-aardvark added the good first issue Good for people who haven't worked on ESLint before label May 12, 2018
@platinumazure
Copy link
Member

Question: Should the rule report for a case where the spread argument is later on? (e.g., Object.assign({}, foo, ...others))

@ljharb
Copy link
Sponsor Contributor

ljharb commented May 14, 2018

Indeed, argument spreading anywhere in the assign call requires using Object.assign, and this shouldn’t report.

However, yes, i think it should, if possible, force the latter example to Object.assign({ ...foo }, ...others)

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 14, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly good first issue Good for people who haven't worked on ESLint before rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants