UNPKG

855 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag non-camelcased identifiers
3 * @author Nicholas C. Zakas
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 return {
15
16 "Identifier": function(node) {
17 // Leading and trailing underscores are commonly used to flag private/protected identifiers, strip them
18 var name = node.name.replace(/^_+|_+$/g, "");
19
20 // if there's an underscore, it might be A_CONSTANT, which is okay
21 if (name.indexOf("_") > -1 && name !== name.toUpperCase()) {
22 context.report(node, "Identifier '{{name}}' is not in camel case.", { name: node.name });
23 }
24 }
25 };
26
27};