clang-format improvements#1251
Conversation
1bd5793 to
5b3e9be
Compare
- Add a clang-format linter check to the PR pipeline - Apply clang-format to files where the linter initially failed - Remove `CommentPragmas` from `.clang-format` - Remove all `// clang-format off` and `// NO-FORMAT` as they are not needed - Remove a commented out `GSL_SUPPRESS`
|
I am not github pipeline expert. The clang-format.yml file is AI generated. I have no idea if it is OK or not. |
carsonRadtke
left a comment
There was a problem hiding this comment.
Thanks for making these changes! The only blocker is the third-party actions dependency - if you wouldn't mind changing that to a shell command, that'd be appreciated.
OK, I'll give it a try. |
Co-authored-by: Carson Radtke <nosrac925@gmail.com>
…"GSL_SUPPRESS(bounds .1)"
to prevent formatting of include/CMakeLists.txt
In a VS2026 developer command prompt I ran `clang-format -i include\gsl\* --assume-filename x.cpp`. This was necessary because VS GUI does not format files without an extension :(. Please note that `--assume-filename` is necessary here, otherwise the files will not be formatted. Surprisingly the behaviour for the formatter differs from the behaviour of `lang-format(-20) --dry-run --Werror include/gsl/*` where clang-format recognizes that the files is C++.
Consider adding |
| # Install the exact clang-format binary | ||
| - name: Install clang-format | ||
| run: | | ||
| sudo apt install clang-format-${{ env.CLANG_VERSION }} |
There was a problem hiding this comment.
I'd rather use the pre-installed version, but I'm not going to block the PR on it.
There was a problem hiding this comment.
The pre-installed version needs the WhitespaceSensitiveMacros change, clang-format-20 does not.
Regarding the burden on the authors: I think it might be a good idea to provide an apply-clang-format.bat and an apply-clang-format.sh. Of course the bat file would only work in the developer command prompt and could only use the clang-format version shipped with Visual Studio. What do you think about it? Shall I add those files to make formatting easier?
There was a problem hiding this comment.
Shall I add those files to make formatting easier?
That sounds good to me. Can you add it to a <repo-root>/scripts folder?
There was a problem hiding this comment.
Alternatively, we could add it as a copilot skill so [at]Copilot can make the changes automatically?
This way we don't have to worry about what clang-format version is installed on the user's machine when they run the script. Copilot will automatically have whatever we specify in https://github.com/microsoft/GSL/blob/main/.github/workflows/copilot-setup-steps.yml.
Either way is fine by me.
There was a problem hiding this comment.
Regarding the copilot-setup-steps.yml I have no idea how that all works together, what the best place is to do changes. I either need your guidance or you do your refinements after this PR is merged. Whatever you think is better.
carsonRadtke
left a comment
There was a problem hiding this comment.
Thanks for the changes! LGTM
I'll merge it on Monday in case you want to address my non-blocking comments.
Here is a patch for .clang-format together with the changes it does to the files. I understand that it fixes the whitespace-in-suppress-attributes-problem, but I am not sure if this looks better. Which version do you prefer? Shall I apply the patch or leave it as it is? For example: |
I don't really have a preference on what "looks better", but I do think that having |
for linux with linter (shfmt and shellcheck)
batfile and a Linuxshscript to apply formatting to all sources files, and on Linux also to all.shshell scripts. Add a linter check to the pipeline for the.shshell scripts (callingshfmtandshellcheck).CommentPragmasfrom.clang-formatWhitespaceSensitiveMacros: [GSL_SUPPRESS]to.clang-format// clang-format offand// NO-FORMATas they are not needed any moreGSL_SUPPRESS