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 incorrectly considers out-of-scope variables #14045

Closed
tkalliom opened this issue Jan 27, 2021 · 1 comment
Closed

require-atomic-updates incorrectly considers out-of-scope variables #14045

tkalliom opened this issue Jan 27, 2021 · 1 comment
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon

Comments

@tkalliom
Copy link

Tell us about your environment

  • ESLint Version: v7.18.0
  • Node Version: v10.23.1
  • npm Version: v6.14.8

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

Please show your full configuration:

Configuration
module.exports = {
    "env": {
        "node": true,
        "es2021": true
    },
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "rules": {
        "require-atomic-updates": ["warn"]
    }
};

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 getOtherList() {
    return Promise.resolve([{tag: "other"}]);
}

const main = async function () {
    const list = [{tag: "something"}];
    for (const item of list) {
        console.log(item.tag);
    }

    const otherList = await getOtherList();
    for (const item of list) {
        const match = otherList.find(o => o.tag === item.tag); // warning for this line
        console.log(match);
    }
}
npx eslint index.js

What did you expect to happen?
No warning to be produced, since there is no asynchronicity involved in the second loop.

What actually happened? Please include the actual, raw output from ESLint.

  12:5  warning  Possible race condition: `const item` might be reassigned based on an outdated value of `const item`  require-atomic-updates

✖ 1 problem (0 errors, 1 warning)

For comparison, the following code – with only the name of the iteration variable changed – produces no warnings.

async function getOtherList() {
    return Promise.resolve([{tag: "other"}]);
}

const main = async function () {
    const list = [{tag: "something"}];
    for (const item of list) {
        console.log(item.tag);
    }

    const otherList = await getOtherList();
    for (const item2 of list) {
        const match = otherList.find(o => o.tag === item2.tag); // warning for this line
        console.log(match);
    }
}

Are you willing to submit a pull request to fix this bug?
no

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

Duplicate of #11899

@aladdin-add aladdin-add marked this as a duplicate of #11899 Jan 27, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 29, 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 Jul 29, 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 bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

2 participants