@interlace/eslint-devkit 1.17.2 → 1.17.4

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
@@ -1,9 +1,9 @@
1
1
  <p align="center">
2
- <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-devkit" target="blank"><img src="https://eslint.interlace.tools/logos/interlace.svg" alt="Interlace" height="90" /></a>
2
+ <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-devkit" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="90" /></picture></a>
3
3
  &nbsp;&nbsp;
4
- <a href="https://oxc.rs" target="_blank"><img src="https://eslint.interlace.tools/logos/oxlint.svg" alt="oxlint" height="90" /></a>
4
+ <a href="https://oxc.rs" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/oxlint-dark.svg"><img src="https://eslint.interlace.tools/logos/oxlint-light.svg" alt="oxlint" height="90" /></picture></a>
5
5
  &nbsp;&nbsp;
6
- <a href="https://eslint.org" target="_blank"><img src="https://eslint.interlace.tools/logos/eslint.svg" alt="ESLint" height="90" /></a>
6
+ <a href="https://eslint.org" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/eslint-dark.svg"><img src="https://eslint.interlace.tools/logos/eslint-light.svg" alt="ESLint" height="90" /></picture></a>
7
7
  </p>
8
8
 
9
9
  # @interlace/eslint-devkit
@@ -553,5 +553,5 @@ See [CHANGELOG.md](./CHANGELOG.md) for a list of changes and version history.
553
553
  </p>
554
554
 
555
555
  <p align="center">
556
- <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-devkit" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
556
+ <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-devkit" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="70" /></picture></a>
557
557
  </p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interlace/eslint-devkit",
3
- "version": "1.17.2",
3
+ "version": "1.17.4",
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",
@@ -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,]+\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 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};
@@ -7,7 +7,7 @@ import type { TSESLint } from '@typescript-eslint/utils';
7
7
  /**
8
8
  * Documentation URL resolver function type
9
9
  */
10
- type DocsUrl = (ruleName: string) => string;
10
+ type DocsUrl = (ruleName: string) => string | undefined;
11
11
  /**
12
12
  * Pure function - doesn't mutate either parameter!
13
13
  * Uses the default options and overrides with the options provided by the user
@@ -116,9 +116,18 @@ export declare namespace RuleCreator {
116
116
  */
117
117
  export declare function createRuleCreator<PluginDocs = unknown>(urlCreator: DocsUrl): <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<RuleWithMetaAndName<Options, MessageIds, PluginDocs>>) => RuleModuleWithName<MessageIds, Options, PluginDocs>;
118
118
  /**
119
- * Default rule creator with a generic documentation URL pattern
119
+ * Default rule creator. Mints NO documentation URL.
120
120
  *
121
- * This can be used directly if you don't need custom URL generation
121
+ * This factory cannot know which plugin a rule belongs to, so any URL it builds is a
122
+ * guess. It used to guess `packages/eslint-plugin/docs/rules/<name>.md` — a package
123
+ * that has never existed in this repo — which every plugin then had to scrub on export
124
+ * via {@link withCanonicalDocsUrls}. That worked only for slugs registered in
125
+ * {@link PLUGIN_DOCS_CATEGORY}: a rule authored before its plugin was registered kept
126
+ * the placeholder and shipped a "see docs" link that 404s in every IDE, CI report and
127
+ * SARIF file.
128
+ *
129
+ * Omitting the URL makes that gap silent-but-correct instead of silently wrong, and
130
+ * {@link withCanonicalDocsUrls} warns when a slug is missing so it gets noticed.
122
131
  */
123
132
  export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<RuleWithMetaAndName<Options, MessageIds, unknown>>) => RuleModuleWithName<MessageIds, Options, unknown>;
124
133
  /**
@@ -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(name=>`https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin/docs/rules/${name}.md`);exports.ESLintUtils={RuleCreator,applyDefault};const PLUGIN_DOCS_CATEGORY={"plugin-anthropic-security":"security","plugin-gemini-security":"security","plugin-mcp-sdk-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){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-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}