Skip to content

Commit 4254315

Browse files
Trotttargos
authored andcommitted
tools: improve valid-typeof lint rule
Require that `typeof` comparisons be to string literals. PR-URL: #37924 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7b0e4e2 commit 4254315

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
@@ -287,7 +287,7 @@ module.exports = {
287287
'template-curly-spacing': 'error',
288288
'unicode-bom': 'error',
289289
'use-isnan': 'error',
290-
'valid-typeof': 'error',
290+
'valid-typeof': ['error', { requireStringLiterals: true }],
291291

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

lib/internal/encoding.js

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

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

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)