From 609a310e2a46c26969deaae7919e44dbd618fb49 Mon Sep 17 00:00:00 2001
From: Rich Trott <rtrott@gmail.com>
Date: Sun, 9 Jan 2022 07:57:37 -0800
Subject: [PATCH] tools: enable ESLint no-sparse-arrays rule
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

PR-URL: https://github.com/nodejs/node/pull/41463
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
---
 .eslintrc.js                                 | 1 +
 lib/internal/modules/esm/get_format.js       | 2 +-
 test/parallel/test-assert-deep.js            | 2 ++
 test/parallel/test-util-inspect.js           | 3 ++-
 test/parallel/test-util-isDeepStrictEqual.js | 2 ++
 5 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/.eslintrc.js b/.eslintrc.js
index ff4e95d98ac0d4..e0e099a3238a60 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -275,6 +275,7 @@ module.exports = {
     'no-self-compare': 'error',
     'no-setter-return': 'error',
     'no-shadow-restricted-names': 'error',
+    'no-sparse-arrays': 'error',
     'no-tabs': 'error',
     'no-template-curly-in-string': 'error',
     'no-this-before-super': 'error',
diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js
index 7c07e5b1f7ce17..58173a6bd55f89 100644
--- a/lib/internal/modules/esm/get_format.js
+++ b/lib/internal/modules/esm/get_format.js
@@ -43,7 +43,7 @@ const protocolHandlers = ObjectAssign(ObjectCreate(null), {
     const { 1: mime } = RegExpPrototypeExec(
       /^([^/]+\/[^;,]+)(?:[^,]*?)(;base64)?,/,
       parsed.pathname,
-    ) || [, null];
+    ) || [, null]; // eslint-disable-line no-sparse-arrays
     const format = ({
       '__proto__': null,
       'text/javascript': 'module',
diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js
index c74ca48d26cb74..f067ad83dc0e69 100644
--- a/test/parallel/test-assert-deep.js
+++ b/test/parallel/test-assert-deep.js
@@ -567,8 +567,10 @@ assertNotDeepOrStrict(
 
 // Handle sparse arrays.
 {
+  /* eslint-disable no-sparse-arrays */
   assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
   assertNotDeepOrStrict([1, , , 3], [1, , , 3, , , ]);
+  /* eslint-enable no-sparse-arrays */
   const a = new Array(3);
   const b = new Array(3);
   a[2] = true;
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index 26b21c4a8854fe..029b7cde8a06f8 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -434,7 +434,7 @@ assert.strictEqual(
 
 // Array with extra properties.
 {
-  const arr = [1, 2, 3, , ];
+  const arr = [1, 2, 3, , ]; // eslint-disable-line no-sparse-arrays
   arr.foo = 'bar';
   assert.strictEqual(util.inspect(arr),
                      "[ 1, 2, 3, <1 empty item>, foo: 'bar' ]");
@@ -2142,6 +2142,7 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
   [function() {}, '[Function (anonymous)]'],
   [() => {}, '[Function (anonymous)]'],
   [[1, 2], '[ 1, 2 ]'],
+  // eslint-disable-next-line no-sparse-arrays
   [[, , 5, , , , ], '[ <2 empty items>, 5, <3 empty items> ]'],
   [{ a: 5 }, '{ a: 5 }'],
   [new Set([1, 2]), 'Set(2) { 1, 2 }'],
diff --git a/test/parallel/test-util-isDeepStrictEqual.js b/test/parallel/test-util-isDeepStrictEqual.js
index 1ad64c2ff81a57..da266fc84ce0bb 100644
--- a/test/parallel/test-util-isDeepStrictEqual.js
+++ b/test/parallel/test-util-isDeepStrictEqual.js
@@ -409,8 +409,10 @@ notUtilIsDeepStrict(
 }
 
 // Handle sparse arrays
+/* eslint-disable no-sparse-arrays */
 utilIsDeepStrict([1, , , 3], [1, , , 3]);
 notUtilIsDeepStrict([1, , , 3], [1, , , 3, , , ]);
+/* eslint-enable no-sparse-arrays */
 
 // Handle different error messages
 {