@sarj/eslint-plugin 16.38.50 → 16.38.52
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.cjs +58 -6
- package/dist/index.js +58 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2573,16 +2573,68 @@ function typeBinding(source, identifier) {
|
|
|
2573
2573
|
}
|
|
2574
2574
|
return null;
|
|
2575
2575
|
}
|
|
2576
|
+
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
2576
2577
|
function retainsNamedTypeUses(source, removed) {
|
|
2577
2578
|
const manager = source.scopeManager;
|
|
2578
2579
|
if (manager === null) return false;
|
|
2579
|
-
const
|
|
2580
|
-
|
|
2580
|
+
const index = referenceIndex(source, manager);
|
|
2581
|
+
for (const reference of referencesWithin(index.references, removed)) {
|
|
2582
|
+
if (!reference.isRead()) continue;
|
|
2581
2583
|
const binding3 = reference.resolved;
|
|
2582
2584
|
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
2583
|
-
if (binding3.defs.length === 0)
|
|
2584
|
-
|
|
2585
|
-
|
|
2585
|
+
if (binding3.defs.length === 0) continue;
|
|
2586
|
+
const reads = publicReadExtents(index, binding3);
|
|
2587
|
+
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
2588
|
+
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
2589
|
+
}
|
|
2590
|
+
return true;
|
|
2591
|
+
}
|
|
2592
|
+
function referenceIndex(source, manager) {
|
|
2593
|
+
const cached = REFERENCE_INDEXES.get(source);
|
|
2594
|
+
if (cached?.manager === manager) return cached;
|
|
2595
|
+
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
2596
|
+
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
2597
|
+
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
2598
|
+
REFERENCE_INDEXES.set(source, index);
|
|
2599
|
+
return index;
|
|
2600
|
+
}
|
|
2601
|
+
function* referencesWithin(references, removed) {
|
|
2602
|
+
let low = 0;
|
|
2603
|
+
let high = references.length;
|
|
2604
|
+
while (low < high) {
|
|
2605
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
2606
|
+
const reference = references[middle];
|
|
2607
|
+
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
2608
|
+
else low = middle + 1;
|
|
2609
|
+
}
|
|
2610
|
+
for (let index = low; index < references.length; index++) {
|
|
2611
|
+
const reference = references[index];
|
|
2612
|
+
if (reference === void 0) continue;
|
|
2613
|
+
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
2614
|
+
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
function publicReadExtents(index, binding3) {
|
|
2618
|
+
const cached = index.publicReads.get(binding3);
|
|
2619
|
+
if (cached !== void 0) return cached;
|
|
2620
|
+
let type = null;
|
|
2621
|
+
let value = null;
|
|
2622
|
+
let both = null;
|
|
2623
|
+
for (const retained of binding3.references) {
|
|
2624
|
+
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
2625
|
+
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
2626
|
+
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
2627
|
+
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
2628
|
+
}
|
|
2629
|
+
const result = { type, value, both };
|
|
2630
|
+
index.publicReads.set(binding3, result);
|
|
2631
|
+
return result;
|
|
2632
|
+
}
|
|
2633
|
+
function extendExtent(extent, identifier) {
|
|
2634
|
+
return {
|
|
2635
|
+
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
2636
|
+
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
2637
|
+
};
|
|
2586
2638
|
}
|
|
2587
2639
|
function publicTypeUse(identifier) {
|
|
2588
2640
|
let node = identifier;
|
|
@@ -4209,7 +4261,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4209
4261
|
// package.json
|
|
4210
4262
|
var package_default = {
|
|
4211
4263
|
name: "@sarj/eslint-plugin",
|
|
4212
|
-
version: "16.38.
|
|
4264
|
+
version: "16.38.52",
|
|
4213
4265
|
packageManager: "npm@12.2.1",
|
|
4214
4266
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4215
4267
|
type: "module",
|
package/dist/index.js
CHANGED
|
@@ -2522,16 +2522,68 @@ function typeBinding(source, identifier) {
|
|
|
2522
2522
|
}
|
|
2523
2523
|
return null;
|
|
2524
2524
|
}
|
|
2525
|
+
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
2525
2526
|
function retainsNamedTypeUses(source, removed) {
|
|
2526
2527
|
const manager = source.scopeManager;
|
|
2527
2528
|
if (manager === null) return false;
|
|
2528
|
-
const
|
|
2529
|
-
|
|
2529
|
+
const index = referenceIndex(source, manager);
|
|
2530
|
+
for (const reference of referencesWithin(index.references, removed)) {
|
|
2531
|
+
if (!reference.isRead()) continue;
|
|
2530
2532
|
const binding3 = reference.resolved;
|
|
2531
2533
|
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
2532
|
-
if (binding3.defs.length === 0)
|
|
2533
|
-
|
|
2534
|
-
|
|
2534
|
+
if (binding3.defs.length === 0) continue;
|
|
2535
|
+
const reads = publicReadExtents(index, binding3);
|
|
2536
|
+
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
2537
|
+
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
2538
|
+
}
|
|
2539
|
+
return true;
|
|
2540
|
+
}
|
|
2541
|
+
function referenceIndex(source, manager) {
|
|
2542
|
+
const cached = REFERENCE_INDEXES.get(source);
|
|
2543
|
+
if (cached?.manager === manager) return cached;
|
|
2544
|
+
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
2545
|
+
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
2546
|
+
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
2547
|
+
REFERENCE_INDEXES.set(source, index);
|
|
2548
|
+
return index;
|
|
2549
|
+
}
|
|
2550
|
+
function* referencesWithin(references, removed) {
|
|
2551
|
+
let low = 0;
|
|
2552
|
+
let high = references.length;
|
|
2553
|
+
while (low < high) {
|
|
2554
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
2555
|
+
const reference = references[middle];
|
|
2556
|
+
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
2557
|
+
else low = middle + 1;
|
|
2558
|
+
}
|
|
2559
|
+
for (let index = low; index < references.length; index++) {
|
|
2560
|
+
const reference = references[index];
|
|
2561
|
+
if (reference === void 0) continue;
|
|
2562
|
+
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
2563
|
+
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
function publicReadExtents(index, binding3) {
|
|
2567
|
+
const cached = index.publicReads.get(binding3);
|
|
2568
|
+
if (cached !== void 0) return cached;
|
|
2569
|
+
let type = null;
|
|
2570
|
+
let value = null;
|
|
2571
|
+
let both = null;
|
|
2572
|
+
for (const retained of binding3.references) {
|
|
2573
|
+
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
2574
|
+
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
2575
|
+
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
2576
|
+
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
2577
|
+
}
|
|
2578
|
+
const result = { type, value, both };
|
|
2579
|
+
index.publicReads.set(binding3, result);
|
|
2580
|
+
return result;
|
|
2581
|
+
}
|
|
2582
|
+
function extendExtent(extent, identifier) {
|
|
2583
|
+
return {
|
|
2584
|
+
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
2585
|
+
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
2586
|
+
};
|
|
2535
2587
|
}
|
|
2536
2588
|
function publicTypeUse(identifier) {
|
|
2537
2589
|
let node = identifier;
|
|
@@ -4162,7 +4214,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4162
4214
|
// package.json
|
|
4163
4215
|
var package_default = {
|
|
4164
4216
|
name: "@sarj/eslint-plugin",
|
|
4165
|
-
version: "16.38.
|
|
4217
|
+
version: "16.38.52",
|
|
4166
4218
|
packageManager: "npm@12.2.1",
|
|
4167
4219
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4168
4220
|
type: "module",
|