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 <[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 7b0e4e2 commit 4254315

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

‎.eslintrc.js‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function validateDecoder(obj){
6363
}
6464

6565
functionvalidateArgument(prop,expected,propName,expectedName){
66+
// eslint-disable-next-line valid-typeof
6667
if(typeofprop!==expected)
6768
thrownewERR_INVALID_ARG_TYPE(propName,expectedName,prop);
6869
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@ function foo(){}
1111
constcallsfoo=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(typeoftracker.report()[0]==='undefined'){
23-
process.exit(1);
24-
}
20+
assert.strictEqual(typeoftracker.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)