Skip to content

format_code.py changed to print the diff when not formatting files inline #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2021

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Jun 11, 2021

This PR modifies format_code.py to print a unified diff of incorrectly-formatted files when both -noformat_file and -verbose are specified. This can make it easier to correct formatting problems based on the output from GitHub Actions without having to run clang-format yourself. This is especially useful if the version of clang-format on the GitHub Actions runners differs from that on your local machine, as they may produce different results.

Here is an example output of format_code.py:

$ python3 scripts/format_code.py -noformat_file -verbose -f example.cc                  
Found 1 file(s). Checking their format.
  - Requires reformatting: "example.cc"
------ BEGIN FORMATTING DIFF OF example.cc
---
+++
@@ -1,9 +1,9 @@
+#include <string>
 #include <vector>
-#include <string>

 std::vector<std::string> GetStrings() {
-    std::vector<std::string> v;
+  std::vector<std::string> v;
   v.emplace_back("string1");
-  v.emplace_back( "string2" );
+  v.emplace_back("string2");
   return v;
 }
------ END FORMATTING DIFF OF example.cc

@dconeybe dconeybe self-assigned this Jun 11, 2021
@google-cla google-cla bot added the cla: yes label Jun 11, 2021
@dconeybe dconeybe requested a review from DellaBitta June 11, 2021 17:00
@dconeybe dconeybe assigned DellaBitta and unassigned dconeybe Jun 11, 2021
dconeybe added a commit that referenced this pull request Jun 11, 2021
dconeybe added a commit that referenced this pull request Jun 11, 2021
@dconeybe dconeybe merged commit 46c31ce into main Jun 14, 2021
@dconeybe dconeybe deleted the dconeybe/FormatCodePrintDiff branch June 14, 2021 18:13
@firebase firebase locked and limited conversation to collaborators Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants