isml-linter 5.39.3 → 5.39.4
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 +1167 -1159
- 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 +684 -684
- package/src/isml_tree/MaskUtils.js +421 -421
- package/src/isml_tree/ParseUtils.js +514 -506
- package/src/isml_tree/TreeBuilder.js +273 -273
- 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 +853 -853
- package/src/rules/tree/leading-iscache.js +39 -39
- package/src/rules/tree/leading-iscontent.js +35 -35
- 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 +76 -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 -149
- 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,76 @@
|
|
|
1
|
-
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
-
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
-
// const Constants = require('../../Constants');
|
|
4
|
-
// const GeneralUtils = require('../../util/GeneralUtils');
|
|
5
|
-
|
|
6
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
7
|
-
const description = 'Only one element per line is allowed';
|
|
8
|
-
|
|
9
|
-
const Rule = Object.create(TreeRulePrototype);
|
|
10
|
-
|
|
11
|
-
Rule.init(ruleId, description);
|
|
12
|
-
|
|
13
|
-
Rule.isBroken = function(node) {
|
|
14
|
-
|
|
15
|
-
const config = ConfigUtils.load();
|
|
16
|
-
const ruleConfig = config.rules[ruleId];
|
|
17
|
-
|
|
18
|
-
if (ruleConfig && ruleConfig.except) {
|
|
19
|
-
|
|
20
|
-
if (node.parent && node.parent.isOfType('iscomment') && ruleConfig.except.indexOf('iscomment') >= 0) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!node.isIsmlTag() && !node.isHtmlTag() && ruleConfig.except.indexOf('non-tag') >= 0) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return !node.isRoot() &&
|
|
30
|
-
!node.parent.isContainer() &&
|
|
31
|
-
node.lineNumber === node.parent.lineNumber;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Rule.getFixedContent = rootNode => {
|
|
35
|
-
// fixContent(rootNode);
|
|
36
|
-
|
|
37
|
-
// return GeneralUtils.applyActiveLineBreaks(rootNode.toString());
|
|
38
|
-
// };
|
|
39
|
-
|
|
40
|
-
// const fixContent = node => {
|
|
41
|
-
// for (let i = 0; i < node.children.length; i++) {
|
|
42
|
-
// const child = node.children[i];
|
|
43
|
-
|
|
44
|
-
// if (child.isInSameLineAsParent() && !node.isIsmlComment()) {
|
|
45
|
-
// const indentation = getCorrectIndentation(child);
|
|
46
|
-
// const parentIndentation = getCorrectIndentation(node);
|
|
47
|
-
|
|
48
|
-
// child.head = `${Constants.EOL}${indentation}${child.head}${Constants.EOL}${parentIndentation}`;
|
|
49
|
-
|
|
50
|
-
// if (child.tail) {
|
|
51
|
-
// child.setTail(`${Constants.EOL}${indentation}${child.tail}${Constants.EOL}`);
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
// fixContent(child);
|
|
56
|
-
// }
|
|
57
|
-
// };
|
|
58
|
-
|
|
59
|
-
// const getCorrectIndentation = node => {
|
|
60
|
-
// const indentSize = node.depth - 1;
|
|
61
|
-
// const config = ConfigUtils.load();
|
|
62
|
-
// let indentation = '';
|
|
63
|
-
// let indentUnit = '';
|
|
64
|
-
|
|
65
|
-
// for (let i = 0; i < (config.indent || 4); ++i) {
|
|
66
|
-
// indentUnit += ' ';
|
|
67
|
-
// }
|
|
68
|
-
|
|
69
|
-
// for (let i = 0; i < indentSize; ++i) {
|
|
70
|
-
// indentation += indentUnit;
|
|
71
|
-
// }
|
|
72
|
-
|
|
73
|
-
// return indentation;
|
|
74
|
-
// };
|
|
75
|
-
|
|
76
|
-
module.exports = Rule;
|
|
1
|
+
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
+
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
+
// const Constants = require('../../Constants');
|
|
4
|
+
// const GeneralUtils = require('../../util/GeneralUtils');
|
|
5
|
+
|
|
6
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
7
|
+
const description = 'Only one element per line is allowed';
|
|
8
|
+
|
|
9
|
+
const Rule = Object.create(TreeRulePrototype);
|
|
10
|
+
|
|
11
|
+
Rule.init(ruleId, description);
|
|
12
|
+
|
|
13
|
+
Rule.isBroken = function(node) {
|
|
14
|
+
|
|
15
|
+
const config = ConfigUtils.load();
|
|
16
|
+
const ruleConfig = config.rules[ruleId];
|
|
17
|
+
|
|
18
|
+
if (ruleConfig && ruleConfig.except) {
|
|
19
|
+
|
|
20
|
+
if (node.parent && node.parent.isOfType('iscomment') && ruleConfig.except.indexOf('iscomment') >= 0) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!node.isIsmlTag() && !node.isHtmlTag() && ruleConfig.except.indexOf('non-tag') >= 0) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return !node.isRoot() &&
|
|
30
|
+
!node.parent.isContainer() &&
|
|
31
|
+
node.lineNumber === node.parent.lineNumber;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Rule.getFixedContent = rootNode => {
|
|
35
|
+
// fixContent(rootNode);
|
|
36
|
+
|
|
37
|
+
// return GeneralUtils.applyActiveLineBreaks(rootNode.toString());
|
|
38
|
+
// };
|
|
39
|
+
|
|
40
|
+
// const fixContent = node => {
|
|
41
|
+
// for (let i = 0; i < node.children.length; i++) {
|
|
42
|
+
// const child = node.children[i];
|
|
43
|
+
|
|
44
|
+
// if (child.isInSameLineAsParent() && !node.isIsmlComment()) {
|
|
45
|
+
// const indentation = getCorrectIndentation(child);
|
|
46
|
+
// const parentIndentation = getCorrectIndentation(node);
|
|
47
|
+
|
|
48
|
+
// child.head = `${Constants.EOL}${indentation}${child.head}${Constants.EOL}${parentIndentation}`;
|
|
49
|
+
|
|
50
|
+
// if (child.tail) {
|
|
51
|
+
// child.setTail(`${Constants.EOL}${indentation}${child.tail}${Constants.EOL}`);
|
|
52
|
+
// }
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
// fixContent(child);
|
|
56
|
+
// }
|
|
57
|
+
// };
|
|
58
|
+
|
|
59
|
+
// const getCorrectIndentation = node => {
|
|
60
|
+
// const indentSize = node.depth - 1;
|
|
61
|
+
// const config = ConfigUtils.load();
|
|
62
|
+
// let indentation = '';
|
|
63
|
+
// let indentUnit = '';
|
|
64
|
+
|
|
65
|
+
// for (let i = 0; i < (config.indent || 4); ++i) {
|
|
66
|
+
// indentUnit += ' ';
|
|
67
|
+
// }
|
|
68
|
+
|
|
69
|
+
// for (let i = 0; i < indentSize; ++i) {
|
|
70
|
+
// indentation += indentUnit;
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
// return indentation;
|
|
74
|
+
// };
|
|
75
|
+
|
|
76
|
+
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;
|