@interlace/eslint-devkit 1.4.0 → 1.4.1
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 +6 -0
- package/README.md +10 -1
- package/package.json +2 -2
- package/src/aria-definitions.d.ts +5 -0
- package/src/aria-definitions.js +28 -1
- package/src/node/path.js +29 -5
- package/src/resolver/dependency-analysis.d.ts +20 -0
- package/src/resolver/dependency-analysis.js +148 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## [1.4.0] - 2026-05-03
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#155](https://github.com/ofri-peretz/eslint/pull/155) [`736a5fe`](https://github.com/ofri-peretz/eslint/commit/736a5fed47e673f6157ea900b29fe2a54e4bc7df) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Fix `patternToRegex` (glob→regex) to escape **all** regex metacharacters, not just `.`. The previous chained `.replace()` left `\ + ( ) | [ ] { } ^ $` to leak through as regex syntax, so an ignore glob such as `a+b` or `(x)` compiled to a quantifier / capture group and matched the wrong files (CWE-116, surfaced by CodeQL `js/incomplete-sanitization`). The wildcard translation (`**`, `*`, `?`) is unchanged; a regression-lock test pins the metacharacter behavior.
|
|
8
|
+
|
|
3
9
|
### Changed
|
|
4
10
|
|
|
5
11
|
- Module resolver swapped from `enhanced-resolve` + `get-tsconfig` to [`oxc-resolver`](https://www.npmjs.com/package/oxc-resolver) (Rust NAPI, ~18-30× faster). Per-tsconfig caching for monorepo path-alias correctness across package boundaries.
|
package/README.md
CHANGED
|
@@ -522,10 +522,19 @@ MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
|
522
522
|
|
|
523
523
|
## Contributing
|
|
524
524
|
|
|
525
|
-
Contributions welcome! See
|
|
525
|
+
Contributions welcome! See CONTRIBUTING.md (planned).
|
|
526
526
|
|
|
527
527
|
---
|
|
528
528
|
|
|
529
|
+
<!-- INTERLACE:STAR_CTA:START -->
|
|
530
|
+
## ⭐ Support & follow
|
|
531
|
+
|
|
532
|
+
If the devkit saved you time, **[star the repo](https://github.com/ofri-peretz/eslint)** — stars are the signal that keeps the Interlace ESLint ecosystem maintained — and **[follow the writeups on Dev.to](https://dev.to/ofri-peretz)** for the benchmarks and engineering behind these tools.
|
|
533
|
+
|
|
534
|
+
[](https://github.com/ofri-peretz/eslint)
|
|
535
|
+
|
|
536
|
+
<!-- INTERLACE:STAR_CTA:END -->
|
|
537
|
+
|
|
529
538
|
## Changelog
|
|
530
539
|
|
|
531
540
|
See [CHANGELOG.md](./CHANGELOG.md) for a list of changes and version history.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "TypeScript utilities for building LLM-optimized ESLint plugins - AST helpers, type utilities, security benchmarks, and SARIF output",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@typescript-eslint/utils": "^7.0.0 || ^8.0.0",
|
|
80
|
-
"oxc-resolver": "^11.
|
|
80
|
+
"oxc-resolver": "^11.20.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@typescript-eslint/parser": "^8.46.2",
|
|
@@ -11,4 +11,9 @@ export declare const ARIA_ROLES: Set<string>;
|
|
|
11
11
|
export declare const ARIA_ATTRIBUTES: Set<string>;
|
|
12
12
|
export declare const ARIA_REQUIRED_PROPS: Record<string, string[]>;
|
|
13
13
|
export declare const ARIA_UNSUPPORTED_ELEMENTS: Set<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Global ARIA properties valid on every element regardless of role.
|
|
16
|
+
* Per WAI-ARIA 1.2 § 6.2 "Global States and Properties".
|
|
17
|
+
*/
|
|
18
|
+
export declare const GLOBAL_ARIA_PROPS: Set<string>;
|
|
14
19
|
export declare const ROLE_SUPPORTED_ARIA_PROPS: Record<string, Set<string>>;
|
package/src/aria-definitions.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* MIT license that can be found in the LICENSE file.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.ROLE_SUPPORTED_ARIA_PROPS = exports.ARIA_UNSUPPORTED_ELEMENTS = exports.ARIA_REQUIRED_PROPS = exports.ARIA_ATTRIBUTES = exports.ARIA_ROLES = void 0;
|
|
8
|
+
exports.ROLE_SUPPORTED_ARIA_PROPS = exports.GLOBAL_ARIA_PROPS = exports.ARIA_UNSUPPORTED_ELEMENTS = exports.ARIA_REQUIRED_PROPS = exports.ARIA_ATTRIBUTES = exports.ARIA_ROLES = void 0;
|
|
9
9
|
/**
|
|
10
10
|
* ARIA Definitions
|
|
11
11
|
* Lists of valid ARIA roles and attributes
|
|
@@ -177,6 +177,33 @@ exports.ARIA_UNSUPPORTED_ELEMENTS = new Set([
|
|
|
177
177
|
'title',
|
|
178
178
|
'track',
|
|
179
179
|
]);
|
|
180
|
+
/**
|
|
181
|
+
* Global ARIA properties valid on every element regardless of role.
|
|
182
|
+
* Per WAI-ARIA 1.2 § 6.2 "Global States and Properties".
|
|
183
|
+
*/
|
|
184
|
+
exports.GLOBAL_ARIA_PROPS = new Set([
|
|
185
|
+
'aria-atomic',
|
|
186
|
+
'aria-busy',
|
|
187
|
+
'aria-controls',
|
|
188
|
+
'aria-current',
|
|
189
|
+
'aria-describedby',
|
|
190
|
+
'aria-details',
|
|
191
|
+
'aria-disabled',
|
|
192
|
+
'aria-dropeffect',
|
|
193
|
+
'aria-errormessage',
|
|
194
|
+
'aria-flowto',
|
|
195
|
+
'aria-grabbed',
|
|
196
|
+
'aria-haspopup',
|
|
197
|
+
'aria-hidden',
|
|
198
|
+
'aria-invalid',
|
|
199
|
+
'aria-keyshortcuts',
|
|
200
|
+
'aria-label',
|
|
201
|
+
'aria-labelledby',
|
|
202
|
+
'aria-live',
|
|
203
|
+
'aria-owns',
|
|
204
|
+
'aria-relevant',
|
|
205
|
+
'aria-roledescription',
|
|
206
|
+
]);
|
|
180
207
|
// Mapping of roles to supported ARIA properties
|
|
181
208
|
exports.ROLE_SUPPORTED_ARIA_PROPS = {
|
|
182
209
|
alert: new Set([
|
package/src/node/path.js
CHANGED
|
@@ -47,11 +47,35 @@ function patternToRegex(pattern, cache) {
|
|
|
47
47
|
if (cached) {
|
|
48
48
|
return cached;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
// Translate the glob in a single left-to-right pass: escape every regex
|
|
51
|
+
// metacharacter, then map the glob wildcards (**, *, ?) to their regex
|
|
52
|
+
// equivalents. Doing it in one pass means an escaped metacharacter can never
|
|
53
|
+
// be re-interpreted as a wildcard. The previous chained-replace only handled
|
|
54
|
+
// `. * ?`, leaving `\ + ( ) [ ] { } ^ $ |` to leak through as regex syntax
|
|
55
|
+
// (CWE-116, incomplete sanitization) — e.g. the glob `a+b` compiled to the
|
|
56
|
+
// quantifier `a+b` instead of matching the literal `a+b`.
|
|
57
|
+
let escaped = '';
|
|
58
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
59
|
+
const ch = pattern[i];
|
|
60
|
+
if (ch === '*') {
|
|
61
|
+
if (pattern[i + 1] === '*') {
|
|
62
|
+
escaped += '.*';
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
escaped += '[^/]*';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (ch === '?') {
|
|
70
|
+
escaped += '.';
|
|
71
|
+
}
|
|
72
|
+
else if (/[.+^${}()|[\]\\]/.test(ch)) {
|
|
73
|
+
escaped += '\\' + ch;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
escaped += ch;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
55
79
|
const regex = new RegExp(escaped);
|
|
56
80
|
cache.set(pattern, regex);
|
|
57
81
|
return regex;
|
|
@@ -40,6 +40,8 @@ export interface ImportInfo {
|
|
|
40
40
|
source: string;
|
|
41
41
|
/** Whether this is a dynamic import (import()) */
|
|
42
42
|
dynamic?: boolean;
|
|
43
|
+
/** Whether this is a type-only import (import type {...}) — erased at compile time */
|
|
44
|
+
typeOnly?: boolean;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Strongly Connected Component result
|
|
@@ -258,6 +260,24 @@ export declare function computeSCCsFromFile(startFile: string, options: Omit<Cyc
|
|
|
258
260
|
* @returns true if file is part of a cycle
|
|
259
261
|
*/
|
|
260
262
|
export declare function isFileInCycle(file: string, cache: FileSystemCache): boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Find the shortest cycle path from targetFile back to sourceFile via BFS.
|
|
265
|
+
*
|
|
266
|
+
* This is the path-finding phase — called ONLY after the SCC pre-check
|
|
267
|
+
* confirms that sourceFile and targetFile are in the same SCC (meaning a
|
|
268
|
+
* cycle MUST exist). BFS guarantees the shortest cycle path is returned.
|
|
269
|
+
*
|
|
270
|
+
* Only traverses files within the same SCC (O(1) lookup per hop), so the
|
|
271
|
+
* worst-case work is proportional to the SCC size, not the entire graph.
|
|
272
|
+
*
|
|
273
|
+
* @param sourceFile - The file that contains the import (cycle closes here)
|
|
274
|
+
* @param targetFile - The file being imported (BFS starts here)
|
|
275
|
+
* @param options - Traversal options (workspaceRoot, barrelExports, cache, resolverSettings)
|
|
276
|
+
* @returns The cycle path [targetFile, ..., sourceFile], or null if not found
|
|
277
|
+
*/
|
|
278
|
+
export declare function findShortestCyclePath(sourceFile: string, targetFile: string, options: Omit<CycleDetectionOptions, 'reportAllCycles' | 'maxDepth'> & {
|
|
279
|
+
maxDepth?: number;
|
|
280
|
+
}): string[] | null;
|
|
261
281
|
/**
|
|
262
282
|
* Get the cycle containing a specific file
|
|
263
283
|
*
|
|
@@ -21,6 +21,7 @@ exports.getFileImports = getFileImports;
|
|
|
21
21
|
exports.hasOnlyTypeImports = hasOnlyTypeImports;
|
|
22
22
|
exports.computeSCCsFromFile = computeSCCsFromFile;
|
|
23
23
|
exports.isFileInCycle = isFileInCycle;
|
|
24
|
+
exports.findShortestCyclePath = findShortestCyclePath;
|
|
24
25
|
exports.getCycleForFile = getCycleForFile;
|
|
25
26
|
exports.detectCycleFromImport = detectCycleFromImport;
|
|
26
27
|
exports.findAllCircularDependencies = findAllCircularDependencies;
|
|
@@ -139,7 +140,7 @@ const TYPE_IMPORT_REGEX = /import\s+type\s/;
|
|
|
139
140
|
* Negative lookahead `(?!type[\s{])` excludes `export type ... from` —
|
|
140
141
|
* those are erased at compile time and don't cause runtime cycles.
|
|
141
142
|
*/
|
|
142
|
-
const EXPORT_FROM_REGEX = /
|
|
143
|
+
const EXPORT_FROM_REGEX = /export\s+\{[\s\S]*?\}\s+from\s+['"]([^'"]+)['"]/g;
|
|
143
144
|
/**
|
|
144
145
|
* Default extensions for import resolution.
|
|
145
146
|
* Module-level constant to avoid allocating a new array per resolve call.
|
|
@@ -464,16 +465,26 @@ function getFileImports(file, options) {
|
|
|
464
465
|
// Track resolved paths to dedupe across the three regexes (a single file
|
|
465
466
|
// may have both `import X from 'y'` and `export { X } from 'y'`).
|
|
466
467
|
const seen = new Set();
|
|
467
|
-
const pushImport = (importPath, dynamic = false) => {
|
|
468
|
+
const pushImport = (importPath, dynamic = false, typeOnly = false) => {
|
|
468
469
|
const resolved = resolveImportPath(importPath, resolveOpts);
|
|
469
470
|
if (resolved && fileExists(resolved, cache) && !seen.has(resolved)) {
|
|
470
471
|
seen.add(resolved);
|
|
471
|
-
|
|
472
|
+
const info = { path: resolved, source: importPath };
|
|
473
|
+
if (dynamic)
|
|
474
|
+
info.dynamic = true;
|
|
475
|
+
if (typeOnly)
|
|
476
|
+
info.typeOnly = true;
|
|
477
|
+
imports.push(info);
|
|
472
478
|
}
|
|
473
479
|
};
|
|
474
|
-
// Match ES6 static imports using pre-compiled regex
|
|
475
|
-
|
|
476
|
-
|
|
480
|
+
// Match ES6 static imports using pre-compiled regex.
|
|
481
|
+
// Detect `import type { ... }` by checking if the full match starts with
|
|
482
|
+
// "import type" — these edges are erased at compile time and must not
|
|
483
|
+
// participate in the SCC graph (they cannot cause runtime cycles).
|
|
484
|
+
while ((match = IMPORT_REGEX.exec(content)) !== null) {
|
|
485
|
+
const isTypeImport = /^import\s+type[\s{]/.test(match[0]);
|
|
486
|
+
pushImport(match[1], false, isTypeImport);
|
|
487
|
+
}
|
|
477
488
|
// Match re-exports (`export … from '…'`). Without this, cycles routed
|
|
478
489
|
// through re-export-only files (a common pattern in barrel-heavy
|
|
479
490
|
// codebases) are invisible.
|
|
@@ -541,9 +552,19 @@ function hasOnlyTypeImports(cycle, cache) {
|
|
|
541
552
|
* @returns Array of SCCs (each SCC is an array of file paths)
|
|
542
553
|
*/
|
|
543
554
|
function computeSCCsFromFile(startFile, options) {
|
|
555
|
+
// Normalize to real path: on macOS /tmp is a symlink to /private/tmp.
|
|
556
|
+
// Without this, the starting file is keyed as /tmp/... while all imports
|
|
557
|
+
// resolve to /private/tmp/... — Tarjan's sees them as distinct nodes and
|
|
558
|
+
// misses cycles that cross the symlink boundary.
|
|
559
|
+
try {
|
|
560
|
+
startFile = (0, node_fs_1.realpathSync)(startFile);
|
|
561
|
+
}
|
|
562
|
+
catch { /* ignore broken symlinks */ }
|
|
544
563
|
const { workspaceRoot, barrelExports, cache, resolverSettings } = options;
|
|
545
|
-
// If SCC
|
|
546
|
-
|
|
564
|
+
// If SCC already computed AND covers this file, return cached result.
|
|
565
|
+
// If not in the index, the file wasn't reachable from the previous root —
|
|
566
|
+
// fall through to extend the SCC from this new starting file.
|
|
567
|
+
if (cache.sccComputed && cache.sccs.length > 0 && cache.sccIndex.has(startFile)) {
|
|
547
568
|
return cache.sccs;
|
|
548
569
|
}
|
|
549
570
|
const state = {
|
|
@@ -572,7 +593,11 @@ function computeSCCsFromFile(startFile, options) {
|
|
|
572
593
|
resolverSettings,
|
|
573
594
|
});
|
|
574
595
|
for (const imp of imports) {
|
|
575
|
-
|
|
596
|
+
// Skip dynamic imports and type-only imports — type edges are erased at
|
|
597
|
+
// compile time and cannot form runtime cycles. Excluding them from the
|
|
598
|
+
// SCC graph produces a smaller, more accurate graph and eliminates FPs
|
|
599
|
+
// that would appear for `import type { Foo }` back-references.
|
|
600
|
+
if (!imp.dynamic && !imp.typeOnly && !visited.has(imp.path)) {
|
|
576
601
|
filesToProcess.push(imp.path);
|
|
577
602
|
}
|
|
578
603
|
}
|
|
@@ -584,20 +609,44 @@ function computeSCCsFromFile(startFile, options) {
|
|
|
584
609
|
}
|
|
585
610
|
}
|
|
586
611
|
// Convert to SCCResult format
|
|
587
|
-
const
|
|
612
|
+
const newResults = state.sccs.map((files) => ({
|
|
588
613
|
files,
|
|
589
614
|
hasCycle: files.length > 1,
|
|
590
615
|
}));
|
|
591
|
-
//
|
|
592
|
-
|
|
616
|
+
// MERGE into existing cache — never overwrite. When called from a new root
|
|
617
|
+
// file not previously reachable, we extend the global SCC rather than
|
|
618
|
+
// replacing it. Existing sccIndex entries are preserved so previously
|
|
619
|
+
// processed files retain their cycle membership information.
|
|
620
|
+
const offset = cache.sccs.length;
|
|
621
|
+
cache.sccs.push(...newResults);
|
|
593
622
|
cache.sccComputed = true;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
623
|
+
for (let i = 0; i < newResults.length; i++) {
|
|
624
|
+
for (const file of newResults[i].files) {
|
|
625
|
+
if (!cache.sccIndex.has(file)) {
|
|
626
|
+
cache.sccIndex.set(file, offset + i);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
// Update nonCyclicFiles from SCC results:
|
|
631
|
+
// - Singleton SCCs (hasCycle=false) → file is PROVABLY non-cyclic → add permanently
|
|
632
|
+
// - Multi-file cyclic SCCs → remove from nonCyclicFiles in case a previous pass
|
|
633
|
+
// incorrectly marked them as non-cyclic (e.g., from an incomplete DFS)
|
|
634
|
+
//
|
|
635
|
+
// With nonCyclicFiles populated here from the authoritative SCC, the ImportDeclaration
|
|
636
|
+
// handler can use it as an O(1) fast path without needing to clear it per-file.
|
|
637
|
+
for (const result of newResults) {
|
|
638
|
+
if (result.hasCycle) {
|
|
639
|
+
for (const file of result.files) {
|
|
640
|
+
cache.nonCyclicFiles.delete(file);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
for (const file of result.files) {
|
|
645
|
+
cache.nonCyclicFiles.add(file);
|
|
646
|
+
}
|
|
598
647
|
}
|
|
599
648
|
}
|
|
600
|
-
return
|
|
649
|
+
return cache.sccs;
|
|
601
650
|
}
|
|
602
651
|
/**
|
|
603
652
|
* Tarjan's strong connect function (recursive part)
|
|
@@ -622,8 +671,9 @@ function tarjanStrongConnect(file, state, options, depth) {
|
|
|
622
671
|
resolverSettings,
|
|
623
672
|
});
|
|
624
673
|
for (const imp of imports) {
|
|
625
|
-
// Skip dynamic imports
|
|
626
|
-
|
|
674
|
+
// Skip dynamic and type-only imports — type edges are erased at compile
|
|
675
|
+
// time and must not participate in SCC graph edges.
|
|
676
|
+
if (imp.dynamic || imp.typeOnly)
|
|
627
677
|
continue;
|
|
628
678
|
const successor = imp.path;
|
|
629
679
|
if (!state.indices.has(successor)) {
|
|
@@ -669,6 +719,56 @@ function isFileInCycle(file, cache) {
|
|
|
669
719
|
const scc = cache.sccs[sccIndex];
|
|
670
720
|
return scc && scc.hasCycle;
|
|
671
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* Find the shortest cycle path from targetFile back to sourceFile via BFS.
|
|
724
|
+
*
|
|
725
|
+
* This is the path-finding phase — called ONLY after the SCC pre-check
|
|
726
|
+
* confirms that sourceFile and targetFile are in the same SCC (meaning a
|
|
727
|
+
* cycle MUST exist). BFS guarantees the shortest cycle path is returned.
|
|
728
|
+
*
|
|
729
|
+
* Only traverses files within the same SCC (O(1) lookup per hop), so the
|
|
730
|
+
* worst-case work is proportional to the SCC size, not the entire graph.
|
|
731
|
+
*
|
|
732
|
+
* @param sourceFile - The file that contains the import (cycle closes here)
|
|
733
|
+
* @param targetFile - The file being imported (BFS starts here)
|
|
734
|
+
* @param options - Traversal options (workspaceRoot, barrelExports, cache, resolverSettings)
|
|
735
|
+
* @returns The cycle path [targetFile, ..., sourceFile], or null if not found
|
|
736
|
+
*/
|
|
737
|
+
function findShortestCyclePath(sourceFile, targetFile, options) {
|
|
738
|
+
const { workspaceRoot, barrelExports, cache, resolverSettings } = options;
|
|
739
|
+
const srcSCC = cache.sccIndex.get(sourceFile);
|
|
740
|
+
if (srcSCC === undefined)
|
|
741
|
+
return null;
|
|
742
|
+
// BFS from targetFile, looking for a path back to sourceFile
|
|
743
|
+
const queue = [[targetFile]];
|
|
744
|
+
const visited = new Set([targetFile]);
|
|
745
|
+
while (queue.length > 0) {
|
|
746
|
+
const path = queue.shift();
|
|
747
|
+
const current = path[path.length - 1];
|
|
748
|
+
const imports = getFileImports(current, {
|
|
749
|
+
workspaceRoot,
|
|
750
|
+
barrelExports,
|
|
751
|
+
cache,
|
|
752
|
+
resolverSettings,
|
|
753
|
+
});
|
|
754
|
+
for (const imp of imports) {
|
|
755
|
+
if (imp.dynamic || imp.typeOnly)
|
|
756
|
+
continue;
|
|
757
|
+
if (imp.path === sourceFile) {
|
|
758
|
+
// Found the cycle — return the complete path
|
|
759
|
+
return [...path, sourceFile];
|
|
760
|
+
}
|
|
761
|
+
if (visited.has(imp.path))
|
|
762
|
+
continue;
|
|
763
|
+
// Only traverse files in the same SCC — anything else cannot reach sourceFile
|
|
764
|
+
if (cache.sccIndex.get(imp.path) !== srcSCC)
|
|
765
|
+
continue;
|
|
766
|
+
visited.add(imp.path);
|
|
767
|
+
queue.push([...path, imp.path]);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
672
772
|
/**
|
|
673
773
|
* Get the cycle containing a specific file
|
|
674
774
|
*
|
|
@@ -708,6 +808,17 @@ function getCycleForFile(file, cache) {
|
|
|
708
808
|
* @returns Array of cycle paths found (each is an array of file paths ending at sourceFile)
|
|
709
809
|
*/
|
|
710
810
|
function detectCycleFromImport(sourceFile, targetFile, options) {
|
|
811
|
+
// Normalize paths: on macOS /tmp is a symlink to /private/tmp.
|
|
812
|
+
// ESLint provides the symlink path; resolved imports use the real path.
|
|
813
|
+
// Without normalization, `file === sourceFile` never matches in the DFS.
|
|
814
|
+
try {
|
|
815
|
+
sourceFile = (0, node_fs_1.realpathSync)(sourceFile);
|
|
816
|
+
}
|
|
817
|
+
catch { /* ignore */ }
|
|
818
|
+
try {
|
|
819
|
+
targetFile = (0, node_fs_1.realpathSync)(targetFile);
|
|
820
|
+
}
|
|
821
|
+
catch { /* ignore */ }
|
|
711
822
|
const { maxDepth, reportAllCycles, workspaceRoot, barrelExports, cache, resolverSettings, } = options;
|
|
712
823
|
// Fast path: target is known to not be in any cycle
|
|
713
824
|
if (cache.nonCyclicFiles.has(targetFile)) {
|
|
@@ -795,8 +906,18 @@ function detectCycleFromImport(sourceFile, targetFile, options) {
|
|
|
795
906
|
* @param visited - Set of fully explored files (internal use, persistent)
|
|
796
907
|
* @returns Array of cycles found (each cycle is an array of file paths)
|
|
797
908
|
*/
|
|
798
|
-
function findAllCircularDependencies(file, options, currentPath = [],
|
|
909
|
+
function findAllCircularDependencies(file, options, currentPath = [],
|
|
910
|
+
// NOTE: depth=0 is the root call; normalization happens only there.
|
|
911
|
+
depth = 0, visited = new Set()) {
|
|
799
912
|
const { maxDepth, reportAllCycles, workspaceRoot, barrelExports, cache, resolverSettings, } = options;
|
|
913
|
+
// Normalize to real path at the root call (depth=0 only — recursive calls
|
|
914
|
+
// already receive normalised paths from the resolver's import resolution).
|
|
915
|
+
if (depth === 0) {
|
|
916
|
+
try {
|
|
917
|
+
file = (0, node_fs_1.realpathSync)(file);
|
|
918
|
+
}
|
|
919
|
+
catch { /* ignore broken symlinks */ }
|
|
920
|
+
}
|
|
800
921
|
// OPTIMIZATION 1: Check if file is known to not be in any cycle
|
|
801
922
|
// This is populated across the lint run — once a file is confirmed
|
|
802
923
|
// non-cyclic, all future calls skip it in O(1).
|
|
@@ -830,10 +951,16 @@ function findAllCircularDependencies(file, options, currentPath = [], depth = 0,
|
|
|
830
951
|
if (currentPath.includes(file)) {
|
|
831
952
|
return [[...currentPath, file]];
|
|
832
953
|
}
|
|
833
|
-
// OPTIMIZATION 3: Skip if already
|
|
954
|
+
// OPTIMIZATION 3: Skip if already visited in this DFS run.
|
|
955
|
+
// `visited` is added BEFORE exploring children (below) to prevent
|
|
956
|
+
// infinite recursion through cyclic graphs. This is correct: if we
|
|
957
|
+
// encounter a file already on our `visited` set it means we've started
|
|
958
|
+
// exploring it from a sibling branch — we can safely skip it because
|
|
959
|
+
// the currentPath.includes() check above already handles the cycle case.
|
|
834
960
|
if (visited.has(file)) {
|
|
835
961
|
return [];
|
|
836
962
|
}
|
|
963
|
+
// Mark visited BEFORE recursing to prevent infinite loops on cyclic graphs.
|
|
837
964
|
visited.add(file);
|
|
838
965
|
const imports = getFileImports(file, {
|
|
839
966
|
workspaceRoot,
|