isml-linter 5.39.1 → 5.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +1177 -1142
  2. package/LICENSE +21 -21
  3. package/README.md +245 -245
  4. package/bin/isml-linter.js +32 -32
  5. package/ismllinter.config.js +33 -33
  6. package/package.json +53 -53
  7. package/scaffold_files/ismllinter.config.js +47 -47
  8. package/src/Builder.js +15 -15
  9. package/src/Constants.js +139 -139
  10. package/src/IsmlLinter.js +255 -255
  11. package/src/enums/ParseStatus.js +5 -5
  12. package/src/enums/SfccTagContainer.js +287 -287
  13. package/src/isml_tree/ContainerNode.js +38 -38
  14. package/src/isml_tree/IsmlNode.js +692 -658
  15. package/src/isml_tree/MaskUtils.js +421 -419
  16. package/src/isml_tree/ParseUtils.js +515 -434
  17. package/src/isml_tree/TreeBuilder.js +273 -271
  18. package/src/publicApi.js +24 -24
  19. package/src/rules/line_by_line/enforce-isprint.js +53 -53
  20. package/src/rules/line_by_line/enforce-require.js +35 -35
  21. package/src/rules/line_by_line/lowercase-filename.js +29 -29
  22. package/src/rules/line_by_line/max-lines.js +37 -37
  23. package/src/rules/line_by_line/no-br.js +36 -36
  24. package/src/rules/line_by_line/no-git-conflict.js +43 -43
  25. package/src/rules/line_by_line/no-import-package.js +34 -34
  26. package/src/rules/line_by_line/no-inline-style.js +34 -34
  27. package/src/rules/line_by_line/no-isscript.js +34 -34
  28. package/src/rules/line_by_line/no-space-only-lines.js +47 -47
  29. package/src/rules/line_by_line/no-tabs.js +38 -38
  30. package/src/rules/line_by_line/no-trailing-spaces.js +52 -52
  31. package/src/rules/prototypes/RulePrototype.js +79 -79
  32. package/src/rules/prototypes/SingleLineRulePrototype.js +47 -47
  33. package/src/rules/prototypes/TreeRulePrototype.js +84 -84
  34. package/src/rules/tree/align-isset.js +87 -87
  35. package/src/rules/tree/contextual-attrs.js +105 -105
  36. package/src/rules/tree/custom-tags.js +54 -54
  37. package/src/rules/tree/disallow-tags.js +39 -39
  38. package/src/rules/tree/empty-eof.js +66 -66
  39. package/src/rules/tree/enforce-security.js +85 -85
  40. package/src/rules/tree/eslint-to-isscript.js +179 -179
  41. package/src/rules/tree/indent.js +856 -853
  42. package/src/rules/tree/leading-iscache.js +39 -43
  43. package/src/rules/tree/leading-iscontent.js +35 -39
  44. package/src/rules/tree/max-depth.js +54 -54
  45. package/src/rules/tree/no-deprecated-attrs.js +67 -67
  46. package/src/rules/tree/no-embedded-isml.js +17 -17
  47. package/src/rules/tree/no-hardcode.js +51 -51
  48. package/src/rules/tree/no-iselse-slash.js +35 -35
  49. package/src/rules/tree/no-redundant-context.js +134 -134
  50. package/src/rules/tree/no-require-in-loop.js +63 -63
  51. package/src/rules/tree/one-element-per-line.js +82 -76
  52. package/src/util/CommandLineUtils.js +19 -19
  53. package/src/util/ConfigUtils.js +219 -219
  54. package/src/util/ConsoleUtils.js +327 -327
  55. package/src/util/CustomTagContainer.js +45 -45
  56. package/src/util/ExceptionUtils.js +149 -136
  57. package/src/util/FileUtils.js +79 -79
  58. package/src/util/GeneralUtils.js +60 -60
  59. package/src/util/NativeExtensionUtils.js +6 -6
  60. package/src/util/RuleUtils.js +295 -295
  61. package/src/util/TempRuleUtils.js +232 -232
