Commit 23fc205
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: #40634
Backport-PR-URL: #42021
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>1 parent 74c0464 commit 23fc205Copy full SHA for 23fc205
File tree
Expand file treeCollapse file tree
42 files changed
+111
-107
lines changedOpen diff view settings
Filter options
- test
- es-module
- js-native-api/test_conversions
- parallel
- pseudo-tty
- report
- sequential
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Expand file treeCollapse file tree
42 files changed
+111
-107
lines changedOpen diff view settings
Collapse file
+4Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
13 | 13 | |
14 | 14 | |
15 | 15 | |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
16 | 20 | |
17 | 21 | |
18 | 22 | |
|
Collapse file
test/es-module/test-esm-data-urls.js
Copy file name to clipboardExpand all lines: test/es-module/test-esm-data-urls.js+9-9Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | | - |
| 18 | + |
19 | 19 | |
20 | 20 | |
21 | 21 | |
| ||
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | | - |
| 38 | + |
39 | 39 | |
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | | - |
| 45 | + |
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | | - |
| 52 | + |
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | | - |
| 59 | + |
60 | 60 | |
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | | - |
| 65 | + |
66 | 66 | |
67 | 67 | |
68 | 68 | |
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | | - |
| 72 | + |
73 | 73 | |
74 | 74 | |
75 | 75 | |
| ||
84 | 84 | |
85 | 85 | |
86 | 86 | |
87 | | - |
| 87 | + |
88 | 88 | |
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | 92 | |
93 | 93 | |
94 | | - |
| 94 | + |
95 | 95 | |
96 | 96 | |
97 | 97 | |
|
Collapse file
test/js-native-api/test_conversions/test.js
Copy file name to clipboardExpand all lines: test/js-native-api/test_conversions/test.js+4-4Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
118 | 118 | |
119 | 119 | |
120 | 120 | |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
125 | 125 | |
126 | 126 | |
127 | 127 | |
|
Collapse file
test/parallel/test-assert-deep.js
Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js+2Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
858 | 858 | |
859 | 859 | |
860 | 860 | |
| 861 | + |
861 | 862 | |
862 | 863 | |
863 | 864 | |
864 | 865 | |
865 | 866 | |
| 867 | + |
866 | 868 | |
867 | 869 | |
868 | 870 | |
|
Collapse file
test/parallel/test-assert.js
Copy file name to clipboardExpand all lines: test/parallel/test-assert.js+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1243 | 1243 | |
1244 | 1244 | |
1245 | 1245 | |
| 1246 | + |
1246 | 1247 | |
1247 | 1248 | |
1248 | 1249 | |
|
Collapse file
test/parallel/test-crypto-hmac.js
Copy file name to clipboardExpand all lines: test/parallel/test-crypto-hmac.js+4-4Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
422 | 422 | |
423 | 423 | |
424 | 424 | |
425 | | - |
426 | | - |
| 425 | + |
| 426 | + |
427 | 427 | |
428 | 428 | |
429 | 429 | |
| ||
440 | 440 | |
441 | 441 | |
442 | 442 | |
443 | | - |
444 | | - |
| 443 | + |
| 444 | + |
445 | 445 | |
446 | 446 | |
447 | 447 | |
|
Collapse file
test/parallel/test-dns-lookup.js
Copy file name to clipboardExpand all lines: test/parallel/test-dns-lookup.js+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
137 | 137 | |
138 | 138 | |
139 | 139 | |
140 | | - |
| 140 | + |
141 | 141 | |
142 | 142 | |
143 | 143 | |
|
Collapse file
+4-4Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
337 | 337 | |
338 | 338 | |
339 | 339 | |
340 | | - |
341 | | - |
342 | | - |
343 | | - |
| 340 | + |
| 341 | + |
| 342 | + |
| 343 | + |
344 | 344 | |
345 | 345 | |
346 | 346 | |
|
Collapse file
test/parallel/test-error-serdes.js
Copy file name to clipboardExpand all lines: test/parallel/test-error-serdes.js+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | | - |
| 67 | + |
68 | 68 | |
Collapse file
test/parallel/test-fs-promises-file-handle-chmod.js
Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises-file-handle-chmod.js+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | | - |
| 22 | + |
23 | 23 | |
24 | 24 | |
25 | 25 | |
|
0 commit comments