z-diff-cleaner
v0.0.4
Published
Remove formatting-only changes from git diffs before sending them to LLMs for code review.
Readme
z-diff-cleaner
Remove formatting-only changes from git diffs before sending them to LLMs for code review.
Features
- Detect and remove whitespace-only changes
- Detect comment-only changes
- Detect quote style changes (safe cases only)
- Detect trailing comma changes (non-JSON)
- Detect optional semicolon changes with ASI safety checks
- Detect import reordering when the import set is unchanged
- Detect line-wrapping-only changes when tokens are unchanged
Install
npm i z-diff-cleanerUsage
import { DiffCleaner } from 'z-diff-cleaner';
const cleaner = new DiffCleaner();
const diffText = `diff --git a/app.ts b/app.ts
@@ -1,2 +1,2 @@
-const a = 1;
+const a = 1;`;
const result = cleaner.clean(diffText, {
ignoreWhitespace: true,
ignoreCommentChanges: true,
ignoreQuoteChanges: true,
ignoreTrailingCommas: true,
ignoreOptionalSemicolons: true,
ignoreImportReordering: true,
ignoreLineWrappingChanges: true,
});
const cleanedDiff = cleaner.reconstruct(result.cleaned);
console.log(cleanedDiff);Configuration
- ignoreWhitespace: Remove whitespace-only changes
- ignoreCommentChanges: Remove comment-only changes
- ignoreImportReordering: Remove import reordering when the set is unchanged
- ignoreLineBreaks: Remove line break changes
- ignoreLineWrappingChanges: Remove line-wrapping-only changes when tokens are unchanged
- ignoreQuoteChanges: Remove quote style changes when safe
- ignoreTrailingCommas: Remove trailing comma changes in non-JSON
- ignoreOptionalSemicolons: Remove optional semicolons when safe
- language: Language hint for future optimizations
Output
The clean API returns:
- original: Parsed diff files
- cleaned: Filtered diff files
- formatChanges: Detected formatting changes
- statistics: Summary of files and lines removed
Development
npm test
npm run lint
npm run typecheck