Skip to content

Commit 4144893

Browse files
author
Dev Optimizer Bot
committed
perf: Reduce Knip false positives for entry files
- Skip commonly used entry files (server.js, index.js, app.js, config.js) - Skip TypeScript declaration files (.d.ts) - Skip migration/seed files - Skip swagger/database files (commonly used but hard to detect) - Reduce unused files findings significantly
1 parent 14bb6b9 commit 4144893

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

src/analyzers/DepsAnalyzer.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,41 @@ export class DepsAnalyzer implements Analyzer {
7171
findings.push(this.createUnusedDepFinding(depName, packageJson, true, projectPath));
7272
}
7373

74-
// Process unused exports
74+
// Process unused exports (files)
7575
for (const item of knipResult.exports || []) {
7676
if (item.type === 'unused') {
77+
// Skip common false positives
78+
const filePath = item.file || '';
79+
80+
// Skip files that are likely entry points or configuration
81+
const likelyUsed = [
82+
/server\.(js|ts)$/,
83+
/app\.(js|ts)$/,
84+
/index\.(js|ts)$/,
85+
/main\.(js|ts)$/,
86+
/config\.(js|ts)$/,
87+
/\.d\.ts$/,
88+
/types\.(js|ts)$/,
89+
/swagger\.(js|ts)$/,
90+
/database\.(js|ts)$/,
91+
/migrations\//,
92+
/seeds\//,
93+
];
94+
95+
if (likelyUsed.some(pattern => pattern.test(filePath))) {
96+
continue; // Skip likely used files
97+
}
98+
99+
// Reduce severity if file might be used dynamically
100+
const dynamicUsage = [
101+
/middleware\//,
102+
/services\//,
103+
/jobs\//,
104+
/api\//,
105+
];
106+
107+
const isLikelyDynamic = dynamicUsage.some(pattern => pattern.test(filePath));
108+
77109
findings.push({
78110
id: `deps-006-${item.name}`,
79111
domain: 'deps',

0 commit comments

Comments
 (0)