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: #41463
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
  • Loading branch information
Trott authored and targos committed Jan 14, 2022
1 parent afa4f37 commit 8090ce7
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 8090ce7

Please sign in to comment.