@interlace/eslint-devkit 1.19.6 → 1.19.8

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/README.md CHANGED
@@ -552,6 +552,7 @@ Part of the **Interlace ESLint ecosystem** — AI-native rules with LLM-optimize
552
552
 
553
553
  | Plugin | Downloads | Description |
554
554
  | :--- | :---: | :--- |
555
+ | [`eslint-plugin-cli-floor`](https://www.npmjs.com/package/eslint-plugin-cli-floor) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-cli-floor.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-cli-floor) | CLI floor for commander, yargs and burgee. |
555
556
  | [`eslint-plugin-conventions`](https://www.npmjs.com/package/eslint-plugin-conventions) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-conventions.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-conventions) | Team-specific habits and styles. |
556
557
  | [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-import-next.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-import-next) | Fast cycle + import-graph analysis. |
557
558
  | [`eslint-plugin-maintainability`](https://www.npmjs.com/package/eslint-plugin-maintainability) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-maintainability.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-maintainability) | Cognitive load and clean-code patterns. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interlace/eslint-devkit",
3
- "version": "1.19.6",
3
+ "version": "1.19.8",
4
4
  "description": "Toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -42,6 +42,17 @@ export interface ImportInfo {
42
42
  dynamic?: boolean;
43
43
  /** Whether this is a type-only import (import type {...}) — erased at compile time */
44
44
  typeOnly?: boolean;
45
+ /**
46
+ * Whether every binding carries the INLINE modifier (`import { type A }`).
47
+ *
48
+ * Kept apart from `typeOnly` because the two are not erased under the same
49
+ * settings: a statement-level `import type` is erased everywhere, while the
50
+ * inline form is PRESERVED under `verbatimModuleSyntax` — emitted as
51
+ * `import {} from './a.js'`, which still evaluates the module. The graph
52
+ * walkers drop this edge unless `CycleDetectionOptions.verbatimModuleSyntax`
53
+ * is set; see `isErasedEdge`.
54
+ */
55
+ inlineTypeOnly?: boolean;
45
56
  }
46
57
  /**
47
58
  * Strongly Connected Component result
@@ -304,6 +315,16 @@ export interface CycleDetectionOptions {
304
315
  cache: FileSystemCache;
305
316
  /** External resolver settings */
306
317
  resolverSettings?: ResolverSetting;
318
+ /**
319
+ * The project compiles with TypeScript's `verbatimModuleSyntax`, so an
320
+ * all-inline-type import (`import { type A }`) is emitted as
321
+ * `import {} from './a.js'` and remains a runtime edge. Off by default: the
322
+ * inline form is then erased and its edge is dropped from the graph.
323
+ *
324
+ * SCC results are cached in `cache`, so a caller that walks the graph under
325
+ * both settings must use a separate `FileSystemCache` for each.
326
+ */
327
+ verbatimModuleSyntax?: boolean;
307
328
  }
308
329
  /**
309
330
  * Lightweight per-import cycle detector (Phase 3 optimization)
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.PERFORMANCE_DOCS=void 0;exports.createLRUCache=createLRUCache;exports.isDefinitelyExternal=isDefinitelyExternal;exports.createFileSystemCache=createFileSystemCache;exports.clearCache=clearCache;exports.invalidateSCCCache=invalidateSCCCache;exports.getFileHash=getFileHash;exports.isCacheValid=isCacheValid;exports.fileExists=fileExists;exports.patternToRegexWithCache=patternToRegexWithCache;exports.shouldIgnoreFileWithCache=shouldIgnoreFileWithCache;exports.resolveImportPath=resolveImportPath;exports.getFileImports=getFileImports;exports.hasOnlyTypeImports=hasOnlyTypeImports;exports.computeSCCsFromFile=computeSCCsFromFile;exports.isFileInCycle=isFileInCycle;exports.findShortestCyclePath=findShortestCyclePath;exports.getCycleForFile=getCycleForFile;exports.detectCycleFromImport=detectCycleFromImport;exports.findAllCircularDependencies=findAllCircularDependencies;exports.getMinimalCycle=getMinimalCycle;exports.getCycleHash=getCycleHash;exports.saveCacheToDisk=saveCacheToDisk;exports.loadCacheFromDisk=loadCacheFromDisk;exports.getFilesNeedingReanalysis=getFilesNeedingReanalysis;exports.isIncrementalAvailable=isIncrementalAvailable;const resolver_1=require("./resolver");const node_fs_1=require("node:fs");const fs_1=require("../node/fs");const path_1=require("../node/path");const LRU_MAX_SIZE=5e4;const EXTERNAL_MODULE_PATTERNS=[/^node:/,/^[a-z@][^/]*$/,/node_modules/];const KNOWN_EXTERNAL_PACKAGES=new Set(["react","react-dom","vue","angular","svelte","lodash","underscore","ramda","rxjs","express","koa","fastify","hapi","axios","fetch","node-fetch","got","fs","path","url","http","https","crypto","util","os","child_process","typescript","eslint","prettier","jest","vitest","mocha","webpack","rollup","vite","esbuild","parcel"]);const IMPORT_REGEX=/import\s+(?:(?:[\w*{}\s,]|'[^'\n]*'|"[^"\n]*")+\s+from\s+)?['"]([^'"]+)['"]/g;const DYNAMIC_IMPORT_REGEX=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;const TYPE_IMPORT_REGEX=/import\s+type\s/;const EXPORT_FROM_REGEX=/export\s+\{[\s\S]*?\}\s+from\s+['"]([^'"]+)['"]/g;const DEFAULT_EXTENSIONS=[".ts",".tsx",".js",".jsx"];class LRUCache{cache=new Map;maxSize;constructor(maxSize=LRU_MAX_SIZE){this.maxSize=maxSize}get(key){const value=this.cache.get(key);if(value!==void 0){this.cache.delete(key);this.cache.set(key,value)}return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.maxSize){const firstKey=this.cache.keys().next().value;if(firstKey!==void 0){this.cache.delete(firstKey)}}this.cache.set(key,value)}has(key){return this.cache.has(key)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}get size(){return this.cache.size}}function createLRUCache(maxSize=LRU_MAX_SIZE){return new LRUCache(maxSize)}function isDefinitelyExternal(importPath){const packageName=importPath.split("/")[0].replace(/^@[^/]+\//,"");if(KNOWN_EXTERNAL_PACKAGES.has(packageName)){return true}return EXTERNAL_MODULE_PATTERNS.some(pattern=>pattern.test(importPath))}function createFileSystemCache(){return{dependencies:new Map,fileExists:new Map,fileHashes:new Map,compiledPatterns:(0,path_1.createPatternCache)(),reportedCycles:new Set,sccIndex:new Map,sccs:[],sccComputed:false,graphHash:"",resolvedPaths:new Map,nonCyclicFiles:new Set,pendingCycleReports:new Map}}function clearCache(cache){cache.dependencies.clear();cache.fileExists.clear();cache.fileHashes.clear();cache.compiledPatterns.clear();cache.reportedCycles.clear();cache.sccIndex.clear();cache.sccs=[];cache.sccComputed=false;cache.graphHash="";cache.resolvedPaths=new Map;cache.nonCyclicFiles.clear();cache.pendingCycleReports.clear()}function invalidateSCCCache(cache){cache.sccIndex.clear();cache.sccs=[];cache.sccComputed=false;cache.nonCyclicFiles.clear()}function getFileHash(filePath){const stats=(0,fs_1.statSync)(filePath);if(!stats){return null}return`${stats.mtimeMs}-${stats.size}`}function isCacheValid(filePath,cache){const cachedHash=cache.fileHashes.get(filePath);if(!cachedHash)return false;const currentHash=getFileHash(filePath);return cachedHash===currentHash}function fileExists(filePath,cache){const cached=cache.fileExists.get(filePath);if(cached!==void 0){return cached}const exists=(0,fs_1.fileExistsSync)(filePath);cache.fileExists.set(filePath,exists);return exists}function patternToRegexWithCache(pattern,cache){return(0,path_1.patternToRegex)(pattern,cache.compiledPatterns)}function shouldIgnoreFileWithCache(file,patterns,cache){return(0,path_1.shouldIgnoreFile)(file,patterns,cache.compiledPatterns)}function resolveImportPath(importPath,options){const fromFile=options.fromFile;const extensions=options.extensions||DEFAULT_EXTENSIONS;const cache=options.cache;const resolverSettings=options.resolverSettings;if(isDefinitelyExternal(importPath)){if(!importPath.startsWith("@")){return null}}const isRelative=importPath.startsWith(".");if(!isRelative){const globalCached=cache.resolvedPaths.get(importPath);if(globalCached!==void 0){return globalCached}}const cacheKey=isRelative?`${fromFile}::${importPath}`:importPath;const cached=cache.resolvedPaths.get(cacheKey);if(cached!==void 0){return cached}let result=(0,resolver_1.resolveModule)(importPath,fromFile,{extensions,mainFields:["module","main"],resolverSettings});if(result&&!isRelative&&result.includes("node_modules")){try{const realPath=(0,node_fs_1.realpathSync)(result);if(realPath.includes("node_modules")){cache.resolvedPaths.set(cacheKey,null);return null}result=realPath}catch{cache.resolvedPaths.set(cacheKey,null);return null}}if(!result&&isRelative){result=(0,path_1.resolvePath)((0,path_1.getDirname)(fromFile),importPath)}cache.resolvedPaths.set(cacheKey,result);return result}function getFileImports(file,options){const{workspaceRoot,barrelExports,cache,resolverSettings}=options;const cached=cache.dependencies.get(file);if(cached){return cached}const imports=[];try{if(!fileExists(file,cache)){return imports}const content=(0,fs_1.readFileSync)(file,"utf-8");if(content===null){return imports}const resolveOpts={fromFile:file,workspaceRoot,barrelExports,cache,extensions:DEFAULT_EXTENSIONS,resolverSettings};IMPORT_REGEX.lastIndex=0;DYNAMIC_IMPORT_REGEX.lastIndex=0;EXPORT_FROM_REGEX.lastIndex=0;let match;const seen=new Set;const pushImport=(importPath,dynamic=false,typeOnly=false)=>{const resolved=resolveImportPath(importPath,resolveOpts);if(resolved&&fileExists(resolved,cache)&&!seen.has(resolved)){seen.add(resolved);const info={path:resolved,source:importPath};if(dynamic)info.dynamic=true;if(typeOnly)info.typeOnly=true;imports.push(info)}};while((match=IMPORT_REGEX.exec(content))!==null){const isTypeImport=/^import\s+type[\s{]/.test(match[0]);pushImport(match[1],false,isTypeImport)}while((match=EXPORT_FROM_REGEX.exec(content))!==null)pushImport(match[1]);while((match=DYNAMIC_IMPORT_REGEX.exec(content))!==null)pushImport(match[1],true);const hash=getFileHash(file);if(hash){const oldHash=cache.fileHashes.get(file);if(oldHash!==hash){invalidateSCCCache(cache)}cache.fileHashes.set(file,hash)}}catch{}cache.dependencies.set(file,imports);return imports}function hasOnlyTypeImports(cycle,cache){for(const file of cycle){if(!fileExists(file,cache))continue;const content=(0,fs_1.readFileSync)(file,"utf-8");if(content===null)return false;const hasRuntimeImport=!TYPE_IMPORT_REGEX.test(content)&&IMPORT_REGEX.test(content);IMPORT_REGEX.lastIndex=0;if(hasRuntimeImport){return false}}return true}function computeSCCsFromFile(startFile,options){try{startFile=(0,node_fs_1.realpathSync)(startFile)}catch{}const{workspaceRoot,barrelExports,cache,resolverSettings}=options;if(cache.sccComputed&&cache.sccs.length>0&&cache.sccIndex.has(startFile)){return cache.sccs}const state={index:0,stack:[],onStack:new Set,indices:new Map,lowlinks:new Map,sccs:[]};const visited=new Set;const filesToProcess=[startFile];while(filesToProcess.length>0){const file=filesToProcess.pop();if(visited.has(file))continue;visited.add(file);const imports=getFileImports(file,{workspaceRoot,barrelExports,cache,resolverSettings});for(const imp of imports){if(!imp.dynamic&&!imp.typeOnly&&!visited.has(imp.path)){filesToProcess.push(imp.path)}}}for(const file of visited){if(!state.indices.has(file)){tarjanStrongConnect(file,state,options,0)}}const newResults=state.sccs.map(files=>({files,hasCycle:files.length>1}));const offset=cache.sccs.length;cache.sccs.push(...newResults);cache.sccComputed=true;for(let i=0;i<newResults.length;i++){for(const file of newResults[i].files){if(!cache.sccIndex.has(file)){cache.sccIndex.set(file,offset+i)}}}for(const result of newResults){if(result.hasCycle){for(const file of result.files){cache.nonCyclicFiles.delete(file)}}else{for(const file of result.files){cache.nonCyclicFiles.add(file)}}}return cache.sccs}function tarjanStrongConnect(file,state,options,depth){const{maxDepth,workspaceRoot,barrelExports,cache,resolverSettings}=options;if(depth>maxDepth){return}const enter=(node,nodeDepth)=>{state.indices.set(node,state.index);state.lowlinks.set(node,state.index);state.index++;state.stack.push(node);state.onStack.add(node);const imports=getFileImports(node,{workspaceRoot,barrelExports,cache,resolverSettings});const successors=[];for(const imp of imports){if(imp.dynamic||imp.typeOnly)continue;successors.push(imp.path)}return{file:node,depth:nodeDepth,successors,next:0}};const relax=(node,candidate)=>{state.lowlinks.set(node,Math.min(state.lowlinks.get(node),candidate))};const frames=[enter(file,depth)];while(frames.length>0){const frame=frames[frames.length-1];if(frame.next<frame.successors.length){const successor=frame.successors[frame.next++];if(!state.indices.has(successor)){if(frame.depth+1>maxDepth){relax(frame.file,0);continue}frames.push(enter(successor,frame.depth+1))}else if(state.onStack.has(successor)){relax(frame.file,state.indices.get(successor))}continue}frames.pop();const lowlink=state.lowlinks.get(frame.file);const index=state.indices.get(frame.file);if(lowlink===index){const scc=[];let w;do{w=state.stack.pop();state.onStack.delete(w);scc.push(w)}while(w!==frame.file);state.sccs.push(scc)}const parent=frames[frames.length-1];if(parent){relax(parent.file,state.lowlinks.get(frame.file))}}}function isFileInCycle(file,cache){const sccIndex=cache.sccIndex.get(file);if(sccIndex===void 0)return false;const scc=cache.sccs[sccIndex];return scc&&scc.hasCycle}function findShortestCyclePath(sourceFile,targetFile,options){const{workspaceRoot,barrelExports,cache,resolverSettings}=options;const srcSCC=cache.sccIndex.get(sourceFile);if(srcSCC===void 0)return null;const queue=[[targetFile]];const visited=new Set([targetFile]);while(queue.length>0){const path=queue.shift();const current=path[path.length-1];const imports=getFileImports(current,{workspaceRoot,barrelExports,cache,resolverSettings});for(const imp of imports){if(imp.dynamic||imp.typeOnly)continue;if(imp.path===sourceFile){return[...path,sourceFile]}if(visited.has(imp.path))continue;if(cache.sccIndex.get(imp.path)!==srcSCC)continue;visited.add(imp.path);queue.push([...path,imp.path])}}return null}function getCycleForFile(file,cache){const sccIndex=cache.sccIndex.get(file);if(sccIndex===void 0)return null;const scc=cache.sccs[sccIndex];if(!scc||!scc.hasCycle)return null;return scc.files}function detectCycleFromImport(sourceFile,targetFile,options){try{sourceFile=(0,node_fs_1.realpathSync)(sourceFile)}catch{}try{targetFile=(0,node_fs_1.realpathSync)(targetFile)}catch{}const{maxDepth,reportAllCycles,workspaceRoot,barrelExports,cache,resolverSettings}=options;if(cache.nonCyclicFiles.has(targetFile)){return[]}const allCycles=[];const pathStack=[sourceFile];let depthLimitHit=false;function dfs(file,depth,visited2){if(file===sourceFile){allCycles.push([...pathStack,file]);return}if(depth>=maxDepth){depthLimitHit=true;return}if(visited2.has(file))return;if(cache.nonCyclicFiles.has(file))return;visited2.add(file);pathStack.push(file);const imports=getFileImports(file,{workspaceRoot,barrelExports,cache,resolverSettings});for(const imp of imports){if(imp.dynamic)continue;if(!reportAllCycles&&allCycles.length>0)break;dfs(imp.path,depth+1,visited2)}pathStack.pop()}const visited=new Set;dfs(targetFile,1,visited);if(allCycles.length===0&&!depthLimitHit){cache.nonCyclicFiles.add(targetFile)}return allCycles}function findAllCircularDependencies(file,options,currentPath=[],depth=0,visited=new Set){const{maxDepth,reportAllCycles,workspaceRoot,barrelExports,cache,resolverSettings}=options;if(depth===0){try{file=(0,node_fs_1.realpathSync)(file)}catch{}}if(cache.nonCyclicFiles.has(file)){return[]}if(depth===0){computeSCCsFromFile(file,{maxDepth,workspaceRoot,barrelExports,cache,resolverSettings});if(!isFileInCycle(file,cache)){cache.nonCyclicFiles.add(file);return[]}}if(depth>maxDepth){return[]}if(currentPath.includes(file)){return[[...currentPath,file]]}if(visited.has(file)){return[]}visited.add(file);const imports=getFileImports(file,{workspaceRoot,barrelExports,cache,resolverSettings});const newPath=[...currentPath,file];const allCycles=[];for(const imp of imports){if(imp.dynamic){continue}if(!reportAllCycles&&allCycles.length>0){break}const cycles=findAllCircularDependencies(imp.path,options,newPath,depth+1,visited);allCycles.push(...cycles)}if(depth===0&&allCycles.length===0){cache.nonCyclicFiles.add(file)}return allCycles}function getMinimalCycle(cycle){if(cycle.length<2)return cycle;const seen=new Map;for(let i=0;i<cycle.length;i++){const file=cycle[i];if(seen.has(file)){const cycleStart=seen?.get?.(file);return cycle.slice(cycleStart,i+1)}seen.set(file,i)}return cycle}function getCycleHash(cycle){const minimalCycle=getMinimalCycle(cycle);const minIndex=minimalCycle.indexOf(minimalCycle.reduce((min,curr)=>curr<min?curr:min,minimalCycle[0]));const normalized=[...minimalCycle.slice(minIndex),...minimalCycle.slice(0,minIndex)];return normalized.join("->")}const CACHE_VERSION=1;const DEFAULT_CACHE_FILE="node_modules/.cache/forge-eslint/cycles.json";const DEFAULT_MAX_CACHE_AGE=24*60*60*1e3;function saveCacheToDisk(cache,options,workspaceRoot){if(!options.enabled)return;const cacheFile=(0,path_1.resolvePath)(workspaceRoot,options.cacheFile||DEFAULT_CACHE_FILE);const data={version:CACHE_VERSION,createdAt:Date.now(),fileHashes:Object.fromEntries(cache.fileHashes),sccs:cache.sccs,sccIndex:Object.fromEntries(cache.sccIndex),nonCyclicFiles:Array.from(cache.nonCyclicFiles),graphHash:cache.graphHash};const cacheDir=(0,path_1.getDirname)(cacheFile);if(!(0,fs_1.fileExistsSync)(cacheDir)){(0,fs_1.mkdirSync)(cacheDir,{recursive:true})}(0,fs_1.writeFileSync)(cacheFile,JSON.stringify(data),"utf-8")}function loadCacheFromDisk(cache,options,workspaceRoot){if(!options.enabled)return false;const cacheFile=(0,path_1.resolvePath)(workspaceRoot,options.cacheFile||DEFAULT_CACHE_FILE);if(!(0,fs_1.fileExistsSync)(cacheFile)){return false}const content=(0,fs_1.readFileSync)(cacheFile,"utf-8");if(content===null){return false}try{const data=JSON.parse(content);if(data.version!==CACHE_VERSION){return false}const maxAge=options.maxCacheAge??DEFAULT_MAX_CACHE_AGE;if(Date.now()-data.createdAt>maxAge){return false}cache.fileHashes=new Map(Object.entries(data.fileHashes));cache.sccs=data.sccs;cache.sccIndex=new Map(Object.entries(data.sccIndex).map(([k,v])=>[k,v]));cache.nonCyclicFiles=new Set(data.nonCyclicFiles);cache.graphHash=data.graphHash;cache.sccComputed=true;return true}catch{return false}}function getFilesNeedingReanalysis(files,cache,options){if(!options.enabled||!cache.sccComputed){return files}const changedFiles=[];for(const file of files){const cachedHash=cache.fileHashes.get(file);const currentHash=getFileHash(file);if(!cachedHash||cachedHash!==currentHash){changedFiles.push(file)}}if(changedFiles.length>0){const affectedSCCIndices=new Set;for(const file of changedFiles){const sccIndex=cache.sccIndex.get(file);if(sccIndex!==void 0){affectedSCCIndices.add(sccIndex)}}const affectedFiles=new Set(changedFiles);for(const scc of cache.sccs){const sccIndex=cache.sccIndex.get(scc.files[0]);if(sccIndex!==void 0&&affectedSCCIndices.has(sccIndex)){for(const file of scc.files){affectedFiles.add(file);cache.nonCyclicFiles.delete(file)}}}for(const[file,imports]of cache.dependencies){for(const imp of imports){if(changedFiles.includes(imp.path)){affectedFiles.add(file);cache.nonCyclicFiles.delete(file);break}}}return Array.from(affectedFiles)}return[]}function isIncrementalAvailable(cache,options){return Boolean(options?.enabled&&cache.sccComputed&&cache.sccs.length>0)}exports.PERFORMANCE_DOCS={algorithm:"Tarjan SCC + DFS hybrid",timeComplexity:"O(V + E)",spaceComplexity:"O(V)",guaranteedComplete:true};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.PERFORMANCE_DOCS=void 0;exports.createLRUCache=createLRUCache;exports.isDefinitelyExternal=isDefinitelyExternal;exports.createFileSystemCache=createFileSystemCache;exports.clearCache=clearCache;exports.invalidateSCCCache=invalidateSCCCache;exports.getFileHash=getFileHash;exports.isCacheValid=isCacheValid;exports.fileExists=fileExists;exports.patternToRegexWithCache=patternToRegexWithCache;exports.shouldIgnoreFileWithCache=shouldIgnoreFileWithCache;exports.resolveImportPath=resolveImportPath;exports.getFileImports=getFileImports;exports.hasOnlyTypeImports=hasOnlyTypeImports;exports.computeSCCsFromFile=computeSCCsFromFile;exports.isFileInCycle=isFileInCycle;exports.findShortestCyclePath=findShortestCyclePath;exports.getCycleForFile=getCycleForFile;exports.detectCycleFromImport=detectCycleFromImport;exports.findAllCircularDependencies=findAllCircularDependencies;exports.getMinimalCycle=getMinimalCycle;exports.getCycleHash=getCycleHash;exports.saveCacheToDisk=saveCacheToDisk;exports.loadCacheFromDisk=loadCacheFromDisk;exports.getFilesNeedingReanalysis=getFilesNeedingReanalysis;exports.isIncrementalAvailable=isIncrementalAvailable;const resolver_1=require("./resolver");const node_fs_1=require("node:fs");const fs_1=require("../node/fs");const path_1=require("../node/path");const LRU_MAX_SIZE=5e4;const EXTERNAL_MODULE_PATTERNS=[/^node:/,/^[a-z@][^/]*$/,/node_modules/];const KNOWN_EXTERNAL_PACKAGES=new Set(["react","react-dom","vue","angular","svelte","lodash","underscore","ramda","rxjs","express","koa","fastify","hapi","axios","fetch","node-fetch","got","fs","path","url","http","https","crypto","util","os","child_process","typescript","eslint","prettier","jest","vitest","mocha","webpack","rollup","vite","esbuild","parcel"]);const IMPORT_REGEX=/import\s+(?:(?:[\w*{}\s,]|'[^'\n]*'|"[^"\n]*")+\s+from\s+)?['"]([^'"]+)['"]/g;const DYNAMIC_IMPORT_REGEX=/import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;const TYPE_IMPORT_REGEX=/import\s+type\s/;const EXPORT_FROM_REGEX=/export\s+\{[\s\S]*?\}\s+from\s+['"]([^'"]+)['"]/g;const BRACED_CLAUSE_ONLY=/^import\s+\{([^}]*)\}\s+from\s+['"]/;const INLINE_TYPE_BINDING=/^type\s+(?!as(?:\s|$))/;function importsOnlyInlineTypes(statement){const clause=BRACED_CLAUSE_ONLY.exec(statement);if(!clause)return false;const bindings=clause[1].split(",").map(binding=>binding.trim()).filter(Boolean);if(!bindings.length)return false;return bindings.every(binding=>INLINE_TYPE_BINDING.test(binding))}const DEFAULT_EXTENSIONS=[".ts",".tsx",".js",".jsx"];class LRUCache{cache=new Map;maxSize;constructor(maxSize=LRU_MAX_SIZE){this.maxSize=maxSize}get(key){const value=this.cache.get(key);if(value!==void 0){this.cache.delete(key);this.cache.set(key,value)}return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.maxSize){const firstKey=this.cache.keys().next().value;if(firstKey!==void 0){this.cache.delete(firstKey)}}this.cache.set(key,value)}has(key){return this.cache.has(key)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}get size(){return this.cache.size}}function createLRUCache(maxSize=LRU_MAX_SIZE){return new LRUCache(maxSize)}function isDefinitelyExternal(importPath){const packageName=importPath.split("/")[0].replace(/^@[^/]+\//,"");if(KNOWN_EXTERNAL_PACKAGES.has(packageName)){return true}return EXTERNAL_MODULE_PATTERNS.some(pattern=>pattern.test(importPath))}function createFileSystemCache(){return{dependencies:new Map,fileExists:new Map,fileHashes:new Map,compiledPatterns:(0,path_1.createPatternCache)(),reportedCycles:new Set,sccIndex:new Map,sccs:[],sccComputed:false,graphHash:"",resolvedPaths:new Map,nonCyclicFiles:new Set,pendingCycleReports:new Map}}function clearCache(cache){cache.dependencies.clear();cache.fileExists.clear();cache.fileHashes.clear();cache.compiledPatterns.clear();cache.reportedCycles.clear();cache.sccIndex.clear();cache.sccs=[];cache.sccComputed=false;cache.graphHash="";cache.resolvedPaths=new Map;cache.nonCyclicFiles.clear();cache.pendingCycleReports.clear()}function invalidateSCCCache(cache){cache.sccIndex.clear();cache.sccs=[];cache.sccComputed=false;cache.nonCyclicFiles.clear()}function getFileHash(filePath){const stats=(0,fs_1.statSync)(filePath);if(!stats){return null}return`${stats.mtimeMs}-${stats.size}`}function isCacheValid(filePath,cache){const cachedHash=cache.fileHashes.get(filePath);if(!cachedHash)return false;const currentHash=getFileHash(filePath);return cachedHash===currentHash}function fileExists(filePath,cache){const cached=cache.fileExists.get(filePath);if(cached!==void 0){return cached}const exists=(0,fs_1.fileExistsSync)(filePath);cache.fileExists.set(filePath,exists);return exists}function patternToRegexWithCache(pattern,cache){return(0,path_1.patternToRegex)(pattern,cache.compiledPatterns)}function shouldIgnoreFileWithCache(file,patterns,cache){return(0,path_1.shouldIgnoreFile)(file,patterns,cache.compiledPatterns)}function resolveImportPath(importPath,options){const fromFile=options.fromFile;const extensions=options.extensions||DEFAULT_EXTENSIONS;const cache=options.cache;const resolverSettings=options.resolverSettings;if(isDefinitelyExternal(importPath)){if(!importPath.startsWith("@")){return null}}const isRelative=importPath.startsWith(".");if(!isRelative){const globalCached=cache.resolvedPaths.get(importPath);if(globalCached!==void 0){return globalCached}}const cacheKey=isRelative?`${fromFile}::${importPath}`:importPath;const cached=cache.resolvedPaths.get(cacheKey);if(cached!==void 0){return cached}let result=(0,resolver_1.resolveModule)(importPath,fromFile,{extensions,mainFields:["module","main"],resolverSettings});if(result&&!isRelative&&result.includes("node_modules")){try{const realPath=(0,node_fs_1.realpathSync)(result);if(realPath.includes("node_modules")){cache.resolvedPaths.set(cacheKey,null);return null}result=realPath}catch{cache.resolvedPaths.set(cacheKey,null);return null}}if(!result&&isRelative){result=(0,path_1.resolvePath)((0,path_1.getDirname)(fromFile),importPath)}cache.resolvedPaths.set(cacheKey,result);return result}function getFileImports(file,options){const{workspaceRoot,barrelExports,cache,resolverSettings}=options;const cached=cache.dependencies.get(file);if(cached){return cached}const imports=[];try{if(!fileExists(file,cache)){return imports}const content=(0,fs_1.readFileSync)(file,"utf-8");if(content===null){return imports}const resolveOpts={fromFile:file,workspaceRoot,barrelExports,cache,extensions:DEFAULT_EXTENSIONS,resolverSettings};IMPORT_REGEX.lastIndex=0;DYNAMIC_IMPORT_REGEX.lastIndex=0;EXPORT_FROM_REGEX.lastIndex=0;let match;const seen=new Map;const pushImport=(importPath,dynamic=false,typeOnly=false,inlineTypeOnly=false)=>{const resolved=resolveImportPath(importPath,resolveOpts);if(!resolved||!fileExists(resolved,cache))return;const existing=seen.get(resolved);if(existing){if(dynamic)return;if(!typeOnly&&!inlineTypeOnly){delete existing.typeOnly;delete existing.inlineTypeOnly}else if(inlineTypeOnly&&existing.typeOnly){delete existing.typeOnly;existing.inlineTypeOnly=true}return}const info={path:resolved,source:importPath};if(dynamic)info.dynamic=true;if(typeOnly)info.typeOnly=true;if(inlineTypeOnly)info.inlineTypeOnly=true;seen.set(resolved,info);imports.push(info)};while((match=IMPORT_REGEX.exec(content))!==null){const isTypeImport=/^import\s+type[\s{]/.test(match[0]);pushImport(match[1],false,isTypeImport,!isTypeImport&&importsOnlyInlineTypes(match[0]))}while((match=EXPORT_FROM_REGEX.exec(content))!==null)pushImport(match[1]);while((match=DYNAMIC_IMPORT_REGEX.exec(content))!==null)pushImport(match[1],true);const hash=getFileHash(file);if(hash){const oldHash=cache.fileHashes.get(file);if(oldHash!==hash){invalidateSCCCache(cache)}cache.fileHashes.set(file,hash)}}catch{}cache.dependencies.set(file,imports);return imports}function hasOnlyTypeImports(cycle,cache){for(const file of cycle){if(!fileExists(file,cache))continue;const content=(0,fs_1.readFileSync)(file,"utf-8");if(content===null)return false;const hasRuntimeImport=!TYPE_IMPORT_REGEX.test(content)&&IMPORT_REGEX.test(content);IMPORT_REGEX.lastIndex=0;if(hasRuntimeImport){return false}}return true}function computeSCCsFromFile(startFile,options){try{startFile=(0,node_fs_1.realpathSync)(startFile)}catch{}const{workspaceRoot,barrelExports,cache,resolverSettings}=options;if(cache.sccComputed&&cache.sccs.length>0&&cache.sccIndex.has(startFile)){return cache.sccs}const state={index:0,stack:[],onStack:new Set,indices:new Map,lowlinks:new Map,sccs:[]};const visited=new Set;const filesToProcess=[startFile];while(filesToProcess.length>0){const file=filesToProcess.pop();if(visited.has(file))continue;visited.add(file);const imports=getFileImports(file,{workspaceRoot,barrelExports,cache,resolverSettings});for(const imp of imports){if(!imp.dynamic&&!isErasedEdge(imp,options)&&!visited.has(imp.path)){filesToProcess.push(imp.path)}}}for(const file of visited){if(!state.indices.has(file)){tarjanStrongConnect(file,state,options,0)}}const newResults=state.sccs.map(files=>({files,hasCycle:files.length>1}));const offset=cache.sccs.length;cache.sccs.push(...newResults);cache.sccComputed=true;for(let i=0;i<newResults.length;i++){for(const file of newResults[i].files){if(!cache.sccIndex.has(file)){cache.sccIndex.set(file,offset+i)}}}for(const result of newResults){if(result.hasCycle){for(const file of result.files){cache.nonCyclicFiles.delete(file)}}else{for(const file of result.files){cache.nonCyclicFiles.add(file)}}}return cache.sccs}function tarjanStrongConnect(file,state,options,depth){const{maxDepth,workspaceRoot,barrelExports,cache,resolverSettings}=options;if(depth>maxDepth){return}const enter=(node,nodeDepth)=>{state.indices.set(node,state.index);state.lowlinks.set(node,state.index);state.index++;state.stack.push(node);state.onStack.add(node);const imports=getFileImports(node,{workspaceRoot,barrelExports,cache,resolverSettings});const successors=[];for(const imp of imports){if(imp.dynamic||isErasedEdge(imp,options))continue;successors.push(imp.path)}return{file:node,depth:nodeDepth,successors,next:0}};const relax=(node,candidate)=>{state.lowlinks.set(node,Math.min(state.lowlinks.get(node),candidate))};const frames=[enter(file,depth)];while(frames.length>0){const frame=frames[frames.length-1];if(frame.next<frame.successors.length){const successor=frame.successors[frame.next++];if(!state.indices.has(successor)){if(frame.depth+1>maxDepth){relax(frame.file,0);continue}frames.push(enter(successor,frame.depth+1))}else if(state.onStack.has(successor)){relax(frame.file,state.indices.get(successor))}continue}frames.pop();const lowlink=state.lowlinks.get(frame.file);const index=state.indices.get(frame.file);if(lowlink===index){const scc=[];let w;do{w=state.stack.pop();state.onStack.delete(w);scc.push(w)}while(w!==frame.file);state.sccs.push(scc)}const parent=frames[frames.length-1];if(parent){relax(parent.file,state.lowlinks.get(frame.file))}}}function isFileInCycle(file,cache){const sccIndex=cache.sccIndex.get(file);if(sccIndex===void 0)return false;const scc=cache.sccs[sccIndex];return scc&&scc.hasCycle}function findShortestCyclePath(sourceFile,targetFile,options){const{workspaceRoot,barrelExports,cache,resolverSettings}=options;const srcSCC=cache.sccIndex.get(sourceFile);if(srcSCC===void 0)return null;const queue=[[targetFile]];const visited=new Set([targetFile]);while(queue.length>0){const path=queue.shift();const current=path[path.length-1];const imports=getFileImports(current,{workspaceRoot,barrelExports,cache,resolverSettings});for(const imp of imports){if(imp.dynamic||isErasedEdge(imp,options))continue;if(imp.path===sourceFile){return[...path,sourceFile]}if(visited.has(imp.path))continue;if(cache.sccIndex.get(imp.path)!==srcSCC)continue;visited.add(imp.path);queue.push([...path,imp.path])}}return null}function getCycleForFile(file,cache){const sccIndex=cache.sccIndex.get(file);if(sccIndex===void 0)return null;const scc=cache.sccs[sccIndex];if(!scc||!scc.hasCycle)return null;return scc.files}function isErasedEdge(imp,options){if(imp.typeOnly)return true;return Boolean(imp.inlineTypeOnly)&&!options.verbatimModuleSyntax}function detectCycleFromImport(sourceFile,targetFile,options){try{sourceFile=(0,node_fs_1.realpathSync)(sourceFile)}catch{}try{targetFile=(0,node_fs_1.realpathSync)(targetFile)}catch{}const{maxDepth,reportAllCycles,workspaceRoot,barrelExports,cache,resolverSettings}=options;if(cache.nonCyclicFiles.has(targetFile)){return[]}const allCycles=[];const pathStack=[sourceFile];let depthLimitHit=false;function dfs(file,depth,visited2){if(file===sourceFile){allCycles.push([...pathStack,file]);return}if(depth>=maxDepth){depthLimitHit=true;return}if(visited2.has(file))return;if(cache.nonCyclicFiles.has(file))return;visited2.add(file);pathStack.push(file);const imports=getFileImports(file,{workspaceRoot,barrelExports,cache,resolverSettings});for(const imp of imports){if(imp.dynamic)continue;if(!reportAllCycles&&allCycles.length>0)break;dfs(imp.path,depth+1,visited2)}pathStack.pop()}const visited=new Set;dfs(targetFile,1,visited);if(allCycles.length===0&&!depthLimitHit){cache.nonCyclicFiles.add(targetFile)}return allCycles}function findAllCircularDependencies(file,options,currentPath=[],depth=0,visited=new Set){const{maxDepth,reportAllCycles,workspaceRoot,barrelExports,cache,resolverSettings}=options;if(depth===0){try{file=(0,node_fs_1.realpathSync)(file)}catch{}}if(cache.nonCyclicFiles.has(file)){return[]}if(depth===0){computeSCCsFromFile(file,{maxDepth,workspaceRoot,barrelExports,cache,resolverSettings});if(!isFileInCycle(file,cache)){cache.nonCyclicFiles.add(file);return[]}}if(depth>maxDepth){return[]}if(currentPath.includes(file)){return[[...currentPath,file]]}if(visited.has(file)){return[]}visited.add(file);const imports=getFileImports(file,{workspaceRoot,barrelExports,cache,resolverSettings});const newPath=[...currentPath,file];const allCycles=[];for(const imp of imports){if(imp.dynamic){continue}if(!reportAllCycles&&allCycles.length>0){break}const cycles=findAllCircularDependencies(imp.path,options,newPath,depth+1,visited);allCycles.push(...cycles)}if(depth===0&&allCycles.length===0){cache.nonCyclicFiles.add(file)}return allCycles}function getMinimalCycle(cycle){if(cycle.length<2)return cycle;const seen=new Map;for(let i=0;i<cycle.length;i++){const file=cycle[i];if(seen.has(file)){const cycleStart=seen?.get?.(file);return cycle.slice(cycleStart,i+1)}seen.set(file,i)}return cycle}function getCycleHash(cycle){const minimalCycle=getMinimalCycle(cycle);const minIndex=minimalCycle.indexOf(minimalCycle.reduce((min,curr)=>curr<min?curr:min,minimalCycle[0]));const normalized=[...minimalCycle.slice(minIndex),...minimalCycle.slice(0,minIndex)];return normalized.join("->")}const CACHE_VERSION=1;const DEFAULT_CACHE_FILE="node_modules/.cache/forge-eslint/cycles.json";const DEFAULT_MAX_CACHE_AGE=24*60*60*1e3;function saveCacheToDisk(cache,options,workspaceRoot){if(!options.enabled)return;const cacheFile=(0,path_1.resolvePath)(workspaceRoot,options.cacheFile||DEFAULT_CACHE_FILE);const data={version:CACHE_VERSION,createdAt:Date.now(),fileHashes:Object.fromEntries(cache.fileHashes),sccs:cache.sccs,sccIndex:Object.fromEntries(cache.sccIndex),nonCyclicFiles:Array.from(cache.nonCyclicFiles),graphHash:cache.graphHash};const cacheDir=(0,path_1.getDirname)(cacheFile);if(!(0,fs_1.fileExistsSync)(cacheDir)){(0,fs_1.mkdirSync)(cacheDir,{recursive:true})}(0,fs_1.writeFileSync)(cacheFile,JSON.stringify(data),"utf-8")}function loadCacheFromDisk(cache,options,workspaceRoot){if(!options.enabled)return false;const cacheFile=(0,path_1.resolvePath)(workspaceRoot,options.cacheFile||DEFAULT_CACHE_FILE);if(!(0,fs_1.fileExistsSync)(cacheFile)){return false}const content=(0,fs_1.readFileSync)(cacheFile,"utf-8");if(content===null){return false}try{const data=JSON.parse(content);if(data.version!==CACHE_VERSION){return false}const maxAge=options.maxCacheAge??DEFAULT_MAX_CACHE_AGE;if(Date.now()-data.createdAt>maxAge){return false}cache.fileHashes=new Map(Object.entries(data.fileHashes));cache.sccs=data.sccs;cache.sccIndex=new Map(Object.entries(data.sccIndex).map(([k,v])=>[k,v]));cache.nonCyclicFiles=new Set(data.nonCyclicFiles);cache.graphHash=data.graphHash;cache.sccComputed=true;return true}catch{return false}}function getFilesNeedingReanalysis(files,cache,options){if(!options.enabled||!cache.sccComputed){return files}const changedFiles=[];for(const file of files){const cachedHash=cache.fileHashes.get(file);const currentHash=getFileHash(file);if(!cachedHash||cachedHash!==currentHash){changedFiles.push(file)}}if(changedFiles.length>0){const affectedSCCIndices=new Set;for(const file of changedFiles){const sccIndex=cache.sccIndex.get(file);if(sccIndex!==void 0){affectedSCCIndices.add(sccIndex)}}const affectedFiles=new Set(changedFiles);for(const scc of cache.sccs){const sccIndex=cache.sccIndex.get(scc.files[0]);if(sccIndex!==void 0&&affectedSCCIndices.has(sccIndex)){for(const file of scc.files){affectedFiles.add(file);cache.nonCyclicFiles.delete(file)}}}for(const[file,imports]of cache.dependencies){for(const imp of imports){if(changedFiles.includes(imp.path)){affectedFiles.add(file);cache.nonCyclicFiles.delete(file);break}}}return Array.from(affectedFiles)}return[]}function isIncrementalAvailable(cache,options){return Boolean(options?.enabled&&cache.sccComputed&&cache.sccs.length>0)}exports.PERFORMANCE_DOCS={algorithm:"Tarjan SCC + DFS hybrid",timeComplexity:"O(V + E)",spaceComplexity:"O(V)",guaranteedComplete:true};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.docsUrlFor=exports.ESLintUtils=exports.createRule=void 0;exports.applyDefault=applyDefault;exports.isTestFilePath=isTestFilePath;exports.RuleCreator=RuleCreator;exports.createRuleCreator=createRuleCreator;exports.withCanonicalDocsUrls=withCanonicalDocsUrls;const generated_file_1=require("./generated-file");const minified_file_1=require("./minified-file");function isObjectNotArray(obj){return typeof obj==="object"&&obj!=null&&!Array.isArray(obj)}function deepMerge(first,second){const keys=new Set([...Object.keys(first),...Object.keys(second)]);return Object.fromEntries([...keys].map(key=>{const firstHasKey=key in first;const secondHasKey=key in second;const firstValue=first[key];const secondValue=second[key];if(firstHasKey&&secondHasKey){return[key,isObjectNotArray(firstValue)&&isObjectNotArray(secondValue)?deepMerge(firstValue,secondValue):secondValue]}return[key,firstHasKey?firstValue:secondValue]}))}function applyDefault(defaultOptions,userOptions){const options=structuredClone(defaultOptions);if(userOptions==null){return options}options.forEach((opt,i)=>{if(userOptions[i]!==void 0){const userOpt=userOptions[i];options[i]=isObjectNotArray(userOpt)&&isObjectNotArray(opt)?deepMerge(opt,userOpt):userOpt}});return options}const TEST_DIR_SEGMENTS=new Set(["__tests__","__test__","test","tests","spec","specs","e2e","__mocks__","mocks","fixtures","__fixtures__"]);const TEST_BASENAME=/\.(test|spec|fixture|mock|e2e-spec|stories|story)\.[cm]?[jt]sx?$/;const TEST_DIR_SUFFIX=/[-_](tests?|specs?)$/;const TEST_SUPPORT_DIR=/^test(?:[-_]?(?:utils?|helpers?|support|data|doubles?|factories|fixtures?|setup))$|^testing$/i;function isTestFilePath(filename){if(!filename||filename==="<input>"||filename==="<text>")return false;const slash=Math.max(filename.lastIndexOf("/"),filename.lastIndexOf("\\"));if(TEST_BASENAME.test(filename.slice(slash+1)))return true;if(slash<0)return false;return filename.slice(0,slash).split(/[\\/]/).some(segment=>TEST_DIR_SEGMENTS.has(segment)||TEST_DIR_SUFFIX.test(segment)||TEST_SUPPORT_DIR.test(segment))}function createRuleInternal({create,defaultOptions,meta,name,skipTestFiles,skipGeneratedFiles,skipMinifiedFiles}){const resolvedDefaultOptions=defaultOptions??[];return{create(context){if(skipTestFiles&&isTestFilePath(context.filename))return{};if(skipGeneratedFiles&&(0,generated_file_1.isGeneratedFile)(context.sourceCode))return{};if(skipMinifiedFiles&&(0,minified_file_1.isMinifiedFile)(context.sourceCode))return{};return create(context,applyDefault(resolvedDefaultOptions,context.options))},defaultOptions:resolvedDefaultOptions,meta,name}}function RuleCreator(urlCreator){return({meta,name,...rule})=>createRuleInternal({meta:{...meta,docs:{...meta.docs,url:urlCreator(name)}},name,...rule})}RuleCreator.withoutDocs=args=>createRuleInternal(args);function createRuleCreator(urlCreator){return RuleCreator(urlCreator)}exports.createRule=RuleCreator(()=>void 0);exports.ESLintUtils={RuleCreator,applyDefault};const PLUGIN_DOCS_CATEGORY={"plugin-anthropic-security":"security","plugin-gemini-security":"security","plugin-mcp-sdk-security":"security","plugin-supabase-security":"security","plugin-openai-security":"security","plugin-browser-security":"security","plugin-drizzle-security":"security","plugin-express-security":"security","plugin-jwt-security":"security","plugin-knex-security":"security","plugin-lambda-security":"security","plugin-mongodb-security":"security","plugin-mysql-security":"security","plugin-nestjs-security":"security","plugin-node-security":"security","plugin-postgresql-security":"security","plugin-prisma-security":"security","plugin-secure-coding":"security","plugin-sequelize-security":"security","plugin-sqlite-security":"security","plugin-typeorm-security":"security","plugin-vercel-ai-security":"security","plugin-conventions":"quality","plugin-import-next":"quality","plugin-maintainability":"quality","plugin-modernization":"quality","plugin-modularity":"quality","plugin-operability":"quality","plugin-react-a11y":"quality","plugin-react-features":"quality","plugin-reliability":"quality"};const docsUrlFor=(pluginSlug,ruleName)=>{const category=PLUGIN_DOCS_CATEGORY[pluginSlug];return category?`https://eslint.interlace.tools/docs/${category}/${pluginSlug}/rules/${ruleName}`:null};exports.docsUrlFor=docsUrlFor;function withCanonicalDocsUrls(pluginSlug,rules){if(!PLUGIN_DOCS_CATEGORY[pluginSlug]){console.warn(`[eslint-devkit] withCanonicalDocsUrls('${pluginSlug}'): slug is not registered in PLUGIN_DOCS_CATEGORY, so no rule in this plugin gets a meta.docs.url. Register it in packages/eslint-devkit/src/rule-creation/rule-creator.ts.`)}for(const name of Object.keys(rules)){const descriptor=Object.getOwnPropertyDescriptor(rules,name);const{get}=descriptor;if(get){Object.defineProperty(rules,name,{...descriptor,get(){const rule=get.call(this);stampDocsUrl(pluginSlug,name,rule);return rule}});continue}stampDocsUrl(pluginSlug,name,descriptor.value)}return rules}function stampDocsUrl(pluginSlug,name,rule){const docs=rule?.meta?.docs;if(!docs)return;const url=(0,exports.docsUrlFor)(pluginSlug,name);if(url)docs.url=url}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.docsUrlFor=exports.ESLintUtils=exports.createRule=void 0;exports.applyDefault=applyDefault;exports.isTestFilePath=isTestFilePath;exports.RuleCreator=RuleCreator;exports.createRuleCreator=createRuleCreator;exports.withCanonicalDocsUrls=withCanonicalDocsUrls;const generated_file_1=require("./generated-file");const minified_file_1=require("./minified-file");function isObjectNotArray(obj){return typeof obj==="object"&&obj!=null&&!Array.isArray(obj)}function deepMerge(first,second){const keys=new Set([...Object.keys(first),...Object.keys(second)]);return Object.fromEntries([...keys].map(key=>{const firstHasKey=key in first;const secondHasKey=key in second;const firstValue=first[key];const secondValue=second[key];if(firstHasKey&&secondHasKey){return[key,isObjectNotArray(firstValue)&&isObjectNotArray(secondValue)?deepMerge(firstValue,secondValue):secondValue]}return[key,firstHasKey?firstValue:secondValue]}))}function applyDefault(defaultOptions,userOptions){const options=structuredClone(defaultOptions);if(userOptions==null){return options}options.forEach((opt,i)=>{if(userOptions[i]!==void 0){const userOpt=userOptions[i];options[i]=isObjectNotArray(userOpt)&&isObjectNotArray(opt)?deepMerge(opt,userOpt):userOpt}});return options}const TEST_DIR_SEGMENTS=new Set(["__tests__","__test__","test","tests","spec","specs","e2e","__mocks__","mocks","fixtures","__fixtures__"]);const TEST_BASENAME=/\.(test|spec|fixture|mock|e2e-spec|stories|story)\.[cm]?[jt]sx?$/;const TEST_DIR_SUFFIX=/[-_](tests?|specs?)$/;const TEST_SUPPORT_DIR=/^test(?:[-_]?(?:utils?|helpers?|support|data|doubles?|factories|fixtures?|setup))$|^testing$/i;function isTestFilePath(filename){if(!filename||filename==="<input>"||filename==="<text>")return false;const slash=Math.max(filename.lastIndexOf("/"),filename.lastIndexOf("\\"));if(TEST_BASENAME.test(filename.slice(slash+1)))return true;if(slash<0)return false;return filename.slice(0,slash).split(/[\\/]/).some(segment=>TEST_DIR_SEGMENTS.has(segment)||TEST_DIR_SUFFIX.test(segment)||TEST_SUPPORT_DIR.test(segment))}function createRuleInternal({create,defaultOptions,meta,name,skipTestFiles,skipGeneratedFiles,skipMinifiedFiles}){const resolvedDefaultOptions=defaultOptions??[];return{create(context){if(skipTestFiles&&isTestFilePath(context.filename))return{};if(skipGeneratedFiles&&(0,generated_file_1.isGeneratedFile)(context.sourceCode))return{};if(skipMinifiedFiles&&(0,minified_file_1.isMinifiedFile)(context.sourceCode))return{};return create(context,applyDefault(resolvedDefaultOptions,context.options))},defaultOptions:resolvedDefaultOptions,meta,name}}function RuleCreator(urlCreator){return({meta,name,...rule})=>createRuleInternal({meta:{...meta,docs:{...meta.docs,url:urlCreator(name)}},name,...rule})}RuleCreator.withoutDocs=args=>createRuleInternal(args);function createRuleCreator(urlCreator){return RuleCreator(urlCreator)}exports.createRule=RuleCreator(()=>void 0);exports.ESLintUtils={RuleCreator,applyDefault};const PLUGIN_DOCS_CATEGORY={"plugin-anthropic-security":"security","plugin-gemini-security":"security","plugin-mcp-sdk-security":"security","plugin-supabase-security":"security","plugin-openai-security":"security","plugin-browser-security":"security","plugin-drizzle-security":"security","plugin-express-security":"security","plugin-jwt-security":"security","plugin-knex-security":"security","plugin-lambda-security":"security","plugin-mongodb-security":"security","plugin-mysql-security":"security","plugin-nestjs-security":"security","plugin-node-security":"security","plugin-postgresql-security":"security","plugin-prisma-security":"security","plugin-secure-coding":"security","plugin-sequelize-security":"security","plugin-sqlite-security":"security","plugin-typeorm-security":"security","plugin-vercel-ai-security":"security","plugin-cli-floor":"quality","plugin-conventions":"quality","plugin-import-next":"quality","plugin-maintainability":"quality","plugin-modernization":"quality","plugin-modularity":"quality","plugin-operability":"quality","plugin-react-a11y":"quality","plugin-react-features":"quality","plugin-reliability":"quality"};const docsUrlFor=(pluginSlug,ruleName)=>{const category=PLUGIN_DOCS_CATEGORY[pluginSlug];return category?`https://eslint.interlace.tools/docs/${category}/${pluginSlug}/rules/${ruleName}`:null};exports.docsUrlFor=docsUrlFor;function withCanonicalDocsUrls(pluginSlug,rules){if(!PLUGIN_DOCS_CATEGORY[pluginSlug]){console.warn(`[eslint-devkit] withCanonicalDocsUrls('${pluginSlug}'): slug is not registered in PLUGIN_DOCS_CATEGORY, so no rule in this plugin gets a meta.docs.url. Register it in packages/eslint-devkit/src/rule-creation/rule-creator.ts.`)}for(const name of Object.keys(rules)){const descriptor=Object.getOwnPropertyDescriptor(rules,name);const{get}=descriptor;if(get){Object.defineProperty(rules,name,{...descriptor,get(){const rule=get.call(this);stampDocsUrl(pluginSlug,name,rule);return rule}});continue}stampDocsUrl(pluginSlug,name,descriptor.value)}return rules}function stampDocsUrl(pluginSlug,name,rule){const docs=rule?.meta?.docs;if(!docs)return;const url=(0,exports.docsUrlFor)(pluginSlug,name);if(url)docs.url=url}