{{ message }}
feat: add --fix CLI option to auto-apply clang-format fixes#202
Draft
shenxianpeng wants to merge 1 commit into
Draft
feat: add --fix CLI option to auto-apply clang-format fixes#202shenxianpeng wants to merge 1 commit into
shenxianpeng wants to merge 1 commit into
Conversation
Adds a --fix flag that runs clang-format -i on files with detected style issues, clearing the format advice so no issues are reported. Related to cpp-linter/cpp-linter-action#439
Contributor
Contributor
2bndy5
reviewed
Jun 9, 2026
Contributor
There was a problem hiding this comment.
- This patch runs clang-format serially, not in parallel. This will add a significant amount of time for events with a large number of changed files.
- This patch ignores the lines-changed-only feature. Formatting the entire file may not be the behavior that users expect.
I think it would be better to handle this inside run_clang_format() because that happens in parallel and the same clang-format args that are already assembled can be reused with -i (which is also done for PR reviews I think).
On a side note, it would be nice to switch from parsing XML to parsing the diff between original source and -i output. But that is a separate issue: #168.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds a
--fixCLI flag tocpp-linterthat runsclang-format -ion files with detected style issues, then clears the format advice so no issues are reported.This is part 1 of implementing
auto-fixforcpp-linter-action(see cpp-linter/cpp-linter-action#439).Changes
cpp_linter/cli.pyfix: bool = Falseattribute toArgsclass--fix/-FCLI argument (store_true)cpp_linter/clang_tools/__init__.pycapture_clang_tools_output(), after collecting all results, ifargs.fixis True and format_cmd is available:clang-format -ion each affected filetests/test_cli_args.py--fixflag parsingDesign Decisions
lines-changed-only), becauseclang-format -icannot target specific line rangesformat_advicereset, so the existing comment/review logic sees zero format issuesRelated
auto-fixoption to fix code format automatically in PR? cpp-linter-action#439