Skip to content
Permalink
Browse files
Fix: require-atomic-updates property assignment message (fixes #15076) (
  • Loading branch information
mdjermanovic committed Oct 9, 2021
1 parent f885fe0 commit 2174a6f0e5d18b673604d31e3ca7b790cdc9429b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
@@ -179,7 +179,8 @@ module.exports = {
schema: [],

messages: {
nonAtomicUpdate: "Possible race condition: `{{value}}` might be reassigned based on an outdated value of `{{value}}`."
nonAtomicUpdate: "Possible race condition: `{{value}}` might be reassigned based on an outdated value of `{{value}}`.",
nonAtomicObjectUpdate: "Possible race condition: `{{value}}` might be assigned based on an outdated state of `{{object}}`."
}
},

@@ -275,13 +276,25 @@ module.exports = {
const variable = reference.resolved;

if (segmentInfo.isOutdated(codePath.currentSegments, variable)) {
context.report({
node: node.parent,
messageId: "nonAtomicUpdate",
data: {
value: sourceCode.getText(node.parent.left)
}
});
if (node.parent.left === reference.identifier) {
context.report({
node: node.parent,
messageId: "nonAtomicUpdate",
data: {
value: variable.name
}
});
} else {
context.report({
node: node.parent,
messageId: "nonAtomicObjectUpdate",
data: {
value: sourceCode.getText(node.parent.left),
object: variable.name
}
});
}

}
}
}
@@ -24,20 +24,20 @@ const VARIABLE_ERROR = {
};

const STATIC_PROPERTY_ERROR = {
messageId: "nonAtomicUpdate",
data: { value: "foo.bar" },
messageId: "nonAtomicObjectUpdate",
data: { value: "foo.bar", object: "foo" },
type: "AssignmentExpression"
};

const COMPUTED_PROPERTY_ERROR = {
messageId: "nonAtomicUpdate",
data: { value: "foo[bar].baz" },
messageId: "nonAtomicObjectUpdate",
data: { value: "foo[bar].baz", object: "foo" },
type: "AssignmentExpression"
};

const PRIVATE_PROPERTY_ERROR = {
messageId: "nonAtomicUpdate",
data: { value: "foo.#bar" },
messageId: "nonAtomicObjectUpdate",
data: { value: "foo.#bar", object: "foo" },
type: "AssignmentExpression"
};

@@ -328,6 +328,36 @@ ruleTester.run("require-atomic-updates", rule, {
}
`,
errors: [STATIC_PROPERTY_ERROR]
},

// https://github.com/eslint/eslint/issues/15076
{
code: `
async () => {
opts.spec = process.stdin;
try {
const { exit_code } = await run(opts);
process.exitCode = exit_code;
} catch (e) {
process.exitCode = 1;
}
};
`,
env: { node: true },
errors: [
{
messageId: "nonAtomicObjectUpdate",
data: { value: "process.exitCode", object: "process" },
type: "AssignmentExpression",
line: 6
},
{
messageId: "nonAtomicObjectUpdate",
data: { value: "process.exitCode", object: "process" },
type: "AssignmentExpression",
line: 8
}
]
}
]
});

0 comments on commit 2174a6f

Please sign in to comment.