vibe-janitor
Version:
A CLI tool that cleans AI-generated JavaScript/TypeScript projects efficiently and intelligently
116 lines (115 loc) • 2.82 kB
TypeScript
/**
* Options for the cleaning process
*/
export interface CleanerOptions {
dryRun?: boolean;
removeUnused?: boolean;
deepScrub?: boolean;
verbose?: boolean;
/**
* Whether to delete unused files when found
*/
deleteUnusedFiles?: boolean;
}
/**
* Results from the cleaning process
*/
export interface CleaningResult {
unusedFiles: string[];
unusedImports: {
file: string;
imports: string[];
}[];
unusedVariables: {
file: string;
variables: string[];
}[];
unusedFunctions: {
file: string;
functions: string[];
}[];
modifiedFiles: string[];
/**
* Files that were deleted due to being unused
*/
deletedFiles: string[];
/**
* Total size of unused files in bytes
*/
unusedFilesSize: number;
}
/**
* Handles detecting and removing unused code, imports, and files
*/
export declare class Cleaner {
private project;
private targetDir;
private options;
constructor(targetDir: string, options?: CleanerOptions);
/**
* Finds the TypeScript config file for the target directory
*/
private findTsConfig;
/**
* Adds all TypeScript and JavaScript files to the project for analysis
*/
private addFilesToProject;
/**
* Finds unused imports in the codebase
*/
private findUnusedImports;
/**
* Escape special characters for use in a regular expression
*/
private escapeRegExp;
/**
* Finds unused variables in the codebase
*/
private findUnusedVariables;
/**
* Helper method to check if a node has export modifier
*/
private hasExportModifier;
/**
* Finds unused functions in the codebase
*/
private findUnusedFunctions;
/**
* Finds potentially unused files based on import references
*/
private findUnusedFiles;
/**
* Check if a file should be protected from deletion
*/
private isFileProtected;
/**
* Delete unused files from the file system
* @param unusedFiles List of file paths to delete
* @returns Array of successfully deleted file paths
*/
private deleteUnusedFiles;
/**
* Clean the project by removing unused code and files
*/
clean(): Promise<CleaningResult>;
/**
* Remove unused imports from a source file
*/
private removeUnusedImports;
/**
* Remove unused variables from a source file
*/
private removeUnusedVariables;
/**
* Remove unused functions from a source file
*/
private removeUnusedFunctions;
/**
* Calculate the size of all unused files
*/
private calculateUnusedFilesSize;
/**
* Format file size in a human-readable way
*/
private formatSize;
}