Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2022-07-27 01:38:24 +0300
committerJuan José Arboleda <soyjuanarbol@gmail.com>2022-10-11 22:45:08 +0300
commit3aaa4109a06ed761b23250d21005f3048134a788 (patch)
tree6bff0c2865ade65983ed836a522e74623fd86054 /tools
parentdff6615bbe8044972d9338ccacbd379cf442b1ed (diff)
lib: add `Promise` methods to `avoid-prototype-pollution` lint rule
PR-URL: https://github.com/nodejs/node/pull/43849 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Diffstat (limited to 'tools')
-rw-r--r--tools/eslint-rules/avoid-prototype-pollution.js32
1 files changed, 28 insertions, 4 deletions
diff --git a/tools/eslint-rules/avoid-prototype-pollution.js b/tools/eslint-rules/avoid-prototype-pollution.js
index 1f71272bd7d..d59b62f9502 100644
--- a/tools/eslint-rules/avoid-prototype-pollution.js
+++ b/tools/eslint-rules/avoid-prototype-pollution.js
@@ -109,11 +109,11 @@ module.exports = {
testRange.start = testRange.start + 'RegexpPrototype'.length;
testRange.end = testRange.start + 'Test'.length;
return [
- fixer.replaceTextRange(node.range, 'Exec'),
+ fixer.replaceTextRange(testRange, 'Exec'),
fixer.insertTextAfter(node, ' !== null'),
];
}
- }]
+ }],
});
},
[`${CallExpression}[expression.callee.name=${/^RegExpPrototypeSymbol(Match|MatchAll|Search)$/}]`](node) {
@@ -142,9 +142,33 @@ module.exports = {
}
context.report({
node,
- message: 'Proxy handler must be a null-prototype object'
+ message: 'Proxy handler must be a null-prototype object',
});
- }
+ },
+
+ [`${CallExpression}[expression.callee.name=PromisePrototypeCatch]`](node) {
+ context.report({
+ node,
+ message: '%Promise.prototype.catch% look up the `then` property of ' +
+ 'the `this` argument, use PromisePrototypeThen instead',
+ });
+ },
+
+ [`${CallExpression}[expression.callee.name=PromisePrototypeFinally]`](node) {
+ context.report({
+ node,
+ message: '%Promise.prototype.finally% look up the `then` property of ' +
+ 'the `this` argument, use SafePromisePrototypeFinally or ' +
+ 'try/finally instead',
+ });
+ },
+
+ [`${CallExpression}[expression.callee.name=${/^Promise(All(Settled)?|Any|Race)/}]`](node) {
+ context.report({
+ node,
+ message: `Use Safe${node.expression.callee.name} instead of ${node.expression.callee.name}`,
+ });
+ },
};
},
};