isml-linter 5.43.4 → 5.43.6

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,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.43.6] - 2023-02-25
4
+
5
+ ### Fixed
6
+ - "indent" Rule - don't add indentation to embbeded "isprint" tag if it's in the same line as previous attribute;
7
+
8
+ ## [5.43.5] - 2023-02-21
9
+
10
+ ### Fixed
11
+ - "indent" Rule - keep indentation of closing tag that is in same line as corresponding opening tag;
12
+ - Tree build for an empty template;
13
+
3
14
  ## [5.43.4] - 2023-02-20
4
15
 
5
16
  ### Fixed
@@ -1108,6 +1119,8 @@
1108
1119
  ### Added
1109
1120
  - Linter is published;
1110
1121
 
1122
+ [5.43.6]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.5...v5.43.6
1123
+ [5.43.5]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.4...v5.43.5
1111
1124
  [5.43.4]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.3...v5.43.4
1112
1125
  [5.43.3]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.2...v5.43.3
1113
1126
  [5.43.2]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.1...v5.43.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isml-linter",
3
- "version": "5.43.4",
3
+ "version": "5.43.6",
4
4
  "author": "Fabiow Quixadá <ftquixada@gmail.com>",
5
5
  "license": "MIT",
6
6
  "main": "src/publicApi.js",
@@ -445,16 +445,16 @@ const privateToString = (node, stream = '') => {
445
445
  };
446
446
 
