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

require-atomic-updates reports false positive when the assigned variable is used in a lambda and function call #11959

Closed
Liu233w opened this issue Jul 6, 2019 · 2 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint

Comments

@Liu233w
Copy link

Liu233w commented Jul 6, 2019

Tell us about your environment

I've built a simple example in ESLint Demo, my configuration is included in it.

  • ESLint Version:
    6.0.1

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

Please show your full configuration:

Configuration
{
    "parserOptions": {
        "ecmaVersion": 9,
        "sourceType": "script",
        "ecmaFeatures": {}
    },
    "rules": {
        "require-atomic-updates": 2
    },
    "env": {}
}

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

async function main() {
  let a = someFunc()
  a(()=>a) // change it to `f(()=>a)`, `a(a)` or `a(()=>b)` will all pass the lint
  a = await func() // Possible race condition: `a` might be reassigned based on an outdated value of `a`.
}

What did you expect to happen?
Pass without error

What actually happened? Please include the actual, raw output from ESLint.
Possible race condition: a might be reassigned based on an outdated value of a.

@Liu233w Liu233w added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jul 6, 2019
@mysticatea
Copy link
Member

Thank you for your report.

In fact, as based on the discussion in #11774, this is intentional behavior. ESLint cannot know when ()=>a function will be called, so the rule handles it as a possible race condition.

@mysticatea mysticatea added question This issue asks a question about ESLint and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jul 9, 2019
@Liu233w
Copy link
Author

Liu233w commented Jul 9, 2019

Thank you for your reply, @mysticatea .

According to the discussion, statements like f(()=>a) should also be marked as a possible race condition. But in the demo above, only a(()=>a) is reported, while f(()=>a) does not. Is that an intended behavior?

@Liu233w Liu233w closed this as completed Jul 9, 2019
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jan 6, 2020
@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 Jan 6, 2020
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 question This issue asks a question about ESLint
Projects
None yet
Development

No branches or pull requests

2 participants