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