1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict';
|
13 |
|
14 |
|
15 | var utils = require('./utils/utils');
|
16 |
|
17 |
|
18 | module.exports = {
|
19 | meta: {
|
20 | docs: {
|
21 | url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/constant-name.md'
|
22 | },
|
23 | schema: [{
|
24 | type: ['string', 'object']
|
25 | }, {
|
26 | type: 'object'
|
27 | }]
|
28 | },
|
29 | create: function(context) {
|
30 | return {
|
31 |
|
32 | CallExpression: function(node) {
|
33 | var prefix = context.options[0];
|
34 | var convertedPrefix;
|
35 | var isConstant;
|
36 |
|
37 | if (prefix === undefined) {
|
38 | return;
|
39 | }
|
40 |
|
41 | convertedPrefix = utils.convertPrefixToRegex(prefix);
|
42 | isConstant = utils.isAngularConstantDeclaration(node);
|
43 |
|
44 | if (isConstant) {
|
45 | var name = node.arguments[0].value;
|
46 |
|
47 | if (name !== undefined && name.indexOf('$') === 0) {
|
48 | context.report(node, 'The {{constant}} constant should not start with "$". This is reserved for AngularJS services', {
|
49 | constant: name
|
50 | });
|
51 | } else if (name !== undefined && !convertedPrefix.test(name)) {
|
52 | if (typeof prefix === 'string' && !utils.isStringRegexp(prefix)) {
|
53 | context.report(node, 'The {{constant}} constant should be prefixed by {{prefix}}', {
|
54 | constant: name,
|
55 | prefix: prefix
|
56 | });
|
57 | } else {
|
58 | context.report(node, 'The {{constant}} constant should follow this pattern: {{prefix}}', {
|
59 | constant: name,
|
60 | prefix: prefix.toString()
|
61 | });
|
62 | }
|
63 | }
|
64 | }
|
65 | }
|
66 | };
|
67 | }
|
68 | };
|