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.
- package/CHANGELOG.md +1177 -1142
- package/LICENSE +21 -21
- package/README.md +245 -245
- package/bin/isml-linter.js +32 -32
- package/ismllinter.config.js +33 -33
- package/package.json +53 -53
- package/scaffold_files/ismllinter.config.js +47 -47
- package/src/Builder.js +15 -15
- package/src/Constants.js +139 -139
- package/src/IsmlLinter.js +255 -255
- package/src/enums/ParseStatus.js +5 -5
- package/src/enums/SfccTagContainer.js +287 -287
- package/src/isml_tree/ContainerNode.js +38 -38
- package/src/isml_tree/IsmlNode.js +692 -658
- package/src/isml_tree/MaskUtils.js +421 -419
- package/src/isml_tree/ParseUtils.js +515 -434
- package/src/isml_tree/TreeBuilder.js +273 -271
- package/src/publicApi.js +24 -24
- package/src/rules/line_by_line/enforce-isprint.js +53 -53
- package/src/rules/line_by_line/enforce-require.js +35 -35
- package/src/rules/line_by_line/lowercase-filename.js +29 -29
- package/src/rules/line_by_line/max-lines.js +37 -37
- package/src/rules/line_by_line/no-br.js +36 -36
- package/src/rules/line_by_line/no-git-conflict.js +43 -43
- package/src/rules/line_by_line/no-import-package.js +34 -34
- package/src/rules/line_by_line/no-inline-style.js +34 -34
- package/src/rules/line_by_line/no-isscript.js +34 -34
- package/src/rules/line_by_line/no-space-only-lines.js +47 -47
- package/src/rules/line_by_line/no-tabs.js +38 -38
- package/src/rules/line_by_line/no-trailing-spaces.js +52 -52
- package/src/rules/prototypes/RulePrototype.js +79 -79
- package/src/rules/prototypes/SingleLineRulePrototype.js +47 -47
- package/src/rules/prototypes/TreeRulePrototype.js +84 -84
- package/src/rules/tree/align-isset.js +87 -87
- package/src/rules/tree/contextual-attrs.js +105 -105
- package/src/rules/tree/custom-tags.js +54 -54
- package/src/rules/tree/disallow-tags.js +39 -39
- package/src/rules/tree/empty-eof.js +66 -66
- package/src/rules/tree/enforce-security.js +85 -85
- package/src/rules/tree/eslint-to-isscript.js +179 -179
- package/src/rules/tree/indent.js +856 -853
- package/src/rules/tree/leading-iscache.js +39 -43
- package/src/rules/tree/leading-iscontent.js +35 -39
- package/src/rules/tree/max-depth.js +54 -54
- package/src/rules/tree/no-deprecated-attrs.js +67 -67
- package/src/rules/tree/no-embedded-isml.js +17 -17
- package/src/rules/tree/no-hardcode.js +51 -51
- package/src/rules/tree/no-iselse-slash.js +35 -35
- package/src/rules/tree/no-redundant-context.js +134 -134
- package/src/rules/tree/no-require-in-loop.js +63 -63
- package/src/rules/tree/one-element-per-line.js +82 -76
- package/src/util/CommandLineUtils.js +19 -19
- package/src/util/ConfigUtils.js +219 -219
- package/src/util/ConsoleUtils.js +327 -327
- package/src/util/CustomTagContainer.js +45 -45
- package/src/util/ExceptionUtils.js +149 -136
- package/src/util/FileUtils.js +79 -79
- package/src/util/GeneralUtils.js +60 -60
- package/src/util/NativeExtensionUtils.js +6 -6
- package/src/util/RuleUtils.js +295 -295
- package/src/util/TempRuleUtils.js +232 -232
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
-
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
-
const ParseUtils = require('../../isml_tree/ParseUtils');
|
|
4
|
-
|
|
5
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
-
const disallowedOccurrenceContainer = [
|
|
7
|
-
|
|
8
|
-
// dw.web.Resource;
|
|
9
|
-
{
|
|
10
|
-
key : 'dw.web.Resource',
|
|
11
|
-
wrong : 'dw.web.',
|
|
12
|
-
correct : 'Resource'
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
key : 'require(\'dw/web/Resource\')',
|
|
16
|
-
wrong : 'require(\'dw/web/Resource\')',
|
|
17
|
-
correct : 'Resource'
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
key : 'require("dw/web/Resource")',
|
|
21
|
-
wrong : 'require("dw/web/Resource")',
|
|
22
|
-
correct : 'Resource'
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// dw.web.URLUtils;
|
|
27
|
-
{
|
|
28
|
-
key : 'dw.web.URLUtils',
|
|
29
|
-
wrong : 'dw.web.',
|
|
30
|
-
correct : 'URLUtils'
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
key : 'require(\'dw/web/URLUtils\')',
|
|
34
|
-
wrong : 'require(\'dw/web/URLUtils\')',
|
|
35
|
-
correct : 'URLUtils'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
key : 'require("dw/web/URLUtils")',
|
|
39
|
-
wrong : 'require("dw/web/URLUtils")',
|
|
40
|
-
correct : 'URLUtils'
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// dw.util.StringUtils;
|
|
45
|
-
{
|
|
46
|
-
key : 'dw.util.StringUtils',
|
|
47
|
-
wrong : 'dw.util.',
|
|
48
|
-
correct : 'StringUtils'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
key : 'require(\'dw/util/StringUtils\')',
|
|
52
|
-
wrong : 'require(\'dw/util/StringUtils\')',
|
|
53
|
-
correct : 'StringUtils'
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
key : 'require("dw/util/StringUtils")',
|
|
57
|
-
wrong : 'require("dw/util/StringUtils")',
|
|
58
|
-
correct : 'StringUtils'
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const Rule = Object.create(TreeRulePrototype);
|
|
63
|
-
|
|
64
|
-
Rule.init(ruleId);
|
|
65
|
-
|
|
66
|
-
Rule.isBroken = function (node) {
|
|
67
|
-
for (let i = 0; i < disallowedOccurrenceContainer.length; i++) {
|
|
68
|
-
const disallowedOccurrence = disallowedOccurrenceContainer[i];
|
|
69
|
-
|
|
70
|
-
if (node.head.indexOf(disallowedOccurrence.key) >= 0) {
|
|
71
|
-
return disallowedOccurrence;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return null;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
Rule.check = function(node, data) {
|
|
79
|
-
|
|
80
|
-
const config = ConfigUtils.load();
|
|
81
|
-
const occurrenceList = this.checkChildren(node, data);
|
|
82
|
-
const disallowedOccurrence = this.isBroken(node);
|
|
83
|
-
|
|
84
|
-
if (disallowedOccurrence) {
|
|
85
|
-
const trimmedHead = node.head.trim();
|
|
86
|
-
const startPos = trimmedHead.indexOf(disallowedOccurrence.key);
|
|
87
|
-
const beforeStartPos = trimmedHead.substring(0, startPos);
|
|
88
|
-
const lineOffset = ParseUtils.getLineBreakQty(beforeStartPos);
|
|
89
|
-
let globalPos = node.globalPos + startPos;
|
|
90
|
-
const message = getMessage(disallowedOccurrence);
|
|
91
|
-
|
|
92
|
-
if (data.isCrlfLineBreak) {
|
|
93
|
-
globalPos += lineOffset;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const error = this.getError(
|
|
97
|
-
node.head.trim(),
|
|
98
|
-
node.lineNumber,
|
|
99
|
-
node.columnNumber + node.head.trim().indexOf(disallowedOccurrence.key) - 1,
|
|
100
|
-
globalPos,
|
|
101
|
-
disallowedOccurrence.wrong.length,
|
|
102
|
-
message
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
occurrenceList.push(error);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return this.return(node, occurrenceList, config);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
Rule.getFixedContent = function(node) {
|
|
112
|
-
|
|
113
|
-
for (let i = 0; i < disallowedOccurrenceContainer.length; i++) {
|
|
114
|
-
const disallowedOccurrence = disallowedOccurrenceContainer[i];
|
|
115
|
-
|
|
116
|
-
if (node.head.indexOf(disallowedOccurrence.key) >= 0) {
|
|
117
|
-
node.head = node.head
|
|
118
|
-
.split(disallowedOccurrence.key)
|
|
119
|
-
.join(disallowedOccurrence.correct);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
124
|
-
this.getFixedContent(node.children[i]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return node.toString();
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const getMessage = disallowedOccurrence => {
|
|
131
|
-
return `"${disallowedOccurrence.wrong}" is not necessary since "${disallowedOccurrence.correct}" is available globally`;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
module.exports = Rule;
|
|
1
|
+
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
+
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
+
const ParseUtils = require('../../isml_tree/ParseUtils');
|
|
4
|
+
|
|
5
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
+
const disallowedOccurrenceContainer = [
|
|
7
|
+
|
|
8
|
+
// dw.web.Resource;
|
|
9
|
+
{
|
|
10
|
+
key : 'dw.web.Resource',
|
|
11
|
+
wrong : 'dw.web.',
|
|
12
|
+
correct : 'Resource'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
key : 'require(\'dw/web/Resource\')',
|
|
16
|
+
wrong : 'require(\'dw/web/Resource\')',
|
|
17
|
+
correct : 'Resource'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key : 'require("dw/web/Resource")',
|
|
21
|
+
wrong : 'require("dw/web/Resource")',
|
|
22
|
+
correct : 'Resource'
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// dw.web.URLUtils;
|
|
27
|
+
{
|
|
28
|
+
key : 'dw.web.URLUtils',
|
|
29
|
+
wrong : 'dw.web.',
|
|
30
|
+
correct : 'URLUtils'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key : 'require(\'dw/web/URLUtils\')',
|
|
34
|
+
wrong : 'require(\'dw/web/URLUtils\')',
|
|
35
|
+
correct : 'URLUtils'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key : 'require("dw/web/URLUtils")',
|
|
39
|
+
wrong : 'require("dw/web/URLUtils")',
|
|
40
|
+
correct : 'URLUtils'
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// dw.util.StringUtils;
|
|
45
|
+
{
|
|
46
|
+
key : 'dw.util.StringUtils',
|
|
47
|
+
wrong : 'dw.util.',
|
|
48
|
+
correct : 'StringUtils'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key : 'require(\'dw/util/StringUtils\')',
|
|
52
|
+
wrong : 'require(\'dw/util/StringUtils\')',
|
|
53
|
+
correct : 'StringUtils'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key : 'require("dw/util/StringUtils")',
|
|
57
|
+
wrong : 'require("dw/util/StringUtils")',
|
|
58
|
+
correct : 'StringUtils'
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const Rule = Object.create(TreeRulePrototype);
|
|
63
|
+
|
|
64
|
+
Rule.init(ruleId);
|
|
65
|
+
|
|
66
|
+
Rule.isBroken = function (node) {
|
|
67
|
+
for (let i = 0; i < disallowedOccurrenceContainer.length; i++) {
|
|
68
|
+
const disallowedOccurrence = disallowedOccurrenceContainer[i];
|
|
69
|
+
|
|
70
|
+
if (node.head.indexOf(disallowedOccurrence.key) >= 0) {
|
|
71
|
+
return disallowedOccurrence;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
Rule.check = function(node, data) {
|
|
79
|
+
|
|
80
|
+
const config = ConfigUtils.load();
|
|
81
|
+
const occurrenceList = this.checkChildren(node, data);
|
|
82
|
+
const disallowedOccurrence = this.isBroken(node);
|
|
83
|
+
|
|
84
|
+
if (disallowedOccurrence) {
|
|
85
|
+
const trimmedHead = node.head.trim();
|
|
86
|
+
const startPos = trimmedHead.indexOf(disallowedOccurrence.key);
|
|
87
|
+
const beforeStartPos = trimmedHead.substring(0, startPos);
|
|
88
|
+
const lineOffset = ParseUtils.getLineBreakQty(beforeStartPos);
|
|
89
|
+
let globalPos = node.globalPos + startPos;
|
|
90
|
+
const message = getMessage(disallowedOccurrence);
|
|
91
|
+
|
|
92
|
+
if (data.isCrlfLineBreak) {
|
|
93
|
+
globalPos += lineOffset;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const error = this.getError(
|
|
97
|
+
node.head.trim(),
|
|
98
|
+
node.lineNumber,
|
|
99
|
+
node.columnNumber + node.head.trim().indexOf(disallowedOccurrence.key) - 1,
|
|
100
|
+
globalPos,
|
|
101
|
+
disallowedOccurrence.wrong.length,
|
|
102
|
+
message
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
occurrenceList.push(error);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return this.return(node, occurrenceList, config);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
Rule.getFixedContent = function(node) {
|
|
112
|
+
|
|
113
|
+
for (let i = 0; i < disallowedOccurrenceContainer.length; i++) {
|
|
114
|
+
const disallowedOccurrence = disallowedOccurrenceContainer[i];
|
|
115
|
+
|
|
116
|
+
if (node.head.indexOf(disallowedOccurrence.key) >= 0) {
|
|
117
|
+
node.head = node.head
|
|
118
|
+
.split(disallowedOccurrence.key)
|
|
119
|
+
.join(disallowedOccurrence.correct);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
124
|
+
this.getFixedContent(node.children[i]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return node.toString();
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const getMessage = disallowedOccurrence => {
|
|
131
|
+
return `"${disallowedOccurrence.wrong}" is not necessary since "${disallowedOccurrence.correct}" is available globally`;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
module.exports = Rule;
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
-
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
-
const ParseUtils = require('../../isml_tree/ParseUtils');
|
|
4
|
-
|
|
5
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
-
const description = '"require()" call is not allowed within a loop';
|
|
7
|
-
|
|
8
|
-
const Rule = Object.create(TreeRulePrototype);
|
|
9
|
-
|
|
10
|
-
Rule.init(ruleId, description);
|
|
11
|
-
|
|
12
|
-
Rule.isBroken = function(node) {
|
|
13
|
-
|
|
14
|
-
if (node.head.indexOf('require(') === -1) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let iterator = node;
|
|
19
|
-
|
|
20
|
-
while (iterator.parent) {
|
|
21
|
-
iterator = iterator.parent;
|
|
22
|
-
|
|
23
|
-
if (iterator.isOfType('isloop')) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
Rule.check = function(node, data) {
|
|
32
|
-
|
|
33
|
-
const config = ConfigUtils.load();
|
|
34
|
-
const occurrenceList = this.checkChildren(node, data);
|
|
35
|
-
|
|
36
|
-
if (this.isBroken(node)) {
|
|
37
|
-
const trimmedHead = node.head.trim();
|
|
38
|
-
const startPos = trimmedHead.indexOf('require(');
|
|
39
|
-
const beforeStartPos = trimmedHead.substring(0, startPos);
|
|
40
|
-
const lineOffset = ParseUtils.getLineBreakQty(beforeStartPos);
|
|
41
|
-
const afterStartPos = trimmedHead.substring(startPos);
|
|
42
|
-
const length = afterStartPos.indexOf(')') + 1;
|
|
43
|
-
let globalPos = node.globalPos + startPos;
|
|
44
|
-
|
|
45
|
-
if (data.isCrlfLineBreak) {
|
|
46
|
-
globalPos += lineOffset;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const error = this.getError(
|
|
50
|
-
node.head.trim(),
|
|
51
|
-
node.lineNumber + lineOffset,
|
|
52
|
-
node.columnNumber + node.head.trim().indexOf('require('),
|
|
53
|
-
globalPos,
|
|
54
|
-
length
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
occurrenceList.push(error);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return this.return(node, occurrenceList, config);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
module.exports = Rule;
|
|
1
|
+
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
+
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
+
const ParseUtils = require('../../isml_tree/ParseUtils');
|
|
4
|
+
|
|
5
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
+
const description = '"require()" call is not allowed within a loop';
|
|
7
|
+
|
|
8
|
+
const Rule = Object.create(TreeRulePrototype);
|
|
9
|
+
|
|
10
|
+
Rule.init(ruleId, description);
|
|
11
|
+
|
|
12
|
+
Rule.isBroken = function(node) {
|
|
13
|
+
|
|
14
|
+
if (node.head.indexOf('require(') === -1) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let iterator = node;
|
|
19
|
+
|
|
20
|
+
while (iterator.parent) {
|
|
21
|
+
iterator = iterator.parent;
|
|
22
|
+
|
|
23
|
+
if (iterator.isOfType('isloop')) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
Rule.check = function(node, data) {
|
|
32
|
+
|
|
33
|
+
const config = ConfigUtils.load();
|
|
34
|
+
const occurrenceList = this.checkChildren(node, data);
|
|
35
|
+
|
|
36
|
+
if (this.isBroken(node)) {
|
|
37
|
+
const trimmedHead = node.head.trim();
|
|
38
|
+
const startPos = trimmedHead.indexOf('require(');
|
|
39
|
+
const beforeStartPos = trimmedHead.substring(0, startPos);
|
|
40
|
+
const lineOffset = ParseUtils.getLineBreakQty(beforeStartPos);
|
|
41
|
+
const afterStartPos = trimmedHead.substring(startPos);
|
|
42
|
+
const length = afterStartPos.indexOf(')') + 1;
|
|
43
|
+
let globalPos = node.globalPos + startPos;
|
|
44
|
+
|
|
45
|
+
if (data.isCrlfLineBreak) {
|
|
46
|
+
globalPos += lineOffset;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const error = this.getError(
|
|
50
|
+
node.head.trim(),
|
|
51
|
+
node.lineNumber + lineOffset,
|
|
52
|
+
node.columnNumber + node.head.trim().indexOf('require('),
|
|
53
|
+
globalPos,
|
|
54
|
+
length
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
occurrenceList.push(error);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this.return(node, occurrenceList, config);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = Rule;
|
|
@@ -1,76 +1,82 @@
|
|
|
1
|
-
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
Rule.
|
|
12
|
-
|
|
13
|
-
Rule.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
+
const IndentRule = require('../tree/indent');
|
|
3
|
+
const ConfigUtils = require('../../util/ConfigUtils');
|
|
4
|
+
const Constants = require('../../Constants');
|
|
5
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
6
|
+
const TreeBuilder = require('../../isml_tree/TreeBuilder');
|
|
7
|
+
|
|
8
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
9
|
+
const description = 'Only one element per line is allowed';
|
|
10
|
+
|
|
11
|
+
const Rule = Object.create(TreeRulePrototype);
|
|
12
|
+
|
|
13
|
+
Rule.init(ruleId, description);
|
|
14
|
+
|
|
15
|
+
Rule.isBroken = function(node) {
|
|
16
|
+
|
|
17
|
+
const config = ConfigUtils.load();
|
|
18
|
+
const ruleConfig = config.rules[ruleId];
|
|
19
|
+
|
|
20
|
+
if (ruleConfig && ruleConfig.except) {
|
|
21
|
+
|
|
22
|
+
if (node.parent && node.parent.isOfType('iscomment') && ruleConfig.except.indexOf('iscomment') >= 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!node.isIsmlTag() && !node.isHtmlTag() && ruleConfig.except.indexOf('non-tag') >= 0) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return !node.isRoot() &&
|
|
32
|
+
!node.parent.isContainer() &&
|
|
33
|
+
node.lineNumber === node.parent.endLineNumber;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Rule.getFixedContent = rootNode => {
|
|
37
|
+
addLineBreaks(rootNode);
|
|
38
|
+
|
|
39
|
+
// Rebuilding the tree automatically updates all node data, such as column number,
|
|
40
|
+
// line number, global position, etc;
|
|
41
|
+
const stringifiedTree = rootNode.toString();
|
|
42
|
+
const newRootNode = TreeBuilder.build(null, stringifiedTree).rootNode;
|
|
43
|
+
const partialFixContent = IndentRule.getFixedContent(newRootNode);
|
|
44
|
+
|
|
45
|
+
return GeneralUtils.applyActiveLineBreaks(partialFixContent);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const addLineBreaks = node => {
|
|
49
|
+
const config = ConfigUtils.load();
|
|
50
|
+
const ruleConfig = config.rules[ruleId];
|
|
51
|
+
const shouldIgnoreNonTags = ruleConfig && ruleConfig.except && ruleConfig.except.indexOf('non-tag') >= 0;
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
54
|
+
const child = node.children[i];
|
|
55
|
+
|
|
56
|
+
if (shouldAddLeadingLineBreakToChildHead(node, child, shouldIgnoreNonTags)) {
|
|
57
|
+
child.head = Constants.EOL + child.head;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (shouldAddLeadingLineBreakToParentTail(node, child, shouldIgnoreNonTags)) {
|
|
61
|
+
node.tail = Constants.EOL + node.tail;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
addLineBreaks(child);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const shouldAddLeadingLineBreakToChildHead = (node, child, shouldIgnoreNonTags) => {
|
|
69
|
+
return (child.isFirstChild() && child.isInSameLineAsParentEnd() || child.isTag() && child.isInSameLineAsPreviousSibling())
|
|
70
|
+
&& !node.isIsmlComment()
|
|
71
|
+
&& (child.isTag() || !child.isTag() && !shouldIgnoreNonTags);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const shouldAddLeadingLineBreakToParentTail = (node, child, shouldIgnoreNonTags) => {
|
|
75
|
+
return child.isLastChild()
|
|
76
|
+
&& child.endLineNumber === node.tailLineNumber
|
|
77
|
+
&& !node.isIsmlComment()
|
|
78
|
+
&& !node.tail.startsWith(Constants.EOL)
|
|
79
|
+
&& (child.isTag() || !child.isTag() && !shouldIgnoreNonTags);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports = Rule;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const parseCommand = () => {
|
|
2
|
-
const commandObject = {
|
|
3
|
-
options : [],
|
|
4
|
-
files : []
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
for (let i = 2; i < process.argv.length; i++) {
|
|
8
|
-
const arg = process.argv[i];
|
|
9
|
-
if (arg.startsWith('--')) {
|
|
10
|
-
commandObject.options.push(arg);
|
|
11
|
-
} else {
|
|
12
|
-
commandObject.files.push(arg);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return commandObject;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports.parseCommand = parseCommand;
|
|
1
|
+
const parseCommand = () => {
|
|
2
|
+
const commandObject = {
|
|
3
|
+
options : [],
|
|
4
|
+
files : []
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
8
|
+
const arg = process.argv[i];
|
|
9
|
+
if (arg.startsWith('--')) {
|
|
10
|
+
commandObject.options.push(arg);
|
|
11
|
+
} else {
|
|
12
|
+
commandObject.files.push(arg);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return commandObject;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports.parseCommand = parseCommand;
|