oxlint-plugin-arch 0.3.1 → 0.3.3

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.2
4
+
5
+ - Fix `chain-newline` reporting already-wrapped chains whose root is parenthesized, like `(db as TestDb)\n .insertInto()`, spans several lines, or has a comment between two links.
6
+ - Autofix `call-array-multiline` arrays with parenthesized elements, like `Promise.all([(a), (b)])`.
7
+
3
8
  ## 0.3.1
4
9
 
5
10
  - Fix `key-value-same-line` reporting `key: (` values whose parenthesized expression starts on the next line.
package/dist/index.js CHANGED
@@ -815,32 +815,43 @@ function callArrayMultilineIsShadowed(context, root) {
815
815
  }
816
816
  return false;
817
817
  }
818
- function callArrayMultilineEdits(array, text, elementIndent, baseIndent, newline) {
818
+ function callArrayMultilineOuterRange(source, node) {
819
+ let range = [node.range[0], node.range[1]];
820
+ let before = source.getTokenBefore(node);
821
+ let after = source.getTokenAfter(node);
822
+ while (before?.value === "(" && after?.value === ")") {
823
+ range = [before.range[0], after.range[1]];
824
+ before = source.getTokenBefore(before);
825
+ after = source.getTokenAfter(after);
826
+ }
827
+ return range;
828
+ }
829
+ function callArrayMultilineEdits(array, source, text, elementIndent, baseIndent, newline) {
819
830
  const elements = array.elements;
820
831
  if (elements.some((element) => element === null))
821
832
  return null;
822
- const present = elements.filter((element) => element !== null);
833
+ const present = elements.filter((element) => element !== null).map((element) => callArrayMultilineOuterRange(source, element));
823
834
  const first = present[0];
824
835
  const last = present.at(-1);
825
836
  if (!first || !last)
826
837
  return null;
827
838
  const edits = [];
828
- const openingRange = [array.range[0] + 1, first.range[0]];
839
+ const openingRange = [array.range[0] + 1, first[0]];
829
840
  if (!/^\s*$/.test(text.slice(...openingRange)))
830
841
  return null;
831
842
  edits.push({ range: openingRange, text: `${newline}${elementIndent}` });
832
843
  for (let index = 1;index < present.length; index++) {
833
844
  const previous = present[index - 1];
834
845
  const current = present[index];
835
- const gap = text.slice(previous.range[1], current.range[0]);
846
+ const gap = text.slice(previous[1], current[0]);
836
847
  if (!/^,\s*$/.test(gap))
837
848
  return null;
838
849
  edits.push({
839
- range: [previous.range[1] + 1, current.range[0]],
850
+ range: [previous[1] + 1, current[0]],
840
851
  text: `${newline}${elementIndent}`
841
852
  });
842
853
  }
843
- const closingRange = [last.range[1], array.range[1] - 1];
854
+ const closingRange = [last[1], array.range[1] - 1];
844
855
  const closingGap = text.slice(...closingRange);
845
856
  if (!/^,?\s*$/.test(closingGap))
846
857
  return null;
@@ -898,7 +909,7 @@ var callArrayMultiline = defineRule({
898
909
  const text = source.text;
899
910
  const baseIndent = layoutLineIndent(text, array.range[0]);
900
911
  const hasComments = source.getCommentsInside(array).length > 0;
901
- const edits = hasComments ? null : callArrayMultilineEdits(array, text, baseIndent + indentUnit, baseIndent, newline);
912
+ const edits = hasComments ? null : callArrayMultilineEdits(array, source, text, baseIndent + indentUnit, baseIndent, newline);
902
913
  context.report({
903
914
  node: array,
904
915
  messageId: "multiline",
@@ -1011,7 +1022,7 @@ var chainNewline = defineRule2({
1011
1022
  return;
1012
1023
  const source = context.sourceCode;
1013
1024
  const text = source.text;
1014
- const chainIndent = layoutLineIndent(text, root.range[0]) + indentUnit;
1025
+ const chainIndent = layoutLineIndent(text, node.range[0]) + indentUnit;
1015
1026
  const replacements = [];
1016
1027
  let fixable = true;
1017
1028
  let needsFix = false;
@@ -1021,14 +1032,19 @@ var chainNewline = defineRule2({
1021
1032
  needsFix = true;
1022
1033
  continue;
1023
1034
  }
1024
- const range = [link.member.object.range[1], link.member.property.range[0]];
1035
+ const operatorToken = source.getTokenBefore(link.member.property);
1036
+ const objectEnd = (operatorToken && source.getTokenBefore(operatorToken)) ?? link.member.object;
1037
+ const range = [objectEnd.range[1], link.member.property.range[0]];
1025
1038
  const gap = text.slice(...range);
1026
1039
  const operator = link.member.optional ? "?." : ".";
1027
1040
  const expected = `${newline}${chainIndent}${operator}`;
1028
- if (source.commentsExistBetween(link.member.object, link.member.property) || gap.trim() !== operator) {
1041
+ const hasComments = source.commentsExistBetween(objectEnd, link.member.property);
1042
+ if (hasComments || gap.trim() !== operator) {
1029
1043
  fixable = false;
1030
1044
  }
1031
- if (gap !== expected) {
1045
+ const lastComment = hasComments && operatorToken ? source.getTokenBefore(operatorToken, { includeComments: true }) : null;
1046
+ const alignedAfterComment = lastComment !== null && text.slice(lastComment.range[1], link.member.property.range[0]) === expected;
1047
+ if (gap !== expected && !alignedAfterComment) {
1032
1048
  needsFix = true;
1033
1049
  replacements.push({ range, text: expected });
1034
1050
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-plugin-arch",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Configurable architecture rules for Oxlint JavaScript plugins.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",