1 | var isConstant = require('./src/is-constant');
|
2 |
|
3 | module.exports = function camelCase(context) {
|
4 | 'use strict';
|
5 |
|
6 | function isFrontOrBackUnderscore(str) {
|
7 | var k = str.indexOf('_');
|
8 | if (k === 0 || k === str.length - 1) {
|
9 | return true;
|
10 | }
|
11 | k = str.lastIndexOf('_');
|
12 | if (k === str.length - 1) {
|
13 | return true;
|
14 | }
|
15 |
|
16 | return false;
|
17 | }
|
18 |
|
19 | return {
|
20 | Identifier: function (node) {
|
21 | var nameWithMaybeColon = context.getSource(node, 0, 1);
|
22 | if (nameWithMaybeColon[nameWithMaybeColon.length - 1] !== ':') {
|
23 | if (nameWithMaybeColon.indexOf('_') !== -1) {
|
24 |
|
25 |
|
26 | var justName = node.name.trim();
|
27 | if (isConstant(justName)) {
|
28 | return;
|
29 | }
|
30 |
|
31 |
|
32 | if (isFrontOrBackUnderscore(justName)) {
|
33 | return;
|
34 | }
|
35 |
|
36 | context.report(node, '`{{identifier}}` : _ in names only allowed in properties', {
|
37 | identifier: node.name
|
38 | });
|
39 | }
|
40 | }
|
41 | }
|
42 | };
|
43 | };
|