Clean Diff
Compare files in VS Code ignoring whitespace, blank lines, line-break placement, case, or comments, with key-order-insensitive JSON and YAML diffs.
What It Does
- Serves normalized, read-only virtual documents via the
clean-diff: scheme and opens VS Code's native diff editor without modifying your source files.
- Remembers your chosen normalization modes per workspace and updates open diffs live (debounced) as you edit source buffers or save files. Picking no mode at all compares the raw text.
- Supports comparing any two files, two Explorer-selected files, an active file with the clipboard, or the active unsaved buffer with its saved copy on disk.
- Strips line and block comments with a language-aware lexer (see Comment Stripping). Where a file type has no known comment syntax, comments are kept and a warning is shown.
- Reads files that are not open through VS Code's own text loader, so encodings and language detection match the editor.
- Enforces a configurable file size limit (
cleanDiff.maxFileSizeMB, default 10 MB) so large binaries never stall the editor.
Features (Free vs Pro)
| Feature |
Free |
Pro |
| Collapse whitespace (trim lines, collapse runs of spaces and tabs) |
Included |
Included |
| Ignore blank lines |
Included |
Included |
| Ignore line-break placement (reflow tokens) |
Included |
Included |
| Ignore case |
Included |
Included |
| Compare With, Compare Selected (2 files), Clipboard, Active vs Saved |
Included |
Included |
| Live debounced refresh on document edits |
Included |
Included |
| Strip line and block comments (language-aware) |
Upgrade prompt |
Included |
| JSON/JSONC key-sorted canonical diff |
Upgrade prompt |
Included |
| YAML key-sorted canonical diff (documented subset) |
Upgrade prompt |
Included |
3-file compare (A <-> B and B <-> C) |
Upgrade prompt |
Included |
| Saved normalization mode presets |
Upgrade prompt |
Included |
| Copy normalized text to clipboard |
Upgrade prompt |
Included |
Whitespace Modes
- Collapse whitespace trims every line (including non-breaking spaces at the ends) and collapses runs of spaces, tabs, form feeds, and vertical tabs inside a line to one space. It does not delete whitespace between tokens (
a b still differs from ab) and does not touch non-breaking spaces inside a line.
- Ignore blank lines drops empty and whitespace-only lines.
- Ignore line-break placement splits text into tokens at whitespace and
()[]{},; so wrapping and spacing around those delimiters no longer matter.
- Ignore case lowercases everything. With a canonical JSON/YAML mode it also sorts keys case-insensitively, so key order never depends on capitalisation.
Supported languages are matched by VS Code language id first and file extension second: JavaScript, TypeScript (JSX/TSX included), C, C++, Objective-C, C#, Java, Kotlin, Scala, Swift, Dart, Go, Rust, Groovy, Solidity, Zig, Protocol Buffers, JSONC, CSS, SCSS, LESS, PHP, Python, shell, YAML, TOML, Ruby, Perl, R, Elixir, Julia, CoffeeScript, GraphQL, dotenv, Lua, SQL dialects, Haskell, PowerShell, and HTML-like markup (HTML, XML, SVG, XSL, Vue, Svelte, Astro, Handlebars). Makefile, Dockerfile, ignore files, .properties, and INI files only treat whole-line comments (#, !, ;) as comments.
The lexer understands: JavaScript and TypeScript regular expression literals (including / and /* inside character classes) and nested template literals; triple-quoted strings (Python, Kotlin, Scala, Swift, Java, Dart, Groovy, TOML, Elixir, Julia, GraphQL); string interpolation in Kotlin, Scala, Dart, Groovy, Swift, Ruby, Elixir, and C#; Rust raw and multi-line strings, lifetimes, and nested block comments; C# verbatim, interpolated, and raw strings; C++ raw strings and digit separators; Go raw strings; Lua long brackets; SQL dollar-quoted bodies (kept as opaque text), multi-line strings, and executable /*! */ comments; Haskell --> style operators and {-# #-} pragmas; PowerShell here-strings; shell, Ruby, Perl, and PHP heredocs; YAML block scalars; PHP inline HTML outside <?php ... ?>; CSS url(...) contents; XML CDATA sections.
# and ; only start a comment at the beginning of a line or after whitespace, so ${1##*/}, $#, url#fragment, and a#b are kept.
When the lexer cannot tell, it keeps text instead of removing it. Known limits:
- Markdown and files without a known comment syntax are not stripped (a warning says so).
.conf and .cfg files are only handled when VS Code classifies them as properties or ini, and then only for whole-line comments.
// directly after : is never a comment, so URLs in JSX/TSX text survive. Other JSX/TSX text containing // is lexed as code and can be misread, and a comment written as case 1:// note is kept.
- A regular expression directly after
) or ] (for example if (x) /re/.test(s)) is read as division. Regex scans are capped at 2000 characters per literal and a total budget per file, after which / is read as division.
- Ruby and Perl regular expressions and
%w[] literals, Elixir sigils, and Swift #"..."# raw strings are not recognized.
- Heredoc detection is heuristic. A false positive keeps comments in the following lines; it never deletes code.
JSON and YAML Canonical Diffs (Pro)
Both modes parse the file, sort object keys recursively (array order is preserved), and print a canonical form. If parsing fails, the diff falls back to the text-normalized form and a warning explains why.
- Numbers are printed exactly as written, so
1.10 and 1.1, 1e5 and 100000, and integers beyond 2^53 stay distinct.
- Duplicate keys are refused instead of silently keeping the last value.
- Nesting deeper than 200 levels shows "Nesting too deep for canonical mode; showing text diff". A canonical form that would exceed 64 MB (indentation grows with depth) falls back with a warning.
- When both canonical modes are selected, the VS Code language id or file extension chooses the parser (
json/jsonc or yaml/yml). For other files JSON is tried first, then YAML.
- Live refresh of a canonical diff is skipped for buffers over 2 MB and the debounce grows by 100 ms per MB (250 ms base). Large buffers refresh when saved, and a one-time notice says so. A diff whose cached text was evicted is rebuilt on the next edit or save.
Documented YAML Subset
Supported:
- Block mappings and block sequences indented with spaces, including mappings inside sequences
- Single-line flow sequences (
[a, b]) and flow mappings ({ b: 2, a: 1 })
- Plain, single-quoted, and double-quoted single-line scalars. Double-quoted escapes:
\0 \a \b \t \n \v \f \r \e \<space> \" \/ \\ \N \_ \L \P \xNN \uNNNN \UNNNNNNNN. Any other escape is an error.
- YAML 1.2 core scalars:
null/~, true/false (any of the three standard casings), and numbers (decimal, 0x, 0o, .inf, .nan), printed as written. yes, no, on, off are strings.
# comments, blank lines, and --- / ... document markers
Refused (fallback diff with a warning):
- Anchors
&, aliases *, tags !, merge keys <<, complex keys ?
- Block scalars (
|, > with any modifier) and multi-line plain or quoted scalars
- Directives such as
%YAML
- Tabs in indentation or directly after
: or -
- Inline nested sequences (
- - a), duplicate keys, plain scalars containing : or ending in :
- Plain scalars that start with an indicator character (
@, `, %, ,, ], }), quoted scalars followed by more text, multi-line flow collections, and nesting deeper than 200 levels
Commands
cleanDiff.compareWith (Clean Diff: Compare With...): Compare a file against another open or browsed file. From the Explorer with two files selected, compares those two.
cleanDiff.compareSelected (Clean Diff: Compare Selected Files): Compare 2 selected Explorer files (or 3 with Pro).
cleanDiff.compareWithClipboard (Clean Diff: Compare With Clipboard): Compare a file against current clipboard text.
cleanDiff.compareActiveWithSaved (Clean Diff: Compare Active With Saved): Compare the active editor buffer against the saved file on disk.
cleanDiff.compareThreeFiles (Clean Diff: Compare Three Files (Pro)): Open A <-> B and B <-> C normalized diffs side by side (Pro).
cleanDiff.copyNormalizedText (Clean Diff: Copy Normalized Text (Pro)): Normalize the active or selected file and copy the result to the clipboard (Pro).
cleanDiff.savePreset (Clean Diff: Save Mode Preset (Pro)): Save a named set of normalization modes in workspace state (Pro).
cleanDiff.applyPreset (Clean Diff: Apply Mode Preset (Pro)): Load a saved mode preset as the active workspace selection (Pro).
cleanDiff.deletePreset (Clean Diff: Delete Mode Preset (Pro)): Delete a saved mode preset (Pro).
clean-diff.enterLicense (Clean Diff: Enter License Key): Activate a Pro license key in VS Code SecretStorage.
File commands are hidden from the Command Palette while a clean-diff: document is the active editor.
Settings
cleanDiff.maxFileSizeMB (number, default 10): Maximum file size in MB allowed for normalization and diffing. Restricted in untrusted workspaces.
clean-diff.apiBaseUrl (string, default ""): Override the licensing API base URL (must use https://, machine-scoped).
clean-diff.webBaseUrl (string, default ""): Override the web storefront base URL (must use https://, machine-scoped).
Privacy and Data Handling
| Data |
Where |
Retention |
| Compared file contents and clipboard text |
Local memory only (read-only clean-diff: virtual documents, at most 64 MB cached) |
Until the diff is closed or evicted |
| Remembered modes and Pro presets |
VS Code workspaceState |
Workspace lifetime |
| License key, product ID, machine ID hash |
Sent to licensing API (clean-diff.apiBaseUrl) on Pro activation/refresh |
Active license lifetime |
| Telemetry |
None (collectsTelemetry: false) |
0 days |
Clean Diff collects zero telemetry and never transmits source code or file paths.
A clean-diff: document that is closed, evicted, or restored after a restart is rebuilt from the source file recorded in its address. Clipboard snapshots cannot be rebuilt and show a short notice instead.
Offline Behaviour
- All normalization modes, comment stripping, JSON/JSONC and YAML canonicalization, diff rendering, and presets run 100% offline.
- Works in untrusted workspaces (read-only virtual documents;
cleanDiff.maxFileSizeMB is restricted in untrusted workspaces).
- Paid licenses are verified offline using the bundled Ed25519 public key with a 14-day grace period.
- Performance targets: 5 MB of text modes under 1 s, JSON canonical under 1 s, YAML canonical under 1.5 s.
Pricing
Clean Diff is free for whitespace, blank line, line-break, and case normalization across 2-file, clipboard, and saved-vs-active diffs. Pro adds comment stripping, JSON/YAML key-sorted canonical diffs, 3-file compare, saved presets, and copy normalized text.
View plans and buy. After purchase, sign in to your account to copy your license key, then run Clean Diff: Enter License Key.
Support
Report issues or request help at github.com/toolsmith-labs/support. For billing or license questions, email jashambaliya05@gmail.com.
| |