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

[no-sequences] does not trigger if comma is used in parentheses as part of a condition #14184

Closed
danielrentz opened this issue Mar 5, 2021 · 10 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion works as intended The behavior described in this issue is working correctly
Projects

Comments

@danielrentz
Copy link
Contributor

Tell us about your environment
Node version: v12.16.2
npm version: v6.14.4
Local ESLint version: v7.21.0 (Currently used)

Operating System:
Win10

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?
default

Please show your full configuration:

rules:
  no-sequences: error

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

Actual code:

        if ((x1 === x2) && (y1, y2)) {

Intended was

        if ((x1 === x2) && (y1 === y2)) {

What did you expect to happen?

When a comma-sequence in parentheses is part of a longer expression (arithmetic, logical, ...), this rule should not let it pass.

@danielrentz danielrentz added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Mar 5, 2021
@aladdin-add
Copy link
Member

it was by design, per the docs:

This rule forbids the use of the comma operator, with the following exceptions:

  • In the initialization or update portions of a for statement.
  • If the expression sequence is explicitly wrapped in parentheses.

you can entirely disallow comma operator with the no-restricted-syntax:

{
    "rules": {
        "no-restricted-syntax": ["error", "SequenceExpression"]
    }
}

@aladdin-add aladdin-add added this to Needs Triage in Triage via automation Mar 5, 2021
@aladdin-add aladdin-add moved this from Needs Triage to Triaging in Triage Mar 5, 2021
@aladdin-add aladdin-add added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Mar 5, 2021
@danielrentz
Copy link
Contributor Author

Hi @aladdin-add
thank you for the response. I know about this "by design" rule limitation, maybe this report should be labeled as "enhancement" instead of "bug".

The code example above is from our real code base, and it took me over an hour to track down the bug, because the faulty behavior is hidden in an short-circuiting AND expression. The improvement I am suggesting would have helped a lot here.

OTOH, the mentioned code base makes use of for-loops with multiple initializations, so completely disabling the comma operator is also not desirable...

@aladdin-add aladdin-add added enhancement This change enhances an existing feature of ESLint and removed bug ESLint is working incorrectly labels Mar 10, 2021
@aladdin-add
Copy link
Member

agreed it make sense to add an option to support it!

@aladdin-add aladdin-add moved this from Triaging to Ready for Dev Team in Triage Mar 10, 2021
@mdjermanovic mdjermanovic moved this from Ready for Dev Team to Evaluating in Triage Mar 10, 2021
@mdjermanovic
Copy link
Member

When a comma-sequence in parentheses is part of a longer expression (arithmetic, logical, ...), this rule should not let it pass.

It seems difficult to define this. What would be examples of a code with comma sequences that should pass?

@aladdin-add
Copy link
Member

aladdin-add commented Mar 10, 2021

just an option to report comma-sequence in parentheses (eslint ignore it atm). IMHO, the option could be enabled by default in next major release.

@mdjermanovic
Copy link
Member

just an option to report comma-sequence in parentheses (eslint ignore it atm).

Then, if the option is enabled, the rule would report all comma sequences except for those in for-loops? In other words, the option would just skip this check?

@aladdin-add
Copy link
Member

yes!

@mdjermanovic mdjermanovic added works as intended The behavior described in this issue is working correctly and removed enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Mar 10, 2021
@mdjermanovic
Copy link
Member

Makes sense to me 👍

@danielrentz I marked this issue as "works as intended" since it's indeed the intended behavior. If you agree with the solution to add an option described above, then could you please open a rule change request issue? That way, it would be much easier for the team to evaluate a concrete proposal.

@danielrentz
Copy link
Contributor Author

@mdjermanovic Yes, an option to skip (or enable) the "in-parentheses" exception would be fine for me.

@mdjermanovic
Copy link
Member

Thanks! Then, I'm closing this in favor of #14197

Triage automation moved this from Evaluating to Complete Mar 10, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Sep 7, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion works as intended The behavior described in this issue is working correctly
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

3 participants