isml-linter 5.39.4 → 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
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.40.0] - 2022-02-05
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- "one-element-per-line" rule autofix;
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- Small "indent" rule issue;
|
|
10
|
+
- Tree build edge case;
|
|
11
|
+
|
|
3
12
|
## [5.39.4] - 2022-01-30
|
|
4
13
|
|
|
5
14
|
### Fixed
|
|
@@ -1002,6 +1011,7 @@
|
|
|
1002
1011
|
### Added
|
|
1003
1012
|
- Linter is published;
|
|
1004
1013
|
|
|
1014
|
+
[5.40.0]: https://github.com/FabiowQuixada/isml-linter/compare/v5.39.4...v5.40.0
|
|
1005
1015
|
[5.39.4]: https://github.com/FabiowQuixada/isml-linter/compare/v5.39.3...v5.39.4
|
|
1006
1016
|
[5.39.3]: https://github.com/FabiowQuixada/isml-linter/compare/v5.39.2...v5.39.3
|
|
1007
1017
|
[5.39.2]: https://github.com/FabiowQuixada/isml-linter/compare/v5.39.1...v5.39.2
|
package/package.json
CHANGED
|
@@ -251,6 +251,14 @@ class IsmlNode {
|
|
|
251
251
|
return this.parent && this.parent.isIsmlComment();
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
isHardCodedText() {
|
|
255
|
+
return !this.isRoot()
|
|
256
|
+
&& !this.isContainer()
|
|
257
|
+
&& !this.isConditionalComment()
|
|
258
|
+
&& !this.isTag()
|
|
259
|
+
&& !this.isExpression();
|
|
260
|
+
}
|
|
261
|
+
|
|
254
262
|
getPreviousSibling() {
|
|
255
263
|
if (!this.parent || !this.parent.isContainer() && this.isFirstChild() || this.parent.isContainer() && this.parent.isFirstChild() && this.isFirstChild()) {
|
|
256
264
|
return null;
|
|
@@ -193,6 +193,7 @@ const getElementType = trimmedElement => {
|
|
|
193
193
|
const typeValueLastPos = Math.min(...[
|
|
194
194
|
trimmedElement.indexOf(' '),
|
|
195
195
|
trimmedElement.indexOf('/'),
|
|
196
|
+
trimmedElement.indexOf(Constants.EOL),
|
|
196
197
|
trimmedElement.indexOf('>')
|
|
197
198
|
].filter(j => j >= 0));
|
|
198
199
|
|
package/src/rules/tree/indent.js
CHANGED
|
@@ -754,6 +754,9 @@ const checkIfShouldAddIndentationToTail = node => {
|
|
|
754
754
|
!isTailInSameLineAsChild &&
|
|
755
755
|
!isInSameLineAsChild &&
|
|
756
756
|
!isLastClause
|
|
757
|
+
// TODO Works for a specific case only. Might have side effects;
|
|
758
|
+
||
|
|
759
|
+
node.isOfType('iscomment') && !isTailInSameLineAsChild
|
|
757
760
|
||
|
|
758
761
|
isBrokenIntoMultipleLines;
|
|
759
762
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const TreeRulePrototype = require('../prototypes/TreeRulePrototype');
|
|
2
|
+
const IndentRule = require('../tree/indent');
|
|
2
3
|
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
const Constants = require('../../Constants');
|
|
5
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
6
|
+
const TreeBuilder = require('../../isml_tree/TreeBuilder');
|
|
5
7
|
|
|
6
8
|
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
7
9
|
const description = 'Only one element per line is allowed';
|
|
@@ -28,49 +30,53 @@ Rule.isBroken = function(node) {
|
|
|
28
30
|
|
|
29
31
|
return !node.isRoot() &&
|
|
30
32
|
!node.parent.isContainer() &&
|
|
31
|
-
node.lineNumber === node.parent.
|
|
33
|
+
node.lineNumber === node.parent.endLineNumber;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
Rule.getFixedContent = rootNode => {
|
|
37
|
+
addLineBreaks(rootNode);
|
|
36
38
|
|
|
37
|
-
//
|
|
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);
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// const child = node.children[i];
|
|
43
|
-
|
|
44
|
-
// if (child.isInSameLineAsParent() && !node.isIsmlComment()) {
|
|
45
|
-
// const indentation = getCorrectIndentation(child);
|
|
46
|
-
// const parentIndentation = getCorrectIndentation(node);
|
|
45
|
+
return GeneralUtils.applyActiveLineBreaks(partialFixContent);
|
|
46
|
+
};
|
|
47
47
|
|
|
48
|
-
|
|
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;
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
53
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
54
|
+
const child = node.children[i];
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (shouldAddLeadingLineBreakToChildHead(node, child, shouldIgnoreNonTags)) {
|
|
57
|
+
child.head = Constants.EOL + child.head;
|
|
58
|
+
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// let indentation = '';
|
|
63
|
-
// let indentUnit = '';
|
|
60
|
+
if (shouldAddLeadingLineBreakToParentTail(node, child, shouldIgnoreNonTags)) {
|
|
61
|
+
node.tail = Constants.EOL + node.tail;
|
|
62
|
+
}
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
addLineBreaks(child);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
};
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
};
|
|
75
81
|
|
|
76
82
|
module.exports = Rule;
|