diff options
Diffstat (limited to 'tools/eslint/lib/rules/no-array-constructor.js')
-rw-r--r-- | tools/eslint/lib/rules/no-array-constructor.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-array-constructor.js b/tools/eslint/lib/rules/no-array-constructor.js new file mode 100644 index 0000000000..a37d674c80 --- /dev/null +++ b/tools/eslint/lib/rules/no-array-constructor.js @@ -0,0 +1,29 @@ +/** + * @fileoverview Disallow construction of dense arrays using the Array constructor + * @author Matt DuVall <http://www.mattduvall.com/> + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = function(context) { + + function check(node) { + if ( + node.arguments.length !== 1 && + node.callee.type === "Identifier" && + node.callee.name === "Array" + ) { + context.report(node, "The array literal notation [] is preferrable."); + } + } + + return { + "CallExpression": check, + "NewExpression": check + }; + +}; |