Spaces:
Paused
Paused
File size: 2,030 Bytes
34367da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | import 'dotenv/config';
import neo4j from 'neo4j-driver';
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function findZombies() {
const uri = process.env.NEO4J_URI;
const user = process.env.NEO4J_USER;
const password = process.env.NEO4J_PASSWORD;
if (!uri || !user || !password) {
console.error('❌ FEJL: Mangler Neo4j credentials');
process.exit(1);
}
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session();
try {
const query = `
MATCH (f:File)
WHERE f.path ENDS WITH '.ts'
AND NOT ()-[:DEPENDS_ON]->(f)
AND NOT f.name ENDS WITH 'index.ts'
AND NOT f.name ENDS WITH 'server.ts'
AND NOT f.name ENDS WITH '.d.ts'
AND NOT f.name ENDS WITH '.test.ts'
AND NOT f.name ENDS WITH '.spec.ts'
AND NOT f.path CONTAINS 'node_modules'
RETURN f.path as path, f.name as name
ORDER BY f.path
`;
const result = await session.run(query);
const zombies = result.records.map(r => r.get('path'));
console.log(`🧟 Found ${zombies.length} potential zombies.`);
const reportPath = path.resolve(__dirname, '../../../../docs/ZOMBIE_CODE_REPORT.md');
const reportContent = `# 🧟 Zombie Code Report
Generated: ${new Date().toISOString()}
Total: ${zombies.length}
## Potential Dead Code
${zombies.map(z => `- ${z}`).join('\n')}
`;
fs.writeFileSync(reportPath, reportContent);
console.log(`📝 Report saved to: ${reportPath}`);
// Output top 10 for CLI
zombies.slice(0, 10).forEach(z => console.log(`- ${z}`));
if (zombies.length > 10) console.log(`... and ${zombies.length - 10} more.`);
} catch (error) {
console.error('Error:', error);
} finally {
await session.close();
await driver.close();
}
}
findZombies();
|