Skip to content

Format only edited C++ lines while preserving surrounding layouts - #245

Draft
dayfine wants to merge 11 commits into
tooling/clang-format-configfrom
tooling/incremental-cpp-format
Draft

dayfine wants to merge 11 commits into
tooling/clang-format-configfrom
tooling/incremental-cpp-format

Conversation

@dayfine

@dayfine dayfine commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #244 (tooling/clang-format-config); this diff adds only the incremental command, its tests and instructions.

Full-file formatting still reindents existing layouts and introduces unwanted declaration-brace spaces. Add a preview-first command that accepts only same-line whitespace edits on Git-added/modified C++ lines. Keep all leading alignment and newlines, skip reflows/preprocessor/declaration lines, and verify significant Clang raw-token kind/spelling before writing. All candidates are checked before any write; staged content stays untouched and stale snapshots are refused.

Usage from the code worktree: python3 /path/to/format_changed.py --repo .; add --write to apply or --check for a non-writing check. Default scope is staged + unstaged edits against HEAD; --base uses the selected parent's merge base for a whole branch. No hooks or source-format gate are enabled. This narrow mode does not fix indentation or replace style lint.

Validation: all 35 tests pass locally, using real Uncrustify/Clang and temporary Git repositories for preview/check/write, scope/index preservation, explicit bases, unusual paths, token/literal protection and stale-source rejection. Read-only invocation against the active Arduino checkout also completed without writes. CI builds the pinned tool and passes all 35 tests. Code Health and tabs pass too. No application sources are reformatted or native app builds required.

dayfine and others added 9 commits November 7, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant