-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
37 lines (36 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function isClassUsage(node) {
return ['FunctionDeclaration', 'NewExpression', 'MemberExpression'].indexOf(node.parent.type) > -1;
}
module.exports = {
rules: {
snakecase: {
meta: {
fixable: true,
},
create(context) {
return {
Identifier(node) {
var name = node.name;
var split = name.split(/(?=[A-Z])/);
if (split.length > 1) {
if (isClassUsage(node)) {
return true;
}
// this has some uppercase letters
context.report({
message: 'Identifiers must be snake case: {{ identifier }}',
node: node,
data: {
identifier: node.name,
},
// fix(fixer) {
// return fixer.replaceText(node, split.map(function(piece){ return piece.replace('_', '').toLowerCase(); }).join('_'));
// }
})
}
}
}
}
}
}
}