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
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2021-10-27 19:15:11 +0300
committerNode.js GitHub Bot <github-bot@iojs.org>2021-11-02 13:11:49 +0300
commitdd52c05046bcc65746e26e2de65699dffcd454ee (patch)
tree1f29de45ed924f6846f8f2909066fc3264fd7156 /test/.eslintrc.yaml
parent229a182823aa5e60ee5420170ec11e9a541f2163 (diff)
test: avoid deep comparisons with literals
Comparing any value to any non-RegExp literal or undefined using strictEqual (or notStrictEqual) passes if and only if deepStrictEqual (or notDeepStrictEqual, respectively) passes. Unnecessarily using deep comparisons adds confusion. This patch adds an ESLint rule that forbids the use of deepStrictEqual and notDeepStrictEqual when the expected value (i.e., the second argument) is a non-RegExp literal or undefined. For reference, an ESTree literal is defined as follows. extend interface Literal <: Expression { type: "Literal"; value: string | boolean | null | number | RegExp | bigint; } The value `undefined` is an `Identifier` with `name: 'undefined'`. PR-URL: https://github.com/nodejs/node/pull/40634 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Voltrex <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'test/.eslintrc.yaml')
-rw-r--r--test/.eslintrc.yaml4
1 files changed, 4 insertions, 0 deletions
diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml
index 50c51ae5010..55e8ff6af8c 100644
--- a/test/.eslintrc.yaml
+++ b/test/.eslintrc.yaml
@@ -13,6 +13,10 @@ rules:
no-restricted-syntax:
# Config copied from .eslintrc.js
- error
+ - selector: "CallExpression:matches([callee.name='deepStrictEqual'], [callee.property.name='deepStrictEqual']):matches([arguments.1.type='Literal']:not([arguments.1.regex]), [arguments.1.type='Identifier'][arguments.1.name='undefined'])"
+ message: "Use strictEqual instead of deepStrictEqual for literals or undefined."
+ - selector: "CallExpression:matches([callee.name='notDeepStrictEqual'], [callee.property.name='notDeepStrictEqual']):matches([arguments.1.type='Literal']:not([arguments.1.regex]), [arguments.1.type='Identifier'][arguments.1.name='undefined'])"
+ message: "Use notStrictEqual instead of notDeepStrictEqual for literals or undefined."
- selector: "CallExpression:matches([callee.name='deepStrictEqual'], [callee.property.name='deepStrictEqual'])[arguments.2.type='Literal']"
message: "Do not use a literal for the third argument of assert.deepStrictEqual()"
- selector: "CallExpression:matches([callee.name='doesNotThrow'], [callee.property.name='doesNotThrow'])"