Urara-Blog/node_modules/.pnpm-store/v3/files/66/cee2ea2610a9108c6159190aadf1dde6c522502a31e8a66b6d2b2b12128f7c4f6dc4640dbedb184300ddae5ba2e6bc6abf740a0d35f80468145e408568d27f
2022-08-14 01:14:53 +08:00

54 lines
1.4 KiB
Text

/**
* @fileoverview Disallow construction of dense arrays using the Array constructor
* @author Matt DuVall <http://www.mattduvall.com/>
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Disallow `Array` constructors",
recommended: false,
url: "https://eslint.org/docs/rules/no-array-constructor"
},
schema: [],
messages: {
preferLiteral: "The array literal notation [] is preferable."
}
},
create(context) {
/**
* Disallow construction of dense arrays using the Array constructor
* @param {ASTNode} node node to evaluate
* @returns {void}
* @private
*/
function check(node) {
if (
node.arguments.length !== 1 &&
node.callee.type === "Identifier" &&
node.callee.name === "Array"
) {
context.report({ node, messageId: "preferLiteral" });
}
}
return {
CallExpression: check,
NewExpression: check
};
}
};