@interlace/eslint-devkit 1.0.0

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.
Files changed (77) hide show
  1. package/AGENTS.md +352 -0
  2. package/CHANGELOG.md +88 -0
  3. package/LICENSE +22 -0
  4. package/README.md +528 -0
  5. package/package.json +88 -0
  6. package/src/aria-definitions.d.ts +9 -0
  7. package/src/aria-definitions.js +973 -0
  8. package/src/aria-definitions.js.map +1 -0
  9. package/src/ast/ast-utils.d.ts +81 -0
  10. package/src/ast/ast-utils.js +201 -0
  11. package/src/ast/ast-utils.js.map +1 -0
  12. package/src/ast/index.d.ts +1 -0
  13. package/src/ast/index.js +6 -0
  14. package/src/ast/index.js.map +1 -0
  15. package/src/index.d.ts +30 -0
  16. package/src/index.js +54 -0
  17. package/src/index.js.map +1 -0
  18. package/src/messaging/constants.d.ts +120 -0
  19. package/src/messaging/constants.js +744 -0
  20. package/src/messaging/constants.js.map +1 -0
  21. package/src/messaging/formatters.d.ts +124 -0
  22. package/src/messaging/formatters.js +330 -0
  23. package/src/messaging/formatters.js.map +1 -0
  24. package/src/messaging/index.d.ts +3 -0
  25. package/src/messaging/index.js +8 -0
  26. package/src/messaging/index.js.map +1 -0
  27. package/src/messaging/types.d.ts +122 -0
  28. package/src/messaging/types.js +8 -0
  29. package/src/messaging/types.js.map +1 -0
  30. package/src/node/fs.d.ts +65 -0
  31. package/src/node/fs.js +129 -0
  32. package/src/node/fs.js.map +1 -0
  33. package/src/node/index.d.ts +3 -0
  34. package/src/node/index.js +8 -0
  35. package/src/node/index.js.map +1 -0
  36. package/src/node/os.d.ts +24 -0
  37. package/src/node/os.js +49 -0
  38. package/src/node/os.js.map +1 -0
  39. package/src/node/path.d.ts +121 -0
  40. package/src/node/path.js +209 -0
  41. package/src/node/path.js.map +1 -0
  42. package/src/resolver/dependency-analysis.d.ts +421 -0
  43. package/src/resolver/dependency-analysis.js +934 -0
  44. package/src/resolver/dependency-analysis.js.map +1 -0
  45. package/src/resolver/index.d.ts +4 -0
  46. package/src/resolver/index.js +9 -0
  47. package/src/resolver/index.js.map +1 -0
  48. package/src/resolver/resolver-adapter.d.ts +53 -0
  49. package/src/resolver/resolver-adapter.js +126 -0
  50. package/src/resolver/resolver-adapter.js.map +1 -0
  51. package/src/resolver/resolver-detection.d.ts +36 -0
  52. package/src/resolver/resolver-detection.js +219 -0
  53. package/src/resolver/resolver-detection.js.map +1 -0
  54. package/src/resolver/resolver.d.ts +52 -0
  55. package/src/resolver/resolver.js +294 -0
  56. package/src/resolver/resolver.js.map +1 -0
  57. package/src/resolver.d.ts +1 -0
  58. package/src/resolver.js +5 -0
  59. package/src/resolver.js.map +1 -0
  60. package/src/rule-creation/index.d.ts +1 -0
  61. package/src/rule-creation/index.js +6 -0
  62. package/src/rule-creation/index.js.map +1 -0
  63. package/src/rule-creation/rule-creator.d.ts +42 -0
  64. package/src/rule-creation/rule-creator.js +42 -0
  65. package/src/rule-creation/rule-creator.js.map +1 -0
  66. package/src/security/index.d.ts +1 -0
  67. package/src/security/index.js +6 -0
  68. package/src/security/index.js.map +1 -0
  69. package/src/security/security-utils.d.ts +303 -0
  70. package/src/security/security-utils.js +607 -0
  71. package/src/security/security-utils.js.map +1 -0
  72. package/src/types/index.d.ts +1 -0
  73. package/src/types/index.js +6 -0
  74. package/src/types/index.js.map +1 -0
  75. package/src/types/type-utils.d.ts +146 -0
  76. package/src/types/type-utils.js +329 -0
  77. package/src/types/type-utils.js.map +1 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Node.js 'fs' module wrapper and utilities
