mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 13:28:42 +00:00

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>
19 lines
463 B
JavaScript
19 lines
463 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
process.env.NODE_DISABLE_COLORS = true;
|
|
process.stderr.columns = 20;
|
|
|
|
// Confirm that there is no position indicator.
|
|
assert.throws(
|
|
() => { assert.strictEqual('a'.repeat(30), 'a'.repeat(31)); },
|
|
(err) => !err.message.includes('^')
|
|
);
|
|
|
|
// Confirm that there is a position indicator.
|
|
assert.throws(
|
|
() => { assert.strictEqual('aaaa', 'aaaaa'); },
|
|
(err) => err.message.includes('^')
|
|
);
|