UNPKG

896 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag use of constructors without capital letters
3 * @author Nicholas C. Zakas
4 */
5
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = function(context) {
12
13 "use strict";
14
15 return {
16 "NewExpression": function(node) {
17 var constructorName = "";
18
19 if (node.callee.type === "MemberExpression") {
20 constructorName = node.callee.property.name;
21 } else {
22 constructorName = node.callee.name;
23 }
24
25 if (constructorName && constructorName.charAt(0) === constructorName.charAt(0).toLowerCase()) {
26 context.report(node, "A constructor name should start with an uppercase letter.");
27 }
28 }
29 };
30
31};