tools: improve valid-typeof lint rule
Require that `typeof` comparisons be to string literals. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
f34e88a18d
commit
adcd60eee6
@ -307,7 +307,7 @@ module.exports = {
|
||||
'template-curly-spacing': 'error',
|
||||
'unicode-bom': 'error',
|
||||
'use-isnan': 'error',
|
||||
'valid-typeof': 'error',
|
||||
'valid-typeof': ['error', { requireStringLiterals: true }],
|
||||
|
||||
// Custom rules from eslint-plugin-node-core
|
||||
'node-core/no-unescaped-regexp-dot': 'error',
|
||||
|
@ -64,6 +64,7 @@ function validateDecoder(obj) {
|
||||
}
|
||||
|
||||
function validateArgument(prop, expected, propName, expectedName) {
|
||||
// eslint-disable-next-line valid-typeof
|
||||
if (typeof prop !== expected)
|
||||
throw new ERR_INVALID_ARG_TYPE(propName, expectedName, prop);
|
||||
}
|
||||
|
@ -11,22 +11,16 @@ function foo() {}
|
||||
const callsfoo = tracker.calls(foo, 1);
|
||||
|
||||
// Ensures that foo was added to the callChecks array.
|
||||
if (tracker.report()[0].operator !== 'foo') {
|
||||
process.exit(1);
|
||||
}
|
||||
assert.strictEqual(tracker.report()[0].operator, 'foo');
|
||||
|
||||
callsfoo();
|
||||
|
||||
// Ensures that foo was removed from the callChecks array after being called the
|
||||
// expected number of times.
|
||||
if (typeof tracker.report()[0] === 'undefined') {
|
||||
process.exit(1);
|
||||
}
|
||||
assert.strictEqual(typeof tracker.report()[0], 'undefined');
|
||||
|
||||
callsfoo();
|
||||
|
||||
// Ensures that foo was added back to the callChecks array after being called
|
||||
// more than the expected number of times.
|
||||
if (tracker.report()[0].operator !== 'foo') {
|
||||
process.exit(1);
|
||||
}
|
||||
assert.strictEqual(tracker.report()[0].operator, 'foo');
|
||||
|
Loading…
x
Reference in New Issue
Block a user