UNPKG

1.22 kBJavaScriptView Raw
1/**
2 * @fileoverview Disallow construction of dense arrays using the Array constructor
3 * @author Matt DuVall <http://www.mattduvall.com/>
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow `Array` constructors",
16 category: "Stylistic Issues",
17 recommended: false
18 },
19
20 schema: []
21 },
22
23 create(context) {
24
25 /**
26 * Disallow construction of dense arrays using the Array constructor
27 * @param {ASTNode} node node to evaluate
28 * @returns {void}
29 * @private
30 */
31 function check(node) {
32 if (
33 node.arguments.length !== 1 &&
34 node.callee.type === "Identifier" &&
35 node.callee.name === "Array"
36 ) {
37 context.report({ node, message: "The array literal notation [] is preferrable." });
38 }
39 }
40
41 return {
42 CallExpression: check,
43 NewExpression: check
44 };
45
46 }
47};