-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Move clang-format download into dotnet/runtime and add docs for setting up auto-formatting in the repository #59374
Conversation
…o pull down the formatting tools.
…ang-format with the new download scripts.
…t on save" is unavailable.
…vailable for the formatter script.
Tagging subscribers to this area: @dotnet/runtime-infrastructure Issue DetailsIn the dotnet/runtime repository, we regularly have many "nit" comments on PRs from new contributors. Over the last few years, we've made some improvements in this area, but they've generally provided a poorer experience than possible. For the RyuJIT code base, we have an extra CI leg that checks formatting for the CoreCLR JIT. This script generates a For the majority of our managed code, we use Roslyn-based analyzers and This PR provides mechanisms within the dotnet/runtime repo to pull down clang-format (for C and C++ formatting) and dotnet-format (for .NET code) as well as documentation for how to enable auto-formatting when committing code or "format-on-save" in editors like Visual Studio Code. This PR does not yet include formatting rules for the rest of the repository (in particular the CoreCLR native code outside of the JIT or corehost). I wanted to get some feedback on the docs before I start putting together clang-format configuration files based on the existing code styles. To ensure we do not change the existing style used by RyuJIT developers, we are using the same version of clang-format as the current formatting scripts (3.8). Newer versions have slightly different formatting settings that I can't quite seem to figure out how to map to the equivalent of the 3.8 formatting with the limited time-boxed time I spent on it.
|
… any dir that doesn't already have a style configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting up this general framework seems fine to me.
The JIT team should definitely consider updating to a brand new clang-format/clang-tidy, and updating the 5+ year old cached copies we have. Perhaps that would solve some of the problems you were seeing integrating with VS Code?
Note that the JIT team uses the jit-format tool to invoke clang-format/clang-tidy. This is super important since it parallelizes the run, making it much, much faster.
Do you expect to change jitutils bootstrap.cmd/sh to not download the clang tools, and instead use the ones you've provided scripts here for downloading?
If the non-JIT C/C++ code teams decide to use clang-*, that is a big and contentious decision. Just sayin...
Updating clang-format/clang-tidy would solve some of the issues, and would make it easier to apply formatting rules to various parts of the repo that have semi-consistent styling already.
Is
I guess since I've already updated
I'm gearing up for that conversation as we speak. That's why I added the "disable formatting" file at the root of the repo, to make this more opt-in on a team by team basis if I can convince people to describe their existing conventions in clang-format (or let me do it for them). |
Maybe format-on-save is only touching changed files, whereas jit-format is looking at all JIT files, touched or not? I'm not sure we can depend on editor format-on-save, given how people use so many different editing workflows. |
Yes, format-on-save and the pre-commit hook both only look at changed files. A script that touches all files (like jit-format) for CI validation of formatting makes sense. All other cases should be covered by the pre-commit hook or the format-on-save functionality. |
Now that we have the default "disable formatting" file and the filled out docs, I'm going to merge this in. |
In the dotnet/runtime repository, we regularly have many "nit" comments on PRs from new contributors. Over the last few years, we've made some improvements in this area, but they've generally provided a poorer experience than possible.
For the RyuJIT code base, we have an extra CI leg that checks formatting for the CoreCLR JIT. This script generates a
.diff
file that can begit apply
d and outputs instructions on how to run the formatter locally. However, to get the diff file, users need to manually trawl through AzDO build artifacts. Running the script also takes a significant amount of time since it clones and builds the https://github.com/dotnet/jitutils repo to get the tool that executes the formatters.For the majority of our managed code, we use Roslyn-based analyzers and
.editorconfig
files to enforce our formatting. However, we do not provide any mechanism to fix any formatting issues. The build will just emit build errors for formatting problems.This PR provides mechanisms within the dotnet/runtime repo to pull down clang-format (for C and C++ formatting) and dotnet-format (for .NET code) as well as documentation for how to enable auto-formatting when committing code or "format-on-save" in editors like Visual Studio Code.
This PR does not yet include formatting rules for the rest of the repository (in particular the CoreCLR native code outside of the JIT or corehost). I wanted to get some feedback on the docs before I start putting together clang-format configuration files based on the existing code styles.
To ensure we do not change the existing style used by RyuJIT developers, we are using the same version of clang-format as the current formatting scripts (3.8). Newer versions have slightly different formatting settings that I can't quite seem to figure out how to map to the equivalent of the 3.8 formatting with the limited time-boxed time I spent on it.