Skip to content

Commit

Permalink
tools: enable ESLint no-sparse-arrays rule
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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>
  • Loading branch information
Trott authored and Linkgoron committed Jan 31, 2022
1 parent e67e9de commit 291b12b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/get_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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',
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]");
Expand Down Expand Up @@ -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 }'],
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-util-isDeepStrictEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 291b12b

Please sign in to comment.