summaryrefslogtreecommitdiff
path: root/.eslintrc.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-10 15:37:51 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-13 18:50:35 +0100
commit32853c0a136b0616844cdf5c276d2f1eb9a4fc50 (patch)
treed16b0fd161a3f8af6ec0407a74a71d42606a83c3 /.eslintrc.js
parent5f38797ea51886708fbde22527fc54e64382925c (diff)
downloadandroid-node-v8-32853c0a136b0616844cdf5c276d2f1eb9a4fc50.tar.gz
android-node-v8-32853c0a136b0616844cdf5c276d2f1eb9a4fc50.tar.bz2
android-node-v8-32853c0a136b0616844cdf5c276d2f1eb9a4fc50.zip
lib,test: improve faulty assert usage detection
This improves our custom eslint rules to detect assertions to detect assertions with only a single argument and fixes false negatives in case unary expressions are used. Some rules were extended to also lint our docs and tools and the lib rule was simplified to prohibit most assertion calls. PR-URL: https://github.com/nodejs/node/pull/26569 Refs: https://github.com/nodejs/node/pull/26565 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to '.eslintrc.js')
-rw-r--r--.eslintrc.js48
1 files changed, 40 insertions, 8 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 23b707b55d..f8e6e78769 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -170,32 +170,32 @@ module.exports = {
message: '__defineSetter__ is deprecated.',
},
],
- // If this list is modified, please copy the change to lib/.eslintrc.yaml
- // and test/.eslintrc.yaml.
+ // If this list is modified, please copy changes that should apply to ./lib
+ // as well to lib/.eslintrc.yaml.
'no-restricted-syntax': [
'error',
{
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='deepStrictEqual'][arguments.2.type='Literal']",
+ selector: "CallExpression[callee.property.name='deepStrictEqual'][arguments.2.type='Literal']",
message: 'Do not use a literal for the third argument of assert.deepStrictEqual()',
},
{
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='doesNotThrow']",
+ selector: "CallExpression[callee.property.name='doesNotThrow']",
message: 'Please replace `assert.doesNotThrow()` and add a comment next to the code instead.',
},
{
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='rejects'][arguments.length<2]",
+ selector: "CallExpression[callee.property.name='rejects'][arguments.length<2]",
message: '`assert.rejects()` must be invoked with at least two arguments.',
},
{
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='strictEqual'][arguments.2.type='Literal']",
+ selector: "CallExpression[callee.property.name='strictEqual'][arguments.2.type='Literal']",
message: 'Do not use a literal for the third argument of assert.strictEqual()',
},
{
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
+ selector: "CallExpression[callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
message: 'Use an object as second argument of `assert.throws()`.',
},
{
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]",
+ selector: "CallExpression[callee.property.name='throws'][arguments.length<2]",
message: '`assert.throws()` must be invoked with at least two arguments.',
},
{
@@ -210,6 +210,38 @@ module.exports = {
selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]',
message: 'Use `new` keyword when throwing an `Error`.',
},
+ {
+ selector: "CallExpression[callee.property.name='notDeepStrictEqual'][arguments.length<2]",
+ message: 'assert.notDeepStrictEqual() must be invoked with at least two arguments.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='deepStrictEqual'][arguments.length<2]",
+ message: 'assert.deepStrictEqual() must be invoked with at least two arguments.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='notStrictEqual'][arguments.length<2]",
+ message: 'assert.notStrictEqual() must be invoked with at least two arguments.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='strictEqual'][arguments.length<2]",
+ message: 'assert.strictEqual() must be invoked with at least two arguments.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='notDeepStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
+ message: 'The first argument should be the `actual`, not the `expected` value.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='notStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
+ message: 'The first argument should be the `actual`, not the `expected` value.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='deepStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
+ message: 'The first argument should be the `actual`, not the `expected` value.',
+ },
+ {
+ selector: "CallExpression[callee.property.name='strictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
+ message: 'The first argument should be the `actual`, not the `expected` value.',
+ }
],
/* eslint-enable max-len */
'no-return-await': 'error',