Skip to content

Commit b7e7384

Browse files
Trottruyadorno
authored andcommitted
tools: improve valid-typeof lint rule
Require that `typeof` comparisons be to string literals. PR-URL: #37924 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e256c4d commit b7e7384

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ module.exports = {
307307
'template-curly-spacing': 'error',
308308
'unicode-bom': 'error',
309309
'use-isnan': 'error',
310-
'valid-typeof': 'error',
310+
'valid-typeof': ['error', { requireStringLiterals: true }],
311311

312312
// Custom rules from eslint-plugin-node-core
313313
'node-core/no-unescaped-regexp-dot': 'error',

lib/internal/encoding.js

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function validateDecoder(obj) {
6464
}
6565

6666
function validateArgument(prop, expected, propName, expectedName) {
67+
// eslint-disable-next-line valid-typeof
6768
if (typeof prop !== expected)
6869
throw new ERR_INVALID_ARG_TYPE(propName, expectedName, prop);
6970
}

test/parallel/test-assert-calltracker-report.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@ function foo() {}
1111
const callsfoo = tracker.calls(foo, 1);
1212

1313
// Ensures that foo was added to the callChecks array.
14-
if (tracker.report()[0].operator !== 'foo') {
15-
process.exit(1);
16-
}
14+
assert.strictEqual(tracker.report()[0].operator, 'foo');
1715

1816
callsfoo();
1917

2018
// Ensures that foo was removed from the callChecks array after being called the
2119
// expected number of times.
22-
if (typeof tracker.report()[0] === 'undefined') {
23-
process.exit(1);
24-
}
20+
assert.strictEqual(typeof tracker.report()[0], 'undefined');
2521

2622
callsfoo();
2723

2824
// Ensures that foo was added back to the callChecks array after being called
2925
// more than the expected number of times.
30-
if (tracker.report()[0].operator !== 'foo') {
31-
process.exit(1);
32-
}
26+
assert.strictEqual(tracker.report()[0].operator, 'foo');

0 commit comments

Comments
 (0)