447
447
  const getAttributes = node => {
448
- const trimmedHead = node.head.trim();
449
- const nodeHead = trimmedHead.substring(1, trimmedHead.length - 1);
450
- const firstSpaceAfterTagPos = ParseUtils.getFirstEmptyCharPos(trimmedHead);
451
- const leadingEmptySpaceQty = ParseUtils.getNextNonEmptyCharPos(nodeHead);
452
- const afterTagContent = nodeHead.substring(leadingEmptySpaceQty + firstSpaceAfterTagPos);
453
- const stringifiedAttributeList = getStringifiedAttributeArray(afterTagContent);
454
- const attributeList = [];
455
-
456
- for (let i = 0; i < stringifiedAttributeList.length; i++) {
457
- const attr = parseAttribute(node, stringifiedAttributeList, i);
448
+ const trimmedHead = node.head.trim();
449
+ const nodeHead = trimmedHead.substring(1, trimmedHead.length - 1);
450
+ const firstSpaceAfterTagPos = ParseUtils.getFirstEmptyCharPos(trimmedHead);
451
+ const leadingEmptySpaceQty = ParseUtils.getNextNonEmptyCharPos(nodeHead);
452
+ const afterTagContent = nodeHead.substring(leadingEmptySpaceQty + firstSpaceAfterTagPos);
453
+ const rawAttributeList = getStringifiedAttributeArray(afterTagContent);
454
+ const attributeList = [];
455
+
456
+ for (let i = 0; i < rawAttributeList.length; i++) {
457
+ const attr = parseAttribute(node, rawAttributeList, attributeList, i);
458
458
  attributeList.push(attr);
459
459
  }
460
460
 
@@ -525,8 +525,8 @@ const getStringifiedAttributeArray = content => {
525
525
  return result;
526
526
  };
527
527
 
528
- const parseAttribute = (node, attributeList, index) => {
529
- const attribute = attributeList[index];
528
+ const parseAttribute = (node, rawAttributeList, resultingAttributeList, index) => {
529
+ const attribute = rawAttributeList[index];
530
530
  const isAttributeANestedIsmlTag = attribute.startsWith('<is');
531
531
  const isExpressionAttribute = attribute.startsWith('${') && attribute.endsWith('}');
532
532
  const trimmedAttribute = attribute.trim();
@@ -547,6 +547,7 @@ const parseAttribute = (node, attributeList, index) => {
547
547
  const isFirstValueInSameLineAsAttributeName = value && ParseUtils.getLeadingLineBreakQty(value) === 0;
548
548
  const quoteChar = getQuoteChar(trimmedAttribute);
549
549
  const attributeNameFirstLine = name.split(Constants.EOL)[0];
550
+ const isInSameLineAsPreviousAttribute = index >= 1 && resultingAttributeList[index - 1].lineNumber === lineNumber;
550
551
 
551
552
  const columnNumber = isInSameLineAsTagName ?
552
553
  node.columnNumber + leadingContent.length :
@@ -572,6 +573,7 @@ const parseAttribute = (node, attributeList, index) => {
572
573
  isInSameLineAsTagName,
573
574
  isFirstInLine,
574
575
  isFirstValueInSameLineAsAttributeName,
576
+ isInSameLineAsPreviousAttribute,
575
577
  isExpressionAttribute,
576
578
  hasMultilineValue,
577
579
  isNestedIsmlTag : isAttributeANestedIsmlTag,
@@ -594,6 +596,7 @@ const parseAttribute = (node, attributeList, index) => {
594
596
  isInSameLineAsTagName,
595
597
  isFirstInLine,
596
598
  isFirstValueInSameLineAsAttributeName,
599
+ isInSameLineAsPreviousAttribute,
597
600
  isExpressionAttribute,
598
601
  hasMultilineValue,
599
602
  isNestedIsmlTag: isAttributeANestedIsmlTag,
@@ -491,6 +491,10 @@ const getElementList = (templateContent, templatePath, isCrlfLineBreak) => {
491
491
  const elementList = state.elementList;
492
492
  let previousStateContent = state.remainingShadowContent;
493
493
 
494
+ if (templateContent === '') {
495
+ return [];
496
+ }
497
+
494
498
  do {
495
499
  initLoopState(state);
496
500
  parseNextElement(state);
@@ -441,21 +441,24 @@ const addIndentationToText = node => {
441
441
  };
442
442
 
443
443
  const getIndentedNestedIsmlContent = (attribute, nodeIndentation, attributeOffset) => {
444
- if (attribute.fullContent.startsWith('<isif')) {
445
- const attributeRootNode = TreeBuilder.parse(attribute.fullContent, null, null, true);
446
- const fixedContent = Rule.getFixedContent(attributeRootNode);
444
+ const attributeRootNode = TreeBuilder.parse(attribute.fullContent, null, null, true);
445
+ const fixedContent = Rule.getFixedContent(attributeRootNode);
447
446
 
448
- return fixedContent
449
- .split(Constants.EOL)
450
- .map( (line, i) => {
451
- if (i === 0 && attribute.isFirstInLine && !attribute.isInSameLineAsTagName && attribute.index !== 0) {
452
- return Constants.EOL + nodeIndentation + attributeOffset + line;
453
- }
447
+ return fixedContent
448
+ .split(Constants.EOL)
449
+ .map( (line, i) => {
450
+ const shouldAddLineBreak = i === 0 && attribute.isFirstInLine && !attribute.isInSameLineAsTagName && attribute.index !== 0;
454
451
 
455
- return nodeIndentation + attributeOffset + line;
456
- })
457
- .join(Constants.EOL);
458
- }
452
+ if (attribute.isInSameLineAsPreviousAttribute) {
453
+ return ' ' + line;
454
+ }
455
+
456
+ return (shouldAddLineBreak ? Constants.EOL : '')
457
+ + nodeIndentation
458
+ + attributeOffset
459
+ + line;
460
+ })
461
+ .join(Constants.EOL);
459
462
  };
460
463
 
461
464
  const getTreeBuiltAttributeIndentedValue = (attribute, nodeIndentation, attributeOffset) => {
@@ -763,6 +766,7 @@ const checkIfShouldAddIndentationToTail = node => {
763
766
  const isInSameLineAsChild = !node.hasChildren() || node.getLastChild().isInSameLineAsParent();
764
767
  const isTailInSameLineAsChild = !node.hasChildren() || node.tailLineNumber === node.getLastChild().getLastLineNumber();
765
768
  const isBrokenIntoMultipleLines = !node.hasChildren() && node.tailLineNumber && node.lineNumber !== node.tailLineNumber;
769
+ const isInSameLineAsOpeningTag = !node.hasChildren() && node.tailLineNumber && node.endLineNumber === node.tailLineNumber;
766
770
 
767
771
  const shouldAdd = hasTail &&
768
772
  !isTailInSameLineAsChild &&
@@ -774,6 +778,11 @@ const checkIfShouldAddIndentationToTail = node => {
774
778
  ||
775
779
  isBrokenIntoMultipleLines;
776
780
 
781
+ // TODO Merge this condition into the above ones;
782
+ if (isInSameLineAsOpeningTag) {
783
+ return false;
784
+ }
785
+
777
786
  return shouldAdd;
778
787
  };
779
788