3
+ *
4
+ * All file system operations should go through these wrappers for:
5
+ * - Testability (can mock these functions)
6
+ * - Code coverage (all operations tracked)
7
+ * - Consistency (error handling, return types)
8
+ */
9
+ import * as fs from 'node:fs';
10
+ /**
11
+ * Check if a file exists (uncached)
12
+ *
13
+ * @param filePath - Path to the file
14
+ * @returns true if file exists
15
+ */
16
+ export declare function fileExistsSync(filePath: string): boolean;
17
+ /**
18
+ * Read file content synchronously (uncached)
19
+ *
20
+ * @param filePath - Path to the file
21
+ * @param encoding - File encoding (default: 'utf-8')
22
+ * @returns File content or null if file doesn't exist or can't be read
23
+ */
24
+ export declare function readFileSync(filePath: string, encoding?: BufferEncoding): string | null;
25
+ /**
26
+ * Read and parse JSON file synchronously
27
+ *
28
+ * @param filePath - Path to the JSON file
29
+ * @returns Parsed JSON object or null if file doesn't exist or is invalid JSON
30
+ */
31
+ export declare function readJsonFileSync<T = unknown>(filePath: string): T | null;
32
+ /**
33
+ * Get file stats synchronously
34
+ *
35
+ * @param filePath - Path to the file
36
+ * @returns File stats or null if file doesn't exist or can't be read
37
+ */
38
+ export declare function statSync(filePath: string): fs.Stats | null;
39
+ /**
40
+ * Create directory synchronously (with parent directories if needed)
41
+ *
42
+ * @param dirPath - Path to the directory
43
+ * @param options - Options for directory creation
44
+ * @returns true if directory was created or already exists, false on error
45
+ */
46
+ export declare function mkdirSync(dirPath: string, options?: {
47
+ recursive?: boolean;
48
+ }): boolean;
49
+ /**
50
+ * Write file content synchronously
51
+ *
52
+ * @param filePath - Path to the file
53
+ * @param content - Content to write
54
+ * @param encoding - File encoding (default: 'utf-8')
55
+ * @returns true if write succeeded, false on error
56
+ */
57
+ export declare function writeFileSync(filePath: string, content: string, encoding?: BufferEncoding): boolean;
58
+ /**
59
+ * Find a file by walking up directories from a starting point
60
+ *
61
+ * @param filename - Name of the file to find (e.g., 'package.json')
62
+ * @param startDir - Directory to start searching from
63
+ * @returns Absolute path to the file or null if not found
64
+ */
65
+ export declare function findFileUpward(filename: string, startDir: string): string | null;
package/src/node/fs.js ADDED
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileExistsSync = fileExistsSync;
4
+ exports.readFileSync = readFileSync;
5
+ exports.readJsonFileSync = readJsonFileSync;
6
+ exports.statSync = statSync;
7
+ exports.mkdirSync = mkdirSync;
8
+ exports.writeFileSync = writeFileSync;
9
+ exports.findFileUpward = findFileUpward;
10
+ const tslib_1 = require("tslib");
11
+ /**
12
+ * Node.js 'fs' module wrapper and utilities
13
+ *
14
+ * All file system operations should go through these wrappers for:
15
+ * - Testability (can mock these functions)
16
+ * - Code coverage (all operations tracked)
17
+ * - Consistency (error handling, return types)
18
+ */
19
+ const fs = tslib_1.__importStar(require("node:fs"));
20
+ const path_1 = require("./path");
21
+ /**
22
+ * Check if a file exists (uncached)
23
+ *
24
+ * @param filePath - Path to the file
25
+ * @returns true if file exists
26
+ */
27
+ function fileExistsSync(filePath) {
28
+ return fs.existsSync(filePath);
29
+ }
30
+ /**
31
+ * Read file content synchronously (uncached)
32
+ *
33
+ * @param filePath - Path to the file
34
+ * @param encoding - File encoding (default: 'utf-8')
35
+ * @returns File content or null if file doesn't exist or can't be read
36
+ */
37
+ function readFileSync(filePath, encoding = 'utf-8') {
38
+ try {
39
+ return fs.readFileSync(filePath, encoding);
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ /**
46
+ * Read and parse JSON file synchronously
47
+ *
48
+ * @param filePath - Path to the JSON file
49
+ * @returns Parsed JSON object or null if file doesn't exist or is invalid JSON
50
+ */
51
+ function readJsonFileSync(filePath) {
52
+ const content = readFileSync(filePath);
53
+ if (content === null) {
54
+ return null;
55
+ }
56
+ try {
57
+ return JSON.parse(content);
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /**
64
+ * Get file stats synchronously
65
+ *
66
+ * @param filePath - Path to the file
67
+ * @returns File stats or null if file doesn't exist or can't be read
68
+ */
69
+ function statSync(filePath) {
70
+ try {
71
+ return fs.statSync(filePath);
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ /**
78
+ * Create directory synchronously (with parent directories if needed)
79
+ *
80
+ * @param dirPath - Path to the directory
81
+ * @param options - Options for directory creation
82
+ * @returns true if directory was created or already exists, false on error
83
+ */
84
+ function mkdirSync(dirPath, options) {
85
+ try {
86
+ fs.mkdirSync(dirPath, { recursive: true, ...options });
87
+ return true;
88
+ }
89
+ catch {
90
+ return false;
91
+ }
92
+ }
93
+ /**
94
+ * Write file content synchronously
95
+ *
96
+ * @param filePath - Path to the file
97
+ * @param content - Content to write
98
+ * @param encoding - File encoding (default: 'utf-8')
99
+ * @returns true if write succeeded, false on error
100
+ */
101
+ function writeFileSync(filePath, content, encoding = 'utf-8') {
102
+ try {
103
+ fs.writeFileSync(filePath, content, encoding);
104
+ return true;
105
+ }
106
+ catch {
107
+ return false;
108
+ }
109
+ }
110
+ /**
111
+ * Find a file by walking up directories from a starting point
112
+ *
113
+ * @param filename - Name of the file to find (e.g., 'package.json')
114
+ * @param startDir - Directory to start searching from
115
+ * @returns Absolute path to the file or null if not found
116
+ */
117
+ function findFileUpward(filename, startDir) {
118
+ let currentDir = startDir;
119
+ while (currentDir !== (0, path_1.getDirname)(currentDir)) {
120
+ // Stop at root
121
+ const candidate = (0, path_1.joinPath)(currentDir, filename);
122
+ if (fileExistsSync(candidate)) {
123
+ return candidate;
124
+ }
125
+ currentDir = (0, path_1.getDirname)(currentDir);
126
+ }
127
+ return null;
128
+ }
129
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../../../packages/eslint-devkit/src/node/fs.ts"],"names":[],"mappings":";;AAiBA,wCAEC;AASD,oCASC;AAQD,4CAUC;AAQD,4BAMC;AASD,8BAUC;AAUD,sCAWC;AASD,wCAgBC;;AAtID;;;;;;;GAOG;AACH,oDAA8B;AAC9B,iCAA8C;AAE9C;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAAgB;IAC7C,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAC1B,QAAgB,EAChB,WAA2B,OAAO;IAElC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC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AAU,GAAG,QAAQ,CAAC;IAE1B,OAAO,UAAU,KAAK,IAAA,iBAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,eAAe;QACf,MAAM,SAAS,GAAG,IAAA,eAAQ,EAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACjD,IAAI,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,UAAU,GAAG,IAAA,iBAAU,EAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './fs';
2
+ export * from './os';
3
+ export * from './path';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // Node.js utilities for cross-platform compatibility and testability
5
+ tslib_1.__exportStar(require("./fs"), exports);
6
+ tslib_1.__exportStar(require("./os"), exports);
7
+ tslib_1.__exportStar(require("./path"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/eslint-devkit/src/node/index.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,+CAAqB;AACrB,+CAAqB;AACrB,iDAAuB"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Get the platform-specific end-of-line marker
3
+ *
4
+ * @returns Platform EOL string ('\n' on Unix, '\r\n' on Windows)
5
+ */
6
+ export declare function getEOL(): string;
7
+ /**
8
+ * Get the operating system platform
9
+ *
10
+ * @returns Platform string ('darwin', 'linux', 'win32', etc.)
11
+ */
12
+ export declare function getPlatform(): NodeJS.Platform;
13
+ /**
14
+ * Get the CPU architecture
15
+ *
16
+ * @returns Architecture string ('x64', 'arm64', etc.)
17
+ */
18
+ export declare function getArch(): string;
19
+ /**
20
+ * Get the operating system's default directory for temporary files
21
+ *
22
+ * @returns Path to the temporary directory
23
+ */
24
+ export declare function getTmpDir(): string;
package/src/node/os.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEOL = getEOL;
4
+ exports.getPlatform = getPlatform;
5
+ exports.getArch = getArch;
6
+ exports.getTmpDir = getTmpDir;
7
+ const tslib_1 = require("tslib");
8
+ /**
9
+ * Node.js 'os' module wrapper and utilities
10
+ *
11
+ * All OS operations should go through these wrappers for:
12
+ * - Testability (can mock these functions)
13
+ * - Code coverage (all operations tracked)
14
+ * - Consistency (error handling, return types)
15
+ */
16
+ const os = tslib_1.__importStar(require("node:os"));
17
+ /**
18
+ * Get the platform-specific end-of-line marker
19
+ *
20
+ * @returns Platform EOL string ('\n' on Unix, '\r\n' on Windows)
21
+ */
22
+ function getEOL() {
23
+ return os.EOL;
24
+ }
25
+ /**
26
+ * Get the operating system platform
27
+ *
28
+ * @returns Platform string ('darwin', 'linux', 'win32', etc.)
29
+ */
30
+ function getPlatform() {
31
+ return os.platform();
32
+ }
33
+ /**
34
+ * Get the CPU architecture
35
+ *
36
+ * @returns Architecture string ('x64', 'arm64', etc.)
37
+ */
38
+ function getArch() {
39
+ return os.arch();
40
+ }
41
+ /**
42
+ * Get the operating system's default directory for temporary files
43
+ *
44
+ * @returns Path to the temporary directory
45
+ */
46
+ function getTmpDir() {
47
+ return os.tmpdir();
48
+ }
49
+ //# sourceMappingURL=os.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"os.js","sourceRoot":"","sources":["../../../../../packages/eslint-devkit/src/node/os.ts"],"names":[],"mappings":";;AAeA,wBAEC;AAOD,kCAEC;AAOD,0BAEC;AAOD,8BAEC;;AA5CD;;;;;;;GAOG;AACH,oDAA8B;AAE9B;;;;GAIG;AACH,SAAgB,MAAM;IACpB,OAAO,EAAE,CAAC,GAAG,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW;IACzB,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC;AACvB,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO;IACrB,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS;IACvB,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC;AACrB,CAAC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Cache type for compiled regex patterns
3
+ */
4
+ export type PatternCache = Map<string, RegExp>;
5
+ /**
6
+ * Create a new empty pattern cache
7
+ */
8
+ export declare function createPatternCache(): PatternCache;
9
+ /**
10
+ * Convert glob pattern to regex
11
+ *
12
+ * @param pattern - Glob pattern (supports **, *, ?)
13
+ * @param cache - Cache for compiled patterns
14
+ * @returns Compiled RegExp
15
+ */
16
+ export declare function patternToRegex(pattern: string, cache: PatternCache): RegExp;
17
+ /**
18
+ * Check if file should be ignored based on patterns
19
+ *
20
+ * @param file - File path to check
21
+ * @param patterns - Array of glob patterns
22
+ * @param cache - Cache for compiled patterns
23
+ * @returns true if file matches any ignore pattern
24
+ */
25
+ export declare function shouldIgnoreFile(file: string, patterns: string[], cache: PatternCache): boolean;
26
+ /**
27
+ * Check if file is a barrel export (index file)
28
+ *
29
+ * @param file - File path to check
30
+ * @param barrelExports - List of barrel export filenames
31
+ * @returns true if file is a barrel export
32
+ */
33
+ export declare function isBarrelExport(file: string, barrelExports: string[]): boolean;
34
+ /**
35
+ * Format a cycle of file paths for concise display
36
+ *
37
+ * Uses ⟷ for bidirectional (2 modules) or → chain for longer cycles.
38
+ *
39
+ * @param cycle - Array of absolute file paths in the cycle
40
+ * @param workspaceRoot - Workspace root for relative path calculation
41
+ * @returns Formatted string representation of the cycle
42
+ */
43
+ export declare function formatCycleDisplay(cycle: string[], workspaceRoot: string): string;
44
+ /**
45
+ * Get module names from a cycle of file paths
46
+ *
47
+ * Extracts human-readable module names from file paths.
48
+ * For index files, uses the directory name instead.
49
+ *
50
+ * @param cycle - Array of absolute file paths in the cycle
51
+ * @param workspaceRoot - Workspace root for relative path calculation
52
+ * @returns Array of module names
53
+ */
54
+ export declare function getModuleNames(cycle: string[], workspaceRoot: string): string[];
55
+ /**
56
+ * Generate a relative import path from one file to another
57
+ *
58
+ * Calculates the relative path and ensures it starts with './' or '../'.
59
+ * Also normalizes path separators and removes file extensions.
60
+ *
61
+ * @param fromFile - Absolute path of the importing file
62
+ * @param toFile - Absolute path of the target file
63
+ * @returns Relative import path (e.g., './utils', '../helpers')
64
+ */
65
+ export declare function getRelativeImportPath(fromFile: string, toFile: string): string;
66
+ /**
67
+ * Get the basename of a file path
68
+ *
69
+ * Simple wrapper around path.basename for convenience.
70
+ *
71
+ * @param filePath - File path (absolute or relative)
72
+ * @returns Base filename
73
+ */
74
+ export declare function getBasename(filePath: string): string;
75
+ /**
76
+ * Get the directory name of a file path
77
+ *
78
+ * Simple wrapper around path.dirname for convenience.
79
+ *
80
+ * @param filePath - File path (absolute or relative)
81
+ * @returns Directory path
82
+ */
83
+ export declare function getDirname(filePath: string): string;
84
+ /**
85
+ * Calculate relative path from one path to another
86
+ *
87
+ * @param from - Starting path
88
+ * @param to - Target path
89
+ * @returns Relative path
90
+ */
91
+ export declare function getRelativePath(from: string, to: string): string;
92
+ /**
93
+ * Normalize a file path
94
+ *
95
+ * Normalizes path separators to forward slashes for consistent display.
96
+ *
97
+ * @param filePath - File path to normalize
98
+ * @returns Normalized path with forward slashes
99
+ */
100
+ export declare function normalizePath(filePath: string): string;
101
+ /**
102
+ * Join path segments
103
+ *
104
+ * @param segments - Path segments to join
105
+ * @returns Joined path
106
+ */
107
+ export declare function joinPath(...segments: string[]): string;
108
+ /**
109
+ * Resolve path segments to absolute path
110
+ *
111
+ * @param segments - Path segments to resolve
112
+ * @returns Absolute path
113
+ */
114
+ export declare function resolvePath(...segments: string[]): string;
115
+ /**
116
+ * Get file extension
117
+ *
118
+ * @param filePath - File path
119
+ * @returns File extension including the dot (e.g., '.ts')
120
+ */
121
+ export declare function getExtname(filePath: string): string;
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPatternCache = createPatternCache;
4
+ exports.patternToRegex = patternToRegex;
5
+ exports.shouldIgnoreFile = shouldIgnoreFile;
6
+ exports.isBarrelExport = isBarrelExport;
7
+ exports.formatCycleDisplay = formatCycleDisplay;
8
+ exports.getModuleNames = getModuleNames;
9
+ exports.getRelativeImportPath = getRelativeImportPath;
10
+ exports.getBasename = getBasename;
11
+ exports.getDirname = getDirname;
12
+ exports.getRelativePath = getRelativePath;
13
+ exports.normalizePath = normalizePath;
14
+ exports.joinPath = joinPath;
15
+ exports.resolvePath = resolvePath;
16
+ exports.getExtname = getExtname;
17
+ const tslib_1 = require("tslib");
18
+ /**
19
+ * Node.js 'path' module wrapper and utilities
20
+ *
21
+ * All path operations should go through these wrappers for:
22
+ * - Testability (can mock these functions)
23
+ * - Code coverage (all operations tracked)
24
+ * - Consistency (error handling, return types)
25
+ */
26
+ const path = tslib_1.__importStar(require("node:path"));
27
+ /**
28
+ * Create a new empty pattern cache
29
+ */
30
+ function createPatternCache() {
31
+ return new Map();
32
+ }
33
+ /**
34
+ * Convert glob pattern to regex
35
+ *
36
+ * @param pattern - Glob pattern (supports **, *, ?)
37
+ * @param cache - Cache for compiled patterns
38
+ * @returns Compiled RegExp
39
+ */
40
+ function patternToRegex(pattern, cache) {
41
+ const cached = cache.get(pattern);
42
+ if (cached) {
43
+ return cached;
44
+ }
45
+ const escaped = pattern
46
+ .replace(/\./g, '\\.')
47
+ .replace(/\*\*/g, '.*')
48
+ .replace(/\*/g, '[^/]*')
49
+ .replace(/\?/g, '.');
50
+ const regex = new RegExp(escaped);
51
+ cache.set(pattern, regex);
52
+ return regex;
53
+ }
54
+ /**
55
+ * Check if file should be ignored based on patterns
56
+ *
57
+ * @param file - File path to check
58
+ * @param patterns - Array of glob patterns
59
+ * @param cache - Cache for compiled patterns
60
+ * @returns true if file matches any ignore pattern
61
+ */
62
+ function shouldIgnoreFile(file, patterns, cache) {
63
+ const normalizedFile = path.normalize(file);
64
+ return patterns.some((pattern) => {
65
+ const regex = patternToRegex(pattern, cache);
66
+ return regex.test(normalizedFile);
67
+ });
68
+ }
69
+ /**
70
+ * Check if file is a barrel export (index file)
71
+ *
72
+ * @param file - File path to check
73
+ * @param barrelExports - List of barrel export filenames
74
+ * @returns true if file is a barrel export
75
+ */
76
+ function isBarrelExport(file, barrelExports) {
77
+ const basename = path.basename(file);
78
+ return barrelExports.includes(basename);
79
+ }
80
+ /**
81
+ * Format a cycle of file paths for concise display
82
+ *
83
+ * Uses ⟷ for bidirectional (2 modules) or → chain for longer cycles.
84
+ *
85
+ * @param cycle - Array of absolute file paths in the cycle
86
+ * @param workspaceRoot - Workspace root for relative path calculation
87
+ * @returns Formatted string representation of the cycle
88
+ */
89
+ function formatCycleDisplay(cycle, workspaceRoot) {
90
+ const formatted = cycle.map((file) => {
91
+ const relative = path.relative(workspaceRoot, file);
92
+ return relative.replace(/\\/g, '/');
93
+ });
94
+ // Use ⟷ for bidirectional (2 modules) or → chain for more
95
+ if (formatted.length === 2) {
96
+ return `${formatted[0]} ⟷ ${formatted[1]}`;
97
+ }
98
+ return formatted.join(' → ') + ` → ${formatted[0]}`;
99
+ }
100
+ /**
101
+ * Get module names from a cycle of file paths
102
+ *
103
+ * Extracts human-readable module names from file paths.
104
+ * For index files, uses the directory name instead.
105
+ *
106
+ * @param cycle - Array of absolute file paths in the cycle
107
+ * @param workspaceRoot - Workspace root for relative path calculation
108
+ * @returns Array of module names
109
+ */
110
+ function getModuleNames(cycle, workspaceRoot) {
111
+ return cycle.map((file) => {
112
+ const relative = path.relative(workspaceRoot, file);
113
+ const basename = path.basename(relative, path.extname(relative));
114
+ return basename === 'index'
115
+ ? path.basename(path.dirname(relative))
116
+ : basename;
117
+ });
118
+ }
119
+ /**
120
+ * Generate a relative import path from one file to another
121
+ *
122
+ * Calculates the relative path and ensures it starts with './' or '../'.
123
+ * Also normalizes path separators and removes file extensions.
124
+ *
125
+ * @param fromFile - Absolute path of the importing file
126
+ * @param toFile - Absolute path of the target file
127
+ * @returns Relative import path (e.g., './utils', '../helpers')
128
+ */
129
+ function getRelativeImportPath(fromFile, toFile) {
130
+ const currentDir = path.dirname(fromFile);
131
+ let relativeImport = path.relative(currentDir, toFile);
132
+ // Ensure starts with ./ or ../
133
+ if (!relativeImport.startsWith('.')) {
134
+ relativeImport = './' + relativeImport;
135
+ }
136
+ // Normalize path separators and remove extension
137
+ return relativeImport.replace(/\\/g, '/').replace(/\.(ts|tsx|js|jsx)$/, '');
138
+ }
139
+ /**
140
+ * Get the basename of a file path
141
+ *
142
+ * Simple wrapper around path.basename for convenience.
143
+ *
144
+ * @param filePath - File path (absolute or relative)
145
+ * @returns Base filename
146
+ */
147
+ function getBasename(filePath) {
148
+ return path.basename(filePath);
149
+ }
150
+ /**
151
+ * Get the directory name of a file path
152
+ *
153
+ * Simple wrapper around path.dirname for convenience.
154
+ *
155
+ * @param filePath - File path (absolute or relative)
156
+ * @returns Directory path
157
+ */
158
+ function getDirname(filePath) {
159
+ return path.dirname(filePath);
160
+ }
161
+ /**
162
+ * Calculate relative path from one path to another
163
+ *
164
+ * @param from - Starting path
165
+ * @param to - Target path
166
+ * @returns Relative path
167
+ */
168
+ function getRelativePath(from, to) {
169
+ return path.relative(from, to);
170
+ }
171
+ /**
172
+ * Normalize a file path
173
+ *
174
+ * Normalizes path separators to forward slashes for consistent display.
175
+ *
176
+ * @param filePath - File path to normalize
177
+ * @returns Normalized path with forward slashes
178
+ */
179
+ function normalizePath(filePath) {
180
+ return path.normalize(filePath).replace(/\\/g, '/');
181
+ }
182
+ /**
183
+ * Join path segments
184
+ *
185
+ * @param segments - Path segments to join
186
+ * @returns Joined path
187
+ */
188
+ function joinPath(...segments) {
189
+ return path.join(...segments);
190
+ }
191
+ /**
192
+ * Resolve path segments to absolute path
193
+ *
194
+ * @param segments - Path segments to resolve
195
+ * @returns Absolute path
196
+ */
197
+ function resolvePath(...segments) {
198
+ return path.resolve(...segments);
199
+ }
200
+ /**
201
+ * Get file extension
202
+ *
203
+ * @param filePath - File path
204
+ * @returns File extension including the dot (e.g., '.ts')
205
+ */
206
+ function getExtname(filePath) {
207
+ return path.extname(filePath);
208
+ }
209
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../../../packages/eslint-devkit/src/node/path.ts"],"names":[],"mappings":";;AAkBA,gDAEC;AASD,wCAcC;AAUD,4CAUC;AASD,wCAGC;AAWD,gDAeC;AAYD,wCAWC;AAYD,sDAcC;AAUD,kCAEC;AAUD,gCAEC;AASD,0CAEC;AAUD,sCAEC;AAQD,4BAEC;AAQD,kCAEC;AAQD,gCAEC;;AAnOD;;;;;;;GAOG;AACH,wDAAkC;AAOlC;;GAEG;AACH,SAAgB,kBAAkB;IAChC,OAAO,IAAI,GAAG,EAAE,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,OAAe,EAAE,KAAmB;IACjE,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG,OAAO;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;SACtB,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC;SACvB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvB,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,QAAkB,EAClB,KAAmB;IAEnB,MAAM,cAAc,GAAG,IAAI,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