eslint-plugin-absolute 0.2.2 → 0.2.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/dist/index.js CHANGED
@@ -1114,7 +1114,7 @@ var sortExports = {
1114
1114
  });
1115
1115
  return unsorted ? messageId : null;
1116
1116
  };
1117
- const checkForwardDependencies = (items) => {
1117
+ const hasForwardDependenciesInOrder = (items) => {
1118
1118
  const exportNames = items.map((item) => item.name);
1119
1119
  return items.some((item, idx) => {
1120
1120
  const laterNames = new Set(exportNames.slice(idx + 1));
@@ -1130,6 +1130,27 @@ var sortExports = {
1130
1130
  return false;
1131
1131
  });
1132
1132
  };
1133
+ const wouldCreateForwardDependencies = (items, sortedItems) => {
1134
+ const sortedIndices = new Map(sortedItems.map((item, idx) => [item.name, idx]));
1135
+ const exportNames = new Set(items.map((item) => item.name));
1136
+ return items.some((item) => {
1137
+ const itemIndex = sortedIndices.get(item.name);
1138
+ if (itemIndex === undefined) {
1139
+ return false;
1140
+ }
1141
+ const dependencies = getImmediateDependencyNames(item.node);
1142
+ for (const dependency of dependencies) {
1143
+ if (!exportNames.has(dependency)) {
1144
+ continue;
1145
+ }
1146
+ const dependencyIndex = sortedIndices.get(dependency);
1147
+ if (dependencyIndex !== undefined && itemIndex < dependencyIndex) {
1148
+ return true;
1149
+ }
1150
+ }
1151
+ return false;
1152
+ });
1153
+ };
1133
1154
  const processExportBlock = (block) => {
1134
1155
  if (block.length < minKeys) {
1135
1156
  return;
@@ -1142,10 +1163,13 @@ var sortExports = {
1142
1163
  if (!messageId) {
1143
1164
  return;
1144
1165
  }
1145
- if (checkForwardDependencies(items)) {
1166
+ if (hasForwardDependenciesInOrder(items)) {
1146
1167
  return;
1147
1168
  }
1148
1169
  const sortedItems = items.slice().sort(sortComparator);
1170
+ if (wouldCreateForwardDependencies(items, sortedItems)) {
1171
+ return;
1172
+ }
1149
1173
  const expectedOrder = sortedItems.map((item) => item.name).join(", ");
1150
1174
  const [firstNode] = block;
1151
1175
  const lastNode = block[block.length - 1];
package/package.json CHANGED
@@ -30,5 +30,5 @@
30
30
  "typecheck": "bun run tsc --noEmit"
31
31
  },
32
32
  "type": "module",
33
- "version": "0.2.2"
33
+ "version": "0.2.3"
34
34
  }
@@ -388,7 +388,7 @@ export const sortExports: TSESLint.RuleModule<MessageIds, Options> = {
388
388
  return unsorted ? messageId : null;
389
389
  };
390
390
 
391
- const checkForwardDependencies = (items: ExportItem[]) => {
391
+ const hasForwardDependenciesInOrder = (items: ExportItem[]) => {
392
392
  const exportNames = items.map((item) => item.name);
393
393
  return items.some((item, idx) => {
394
394
  const laterNames = new Set(exportNames.slice(idx + 1));
@@ -406,6 +406,37 @@ export const sortExports: TSESLint.RuleModule<MessageIds, Options> = {
406
406
  });
407
407
  };
408
408
 
409
+ const wouldCreateForwardDependencies = (
410
+ items: ExportItem[],
411
+ sortedItems: ExportItem[]
412
+ ) => {
413
+ const sortedIndices = new Map(
414
+ sortedItems.map((item, idx) => [item.name, idx])
415
+ );
416
+ const exportNames = new Set(items.map((item) => item.name));
417
+
418
+ return items.some((item) => {
419
+ const itemIndex = sortedIndices.get(item.name);
420
+ if (itemIndex === undefined) {
421
+ return false;
422
+ }
423
+
424
+ const dependencies = getImmediateDependencyNames(item.node);
425
+ for (const dependency of dependencies) {
426
+ if (!exportNames.has(dependency)) {
427
+ continue;
428
+ }
429
+
430
+ const dependencyIndex = sortedIndices.get(dependency);
431
+ if (dependencyIndex !== undefined && itemIndex < dependencyIndex) {
432
+ return true;
433
+ }
434
+ }
435
+
436
+ return false;
437
+ });
438
+ };
439
+
409
440
  const processExportBlock = (
410
441
  block: TSESTree.ExportNamedDeclaration[]
411
442
  ) => {
@@ -424,12 +455,16 @@ export const sortExports: TSESLint.RuleModule<MessageIds, Options> = {
424
455
  return;
425
456
  }
426
457
 
427
- if (checkForwardDependencies(items)) {
458
+ if (hasForwardDependenciesInOrder(items)) {
428
459
  return;
429
460
  }
430
461
 
431
462
  const sortedItems = items.slice().sort(sortComparator);
432
463
 
464
+ if (wouldCreateForwardDependencies(items, sortedItems)) {
465
+ return;
466
+ }
467
+
433
468
  const expectedOrder = sortedItems
434
469
  .map((item) => item.name)
435
470
  .join(", ");