google_forms/node_modules/eslint/lib/rules/no-sparse-arrays.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-08-09 12:04:48 +00:00
/**
* @fileoverview Disallow sparse arrays
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
2024-08-21 06:34:30 +00:00
/** @type {import('../shared/types').Rule} */
2024-08-09 12:04:48 +00:00
module.exports = {
meta: {
type: "problem",
docs: {
2024-08-21 06:34:30 +00:00
description: "Disallow sparse arrays",
2024-08-09 12:04:48 +00:00
recommended: true,
2024-08-21 06:34:30 +00:00
url: "https://eslint.org/docs/latest/rules/no-sparse-arrays"
2024-08-09 12:04:48 +00:00
},
schema: [],
messages: {
unexpectedSparseArray: "Unexpected comma in middle of array."
}
},
create(context) {
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
return {
ArrayExpression(node) {
2024-08-21 06:34:30 +00:00
const emptySpot = node.elements.includes(null);
2024-08-09 12:04:48 +00:00
if (emptySpot) {
context.report({ node, messageId: "unexpectedSparseArray" });
}
}
};
}
};