From bc32a7feac9793bf78cf0412c1425c056867306f Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Fri, 18 Aug 2023 13:50:38 +0700 Subject: [PATCH] review `eslint` core rules: disallow `null` comparisons without type-checking operators --- packages/core-js-builder/index.js | 4 ++-- packages/core-js-compat/compat.js | 2 +- packages/core-js/internals/regexp-sticky-helpers.js | 4 ++-- tests/eslint/eslint.config.js | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/core-js-builder/index.js b/packages/core-js-builder/index.js index 411ce39ab752..77e89edf4a76 100644 --- a/packages/core-js-builder/index.js +++ b/packages/core-js-builder/index.js @@ -36,7 +36,7 @@ module.exports = async function ({ if (!['bundle', 'cjs', 'esm'].includes(format)) throw TypeError('Incorrect output type'); summary = { comment: normalizeSummary(summary.comment), console: normalizeSummary(summary.console) }; - const TITLE = filename != null ? filename : '`core-js`'; + const TITLE = filename !== null || filename !== undefined ? filename : '`core-js`'; let script = banner; let code = '\n'; @@ -95,7 +95,7 @@ module.exports = async function ({ } else console.log('\u001B[36mnothing\u001B[0m'); } - if (filename != null) { + if (!(filename === null || filename === undefined)) { await mkdirp(dirname(filename)); await writeFile(filename, script); } diff --git a/packages/core-js-compat/compat.js b/packages/core-js-compat/compat.js index b932315004fc..8e919ffab591 100644 --- a/packages/core-js-compat/compat.js +++ b/packages/core-js-compat/compat.js @@ -56,7 +56,7 @@ module.exports = function ({ version = null, inverse = false, } = {}) { - if (modules == null) modules = filter; + if (modules === null || modules === undefined) modules = filter; inverse = !!inverse; const parsedTargets = targets ? targetsParser(targets) : null; diff --git a/packages/core-js/internals/regexp-sticky-helpers.js b/packages/core-js/internals/regexp-sticky-helpers.js index 114069d6df35..060e3028586b 100644 --- a/packages/core-js/internals/regexp-sticky-helpers.js +++ b/packages/core-js/internals/regexp-sticky-helpers.js @@ -8,7 +8,7 @@ var $RegExp = global.RegExp; var UNSUPPORTED_Y = fails(function () { var re = $RegExp('a', 'y'); re.lastIndex = 2; - return re.exec('abcd') != null; + return re.exec('abcd') !== null; }); // UC Browser bug @@ -21,7 +21,7 @@ var BROKEN_CARET = UNSUPPORTED_Y || fails(function () { // https://bugzilla.mozilla.org/show_bug.cgi?id=773687 var re = $RegExp('^r', 'gy'); re.lastIndex = 2; - return re.exec('str') != null; + return re.exec('str') !== null; }); module.exports = { diff --git a/tests/eslint/eslint.config.js b/tests/eslint/eslint.config.js index ce0f14dd50b8..09d1b81b1be9 100644 --- a/tests/eslint/eslint.config.js +++ b/tests/eslint/eslint.config.js @@ -154,6 +154,8 @@ const base = { 'no-empty-function': ERROR, // disallow empty static blocks 'no-empty-static-block': ERROR, + // disallow `null` comparisons without type-checking operators + 'no-eq-null': ERROR, // disallow use of eval() 'no-eval': ERROR, // disallow adding to native types