Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2021-03-26 09:17:23 +0300
committerRich Trott <rtrott@gmail.com>2021-03-28 18:01:44 +0300
commitadcd60eee6b4ca1001e640638349e7ebc6c06e4b (patch)
tree5ba574de895b90c2edc3d8702cd1d4f711d10c3d
parentf34e88a18db506bf425ace5dfcc3aa32d449fe6f (diff)
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>
-rw-r--r--.eslintrc.js2
-rw-r--r--lib/internal/encoding.js1
-rw-r--r--test/parallel/test-assert-calltracker-report.js12
3 files changed, 5 insertions, 10 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 28a31d050a6..3f47ddf45d0 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -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',
diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js
index 560f0daeae7..f6e52238a12 100644
--- a/lib/internal/encoding.js
+++ b/lib/internal/encoding.js
@@ -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);
}
diff --git a/test/parallel/test-assert-calltracker-report.js b/test/parallel/test-assert-calltracker-report.js
index 64b068760ca..87ef0bff17f 100644
--- a/test/parallel/test-assert-calltracker-report.js
+++ b/test/parallel/test-assert-calltracker-report.js
@@ -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');