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

Auto fix no-unneeded-ternary changes code behavior #8507

Closed
feross opened this issue Apr 25, 2017 · 1 comment
Closed

Auto fix no-unneeded-ternary changes code behavior #8507

feross opened this issue Apr 25, 2017 · 1 comment
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 rule Relates to ESLint's core rules

Comments

@feross
Copy link
Contributor

feross commented Apr 25, 2017

Tell us about your environment

  • ESLint Version: 3.19.0
  • Node Version: 7.9.0
  • npm Version: 4.5.0

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

Please show your full configuration:

    "no-unneeded-ternary": ["error", { "defaultAssignment": false }],

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

The following code (line 3) is considered an error by the no-unneeded-ternary rule.

var value = 'a'
var canSet = true
var result = value ? value : canSet ? 'unset' : 'can not set'
// NOTE: `result` is 'a'

When --fix is used, it is corrected to code that has different behavior. See:

var value = 'a'
var canSet = true
var result = value || canSet ? 'unset' : 'can not set'
// NOTE: `result` is 'unset'

What did you expect to happen?

Parens should probably be added in this situation. This code would have maintained the same behavior:

var result = value || (canSet ? 'unset' : 'can not set')

Related issue: standard/standard#866

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Apr 25, 2017
@not-an-aardvark
Copy link
Member

Thanks for reporting, I can reproduce this bug.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Apr 26, 2017
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 Feb 6, 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 rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants