1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict';
|
13 |
|
14 | module.exports = {
|
15 | meta: {
|
16 | schema: [{
|
17 | allowSimple: {
|
18 | type: 'boolean'
|
19 | }
|
20 | }]
|
21 | },
|
22 | create: function(context) {
|
23 |
|
24 | var regularTagPattern = /<(.+?)>/g;
|
25 |
|
26 | var selfClosingTagPattern = /<(.+?)\/>/g;
|
27 |
|
28 | var allowSimple = (context.options[0] && context.options[0].allowSimple) !== false;
|
29 |
|
30 | function reportComplex(node) {
|
31 | context.report(node, 'Inline template is too complex. Use an external template instead');
|
32 | }
|
33 |
|
34 | return {
|
35 | Property: function(node) {
|
36 | if (node.key.name !== 'template' || node.value.type !== 'Literal') {
|
37 | return;
|
38 | }
|
39 | if (!allowSimple) {
|
40 | context.report(node, 'Inline templates are not allowed. Use an external template instead');
|
41 | }
|
42 | if ((node.value.value && node.value.value.match(regularTagPattern) || []).length > 2) {
|
43 | return reportComplex(node);
|
44 | }
|
45 | if ((node.value.value && node.value.value.match(selfClosingTagPattern) || []).length > 1) {
|
46 | return reportComplex(node);
|
47 | }
|
48 | if (node.value && node.value.raw.indexOf('\\') !== -1) {
|
49 | reportComplex(node);
|
50 | }
|
51 | }
|
52 | };
|
53 | }
|
54 | };
|