@@ -1,84 +1,84 @@
1
- const RulePrototype = require('./RulePrototype');
2
- const ConfigUtils = require('../../util/ConfigUtils');
3
- const ParseUtils = require('../../isml_tree/ParseUtils');
4
-
5
- const TreeRulePrototype = Object.create(RulePrototype);
6
-
7
- TreeRulePrototype.check = function(node, data) {
8
-
9
- const config = ConfigUtils.load();
10
- const occurrenceList = this.checkChildren(node, data);
11
-
12
- if (this.isBroken(node)) {
13
- let length = node.head.trim().length;
14
-
15
- if (data.isCrlfLineBreak) {
16
- length += ParseUtils.getLineBreakQty(node.head.trim());
17
- }
18
-
19
- const error = this.getError(
20
- node.head.trim(),
21
- node.lineNumber,
22
- node.columnNumber,
23
- node.globalPos,
24
- length
25
- );
26
-
27
- occurrenceList.push(error);
28
- }
29
-
30
- return this.return(node, occurrenceList, config);
31
- };
32
-
33
- TreeRulePrototype.shouldGetFixedContent = function(node, occurrenceList, config) {
34
- return occurrenceList.length &&
35
- config.autoFix &&
36
- this.getFixedContent &&
37
- node.isRoot();
38
- };
39
-
40
- TreeRulePrototype.return = function(node, occurrenceList, config) {
41
- if (this.shouldGetFixedContent(node, occurrenceList, config)) {
42
- return {
43
- occurrenceList,
44
- fixedContent : this.getFixedContent(node)
45
- };
46
- } else if (node.isRoot()) {
47
- occurrenceList.sort((occurrence1, occurrence2) => {
48
- if ( occurrence1.lineNumber < occurrence2.lineNumber ) {
49
- return -1;
50
- }
51
-
52
- if ( occurrence1.lineNumber > occurrence2.lineNumber ) {
53
- return 1;
54
- }
55
-
56
- return 0;
57
- });
58
-
59
- return {
60
- occurrenceList
61
- } ;
62
-
63
- } else {
64
- return occurrenceList;
65
- }
66
- };
67
-
68
- TreeRulePrototype.fix = function(stream = '') {
69
-
70
- if (!this.isRoot() && !this.isContainer()) {
71
- stream += this.head;
72
- }
73
-
74
- for (let i = 0; i < this.children.length; i++) {
75
- const node = this.children[i];
76
- stream = node.isBroken() ?
77
- node.toString(stream) :
78
- this.getFixedContent(node, stream);
79
- }
80
-
81
- return stream;
82
- };
83
-
84
- module.exports = TreeRulePrototype;
1
+ const RulePrototype = require('./RulePrototype');
2
+ const ConfigUtils = require('../../util/ConfigUtils');
3
+ const ParseUtils = require('../../isml_tree/ParseUtils');
4
+
5
+ const TreeRulePrototype = Object.create(RulePrototype);
6
+
7
+ TreeRulePrototype.check = function(node, data) {
8
+
9
+ const config = ConfigUtils.load();
10
+ const occurrenceList = this.checkChildren(node, data);
11
+
12
+ if (this.isBroken(node)) {
13
+ let length = node.head.trim().length;
14
+
15
+ if (data.isCrlfLineBreak) {
16
+ length += ParseUtils.getLineBreakQty(node.head.trim());
17
+ }
18
+
19
+ const error = this.getError(
20
+ node.head.trim(),
21
+ node.lineNumber,
22
+ node.columnNumber,
23
+ node.globalPos,
24
+ length
25
+ );
26
+
27
+ occurrenceList.push(error);
28
+ }
29
+
30
+ return this.return(node, occurrenceList, config);
31
+ };
32
+
33
+ TreeRulePrototype.shouldGetFixedContent = function(node, occurrenceList, config) {
34
+ return occurrenceList.length &&
35
+ config.autoFix &&
36
+ this.getFixedContent &&
37
+ node.isRoot();
38
+ };
39
+
40
+ TreeRulePrototype.return = function(node, occurrenceList, config) {
41
+ if (this.shouldGetFixedContent(node, occurrenceList, config)) {
42
+ return {
43
+ occurrenceList,
44
+ fixedContent : this.getFixedContent(node)
45
+ };
46
+ } else if (node.isRoot()) {
47
+ occurrenceList.sort((occurrence1, occurrence2) => {
48
+ if ( occurrence1.lineNumber < occurrence2.lineNumber ) {
49
+ return -1;
50
+ }
51
+
52
+ if ( occurrence1.lineNumber > occurrence2.lineNumber ) {
53
+ return 1;
54
+ }
55
+
56
+ return 0;
57
+ });
58
+
59
+ return {
60
+ occurrenceList
61
+ };
62
+
63
+ } else {
64
+ return occurrenceList;
65
+ }
66
+ };
67
+
68
+ TreeRulePrototype.fix = function(stream = '') {
69
+
70
+ if (!this.isRoot() && !this.isContainer()) {
71
+ stream += this.head;
72
+ }
73
+
74
+ for (let i = 0; i < this.children.length; i++) {
75
+ const node = this.children[i];
76
+ stream = node.isBroken() ?
77
+ node.toString(stream) :
78
+ this.getFixedContent(node, stream);
79
+ }
80
+
81
+ return stream;
82
+ };
83
+
84
+ module.exports = TreeRulePrototype;
@@ -1,87 +1,87 @@
1
- const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
2
-
3
- const ruleId = require('path').basename(__filename).slice(0, -3);
4
- const description = 'Tag attributes are not column-aligned';
5
-
6
- const Rule = Object.create(TreeRulePrototype);
7
-
8
- Rule.init(ruleId, description);
9
-
10
- Rule.check = function(node, data) {
11
-
12
- const occurrenceList = this.checkChildren(node, data);
13
- const issetChildren = getConsecutiveIssetTagChildren(node);
14
- const attrPosContainer = getCorrectAttributePositions(issetChildren);
15
- const alignmentoccurrenceList = this.checkAttributesAlignments(issetChildren, attrPosContainer);
16
-
17
- occurrenceList.push(...alignmentoccurrenceList);
18
-
19
- return node.isRoot() ?
20
- { occurrenceList } :
21
- occurrenceList;
22
- };
23
-
24
- const getConsecutiveIssetTagChildren = node => {
25
- const issetChildren = new Set();
26
-
27
- for (let i = 1; i < node.children.length; i++) {
28
- const prevChild = node.children[i - 1];
29
- const child = node.children[i];
30
-
31
- if (prevChild.isOfType('isset') && child.isOfType('isset')) {
32
- issetChildren.add(prevChild);
33
- issetChildren.add(child);
34
- } else if (!child.isOfType('isset') && issetChildren.length > 0) {
35
- break;
36
- }
37
- }
38
-
39
- return issetChildren;
40
- };
41
-
42
- const getCorrectAttributePositions = issetChildren => {
43
-
44
- const attrPosContainer = {};
45
- for (const issetNode of issetChildren) {
46
-
47
- const attrArray = issetNode.getAttributeList();
48
- for (let i = 0; i < attrArray.length; i++) {
49
-
50
- const attr = attrArray[i];
51
- if (!attrPosContainer[attr.name] || attr.localPos > attrPosContainer[attr.name]) {
52
- attrPosContainer[attr.name] = attr.localPos;
53
- }
54
- }
55
- }
56
-
57
- return attrPosContainer;
58
- };
59
-
60
- Rule.checkAttributesAlignments = function(issetChildren, attrPosContainer) {
61
- const occurrenceList = [];
62
-
63
- for (const issetNode of issetChildren) {
64
- const attrArray = issetNode.getAttributeList();
65
-
66
- for (let i = 0; i < attrArray.length; i++) {
67
- const attr = attrArray[i];
68
- if (attr.localPos !== attrPosContainer[attr.name]) {
69
- const error = this.getError(
70
- issetNode.head.trim(),
71
- issetNode.lineNumber,
72
- issetNode.columnNumber,
73
- issetNode.globalPos,
74
- issetNode.head.trim().length,
75
- description
76
- );
77
-
78
- occurrenceList.push(error);
79
- break;
80
- }
81
- }
82
- }
83
-
84
- return occurrenceList;
85
- };
86
-
87
- module.exports = Rule;
1
+ const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
2
+
3
+ const ruleId = require('path').basename(__filename).slice(0, -3);
4
+ const description = 'Tag attributes are not column-aligned';
5
+
6
+ const Rule = Object.create(TreeRulePrototype);
7
+
8
+ Rule.init(ruleId, description);
9
+
10
+ Rule.check = function(node, data) {
11
+
12
+ const occurrenceList = this.checkChildren(node, data);
13
+ const issetChildren = getConsecutiveIssetTagChildren(node);
14
+ const attrPosContainer = getCorrectAttributePositions(issetChildren);
15
+ const alignmentoccurrenceList = this.checkAttributesAlignments(issetChildren, attrPosContainer);
16
+
17
+ occurrenceList.push(...alignmentoccurrenceList);
18
+
19
+ return node.isRoot() ?
20
+ { occurrenceList } :
21
+ occurrenceList;
22
+ };
23
+
24
+ const getConsecutiveIssetTagChildren = node => {
25
+ const issetChildren = new Set();
26
+
27
+ for (let i = 1; i < node.children.length; i++) {
28
+ const prevChild = node.children[i - 1];
29
+ const child = node.children[i];
30
+
31
+ if (prevChild.isOfType('isset') && child.isOfType('isset')) {
32
+ issetChildren.add(prevChild);
33
+ issetChildren.add(child);
34
+ } else if (!child.isOfType('isset') && issetChildren.length > 0) {
35
+ break;
36
+ }
37
+ }
38
+
39
+ return issetChildren;
40
+ };
41
+
42
+ const getCorrectAttributePositions = issetChildren => {
43
+
44
+ const attrPosContainer = {};
45
+ for (const issetNode of issetChildren) {
46
+
47
+ const attrArray = issetNode.getAttributeList();
48
+ for (let i = 0; i < attrArray.length; i++) {
49
+
50
+ const attr = attrArray[i];
51
+ if (!attrPosContainer[attr.name] || attr.localPos > attrPosContainer[attr.name]) {
52
+ attrPosContainer[attr.name] = attr.localPos;
53
+ }
54
+ }
55
+ }
56
+
57
+ return attrPosContainer;
58
+ };
59
+
60
+ Rule.checkAttributesAlignments = function(issetChildren, attrPosContainer) {
61
+ const occurrenceList = [];
62
+
63
+ for (const issetNode of issetChildren) {
64
+ const attrArray = issetNode.getAttributeList();
65
+
66
+ for (let i = 0; i < attrArray.length; i++) {
67
+ const attr = attrArray[i];
68
+ if (attr.localPos !== attrPosContainer[attr.name]) {
69
+ const error = this.getError(
70
+ issetNode.head.trim(),
71
+ issetNode.lineNumber,
72
+ issetNode.columnNumber,
73
+ issetNode.globalPos,
74
+ issetNode.head.trim().length,
75
+ description
76
+ );
77
+
78
+ occurrenceList.push(error);
79
+ break;
80
+ }
81
+ }
82
+ }
83
+
84
+ return occurrenceList;
85
+ };
86
+
87
+ module.exports = Rule;
@@ -1,105 +1,105 @@
1
- const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
2
- const SfccTagContainer = require('../../enums/SfccTagContainer');
3
-
4
- const ruleId = require('path').basename(__filename).slice(0, -3);
5
- const description = 'Embedded ISML is not allowed';
6
-
7
- const Rule = Object.create(TreeRulePrototype);
8
-
9
- Rule.init(ruleId, description);
10
-
11
- Rule.isBroken = function(node) {
12
- if (!node.isIsmlTag() || node.isCustomIsmlTag()) {
13
- return false;
14
- }
15
-
16
- const attrList = node.getAttributeList();
17
- const nodeType = node.getType();
18
- const sfccTagObj = SfccTagContainer[nodeType];
19
- let result = null;
20
-
21
- attrList.some( nodeAttribute => {
22
- const sfccAttr = sfccTagObj.attributes[nodeAttribute.name];
23
- result = checkForExclusiveAttributes(sfccTagObj, nodeAttribute, attrList) ||
24
- checkForConditionalAttributes(sfccAttr, nodeAttribute, attrList);
25
-
26
- return !result;
27
- });
28
-
29
- if (sfccTagObj.requires) {
30
- const exclusiveAttributeList = sfccTagObj.requires.exclusive;
31
- if (attrList.length === 0 && exclusiveAttributeList.length > 1) {
32
- result = {};
33
- result.message = `The "${node.getType()}" tag needs to have either "${exclusiveAttributeList[0]}" or "${exclusiveAttributeList[1]}" attribute`;
34
- }
35
- }
36
-
37
- return result;
38
- };
39
-
40
- const checkForExclusiveAttributes = (sfccTagObj, nodeAttribute, attrList) => {
41
- let result = null;
42
- if (sfccTagObj && sfccTagObj.requires && sfccTagObj.requires.exclusive) {
43
- const exclusiveAttributeObj = sfccTagObj.requires.exclusive;
44
- const exclusiveAttributeOccurrenceList = [];
45
-
46
- for (let i = 0; i < attrList.length; i++) {
47
- const attr = attrList[i];
48
- if (exclusiveAttributeObj.indexOf(attr.name) >= 0) {
49
- exclusiveAttributeOccurrenceList.push(attr.name);
50
- }
51
- }
52
-
53
- if (exclusiveAttributeOccurrenceList.length > 1) {
54
- result = {};
55
- result.message = `The "${nodeAttribute.node.getType()}" tag cannot have "${exclusiveAttributeOccurrenceList[0]}" and "${exclusiveAttributeOccurrenceList[1]}" attributes simultaneously`;
56
- }
57
-
58
- }
59
-
60
- return result;
61
- };
62
-
63
- const checkForConditionalAttributes = (sfccAttr, nodeAttribute, attrList) => {
64
- const requiredAttributeObj = sfccAttr.requires;
65
- let result = null;
66
-
67
- if (requiredAttributeObj) {
68
- const requiredAttributeName = requiredAttributeObj.name;
69
- const requiredAttributeValues = requiredAttributeObj.ifValues;
70
- const isConditionFulfilled = requiredAttributeValues.indexOf(nodeAttribute.value) >= 0;
71
- const hasRequiredAttr = attrList.some( attr => attr.name === requiredAttributeName );
72
-
73
- if (isConditionFulfilled && !hasRequiredAttr) {
74
- result = nodeAttribute;
75
- result.message = `"${requiredAttributeObj.name}" attribute is expected when "${nodeAttribute.name}" attribute has value of "${nodeAttribute.value}"`;
76
- }
77
- }
78
-
79
- return result;
80
- };
81
-
82
- Rule.check = function(node, data) {
83
-
84
- const occurrenceList = this.checkChildren(node, data);
85
-
86
- const occurrence = this.isBroken(node);
87
- if (occurrence) {
88
- const error = this.getError(
89
- node.head.trim(),
90
- node.lineNumber,
91
- node.columnNumber,
92
- node.globalPos,
93
- node.head.trim().length,
94
- occurrence.message
95
- );
96
-
97
- occurrenceList.push(error);
98
- }
99
-
100
- return node.isRoot() ?
101
- { occurrenceList } :
102
- occurrenceList;
103
- };
104
-
105
- module.exports = Rule;
1
+ const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
2
+ const SfccTagContainer = require('../../enums/SfccTagContainer');
3
+
4
+ const ruleId = require('path').basename(__filename).slice(0, -3);
5
+ const description = 'Embedded ISML is not allowed';
6
+
7
+ const Rule = Object.create(TreeRulePrototype);
8
+
9
+ Rule.init(ruleId, description);
10
+
11
+ Rule.isBroken = function(node) {
12
+ if (!node.isIsmlTag() || node.isCustomIsmlTag()) {
13
+ return false;
14
+ }
15
+
16
+ const attrList = node.getAttributeList();
17
+ const nodeType = node.getType();
18
+ const sfccTagObj = SfccTagContainer[nodeType];
19
+ let result = null;
20
+
21
+ attrList.some( nodeAttribute => {
22
+ const sfccAttr = sfccTagObj.attributes[nodeAttribute.name];
23
+ result = checkForExclusiveAttributes(sfccTagObj, nodeAttribute, attrList) ||
24
+ checkForConditionalAttributes(sfccAttr, nodeAttribute, attrList);
25
+
26
+ return !result;
27
+ });
28
+
29
+ if (sfccTagObj.requires) {
30
+ const exclusiveAttributeList = sfccTagObj.requires.exclusive;
31
+ if (attrList.length === 0 && exclusiveAttributeList.length > 1) {
32
+ result = {};
33
+ result.message = `The "${node.getType()}" tag needs to have either "${exclusiveAttributeList[0]}" or "${exclusiveAttributeList[1]}" attribute`;
34
+ }
35
+ }
36
+
37
+ return result;
38
+ };
39
+
40
+ const checkForExclusiveAttributes = (sfccTagObj, nodeAttribute, attrList) => {
41
+ let result = null;
42
+ if (sfccTagObj && sfccTagObj.requires && sfccTagObj.requires.exclusive) {
43
+ const exclusiveAttributeObj = sfccTagObj.requires.exclusive;
44
+ const exclusiveAttributeOccurrenceList = [];
45
+
46
+ for (let i = 0; i < attrList.length; i++) {
47
+ const attr = attrList[i];
48
+ if (exclusiveAttributeObj.indexOf(attr.name) >= 0) {
49
+ exclusiveAttributeOccurrenceList.push(attr.name);
50
+ }
51
+ }
52
+
53
+ if (exclusiveAttributeOccurrenceList.length > 1) {
54
+ result = {};
55
+ result.message = `The "${nodeAttribute.node.getType()}" tag cannot have "${exclusiveAttributeOccurrenceList[0]}" and "${exclusiveAttributeOccurrenceList[1]}" attributes simultaneously`;
56
+ }
57
+
58
+ }
59
+
60
+ return result;
61
+ };
62
+
63
+ const checkForConditionalAttributes = (sfccAttr, nodeAttribute, attrList) => {
64
+ const requiredAttributeObj = sfccAttr.requires;
65
+ let result = null;
66
+
67
+ if (requiredAttributeObj) {
68
+ const requiredAttributeName = requiredAttributeObj.name;
69
+ const requiredAttributeValues = requiredAttributeObj.ifValues;
70
+ const isConditionFulfilled = requiredAttributeValues.indexOf(nodeAttribute.value) >= 0;
71
+ const hasRequiredAttr = attrList.some( attr => attr.name === requiredAttributeName );
72
+
73
+ if (isConditionFulfilled && !hasRequiredAttr) {
74
+ result = nodeAttribute;
75
+ result.message = `"${requiredAttributeObj.name}" attribute is expected when "${nodeAttribute.name}" attribute has value of "${nodeAttribute.value}"`;
76
+ }
77
+ }
78
+
79
+ return result;
80
+ };
81
+
82
+ Rule.check = function(node, data) {
83
+
84
+ const occurrenceList = this.checkChildren(node, data);
85
+
86
+ const occurrence = this.isBroken(node);
87
+ if (occurrence) {
88
+ const error = this.getError(
89
+ node.head.trim(),
90
+ node.lineNumber,
91
+ node.columnNumber,
92
+ node.globalPos,
93
+ node.head.trim().length,
94
+ occurrence.message
95
+ );
96
+
97
+ occurrenceList.push(error);
98
+ }
99
+
100
+ return node.isRoot() ?
101
+ { occurrenceList } :
102
+ occurrenceList;
103
+ };
104
+
105
+ module.exports = Rule;
@@ -1,54 +1,54 @@
1
- const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
2
- const CustomTagContainer = require('../../util/CustomTagContainer');
3
-
4
- const ruleId = require('path').basename(__filename).slice(0, -3);
5
- const description = 'Invalid custom tag';
6
-
7
- const Rule = Object.create(TreeRulePrototype);
8
-
9
- Rule.init(ruleId, description);
10
-
11
- Rule.addError = function(node, message) {
12
- return this.getError(
13
- node.head.trim(),
14
- node.lineNumber,
15
- node.columnNumber,
16
- node.globalPos,
17
- node.head.trim().length,
18
- message
19
- );
20
- };
21
-
22
- Rule.check = function(node, data) {
23
-
24
- const occurrenceList = this.checkChildren(node, data);
25
-
26
- if (data) {
27
- const isUsedButNotDeclared = !data.moduleDefinition && data.customModuleArray && data.customModuleArray.length > 0;
28
-
29
- if (node.head.indexOf('template="util/modules"') >= 0) {
30
- const isUnnecessaryDefinition = data.moduleDefinition && !data.customModuleArray;
31
-
32
- if (isUnnecessaryDefinition) {
33
- const error = this.addError(node, 'Unnecessary inclusion of the modules template');
34
- occurrenceList.push(error);
35
- }
36
- }
37
-
38
- if (isUsedButNotDeclared && node.isCustomIsmlTag()) {
39
- const error = this.addError(node,
40
- CustomTagContainer[node.getType()] ?
41
- `Custom tag "${node.getType()}" could not be identified. Maybe you forgot to include the modules template?` :
42
- `Unknown tag "${node.getType()}". Maybe you forgot to add it to util/modules template?`
43
- );
44
-
45
- occurrenceList.push(error);
46
- }
47
- }
48
-
49
- return node.isRoot() ?
50
- { occurrenceList } :
51
- occurrenceList;
52
- };
53
-
54
- module.exports = Rule;
1
+ const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
2
+ const CustomTagContainer = require('../../util/CustomTagContainer');
3
+
4
+ const ruleId = require('path').basename(__filename).slice(0, -3);
5
+ const description = 'Invalid custom tag';
6
+
7
+ const Rule = Object.create(TreeRulePrototype);
8
+
9
+ Rule.init(ruleId, description);
10
+
11
+ Rule.addError = function(node, message) {
12
+ return this.getError(
13
+ node.head.trim(),
14
+ node.lineNumber,
15
+ node.columnNumber,
16
+ node.globalPos,
17
+ node.head.trim().length,
18
+ message
19
+ );
20
+ };
21
+
22
+ Rule.check = function(node, data) {
23
+
24
+ const occurrenceList = this.checkChildren(node, data);
25
+
26
+ if (data) {
27
+ const isUsedButNotDeclared = !data.moduleDefinition && data.customModuleArray && data.customModuleArray.length > 0;
28
+
29
+ if (node.head.indexOf('template="util/modules"') >= 0) {
30
+ const isUnnecessaryDefinition = data.moduleDefinition && !data.customModuleArray;
31
+
32
+ if (isUnnecessaryDefinition) {
33
+ const error = this.addError(node, 'Unnecessary inclusion of the modules template');
34
+ occurrenceList.push(error);
35
+ }
36
+ }
37
+
38
+ if (isUsedButNotDeclared && node.isCustomIsmlTag()) {
39
+ const error = this.addError(node,
40
+ CustomTagContainer[node.getType()] ?
41
+ `Custom tag "${node.getType()}" could not be identified. Maybe you forgot to include the modules template?` :
42
+ `Unknown tag "${node.getType()}". Maybe you forgot to add it to util/modules template?`
43
+ );
44
+
45
+ occurrenceList.push(error);
46
+ }
47
+ }
48
+
49
+ return node.isRoot() ?
50
+ { occurrenceList } :
51
+ occurrenceList;
52
+ };
53
+
54
+ module.exports = Rule;