-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 dotnet-format script to pre-commit #88933
Conversation
fa701c5
to
790a39d
Compare
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.
All good 👍
I think that at some point in the future, we might want to do something clever to avoid running dotnet format
on all the projects all the time.
It seems like running This might be better than a local hook, as it might include a seamless process for installing a local copy of Edit: Tested the current PR, if you don't have
With the current python script approach, we'd need to return a non-zero error code when the call fails. |
I've tried using the https://github.com/dotnet/format hook but despite cloning the whole repo in For the reference, here's how I included it:
Another issue I had was that I couldn't find how to make So I guess we can stick to the approach in this PR. We could either make it return non-zero when |
Yep, I saw that and originally I tried to set it up like the example in their repo. But I run into multiple issues:
Even though the hook only runs when you modify C# files, sometimes non-C# contributors modify C# files just for parity with changes they are making in other parts of the engine. I wouldn't want to make it a requirement to have To me, running |
It would speed things up drastically if people are aiming to actually use the hook as a pre-commit. For CI, I agree that it doesn't matter. As for being complicated, that kind of thing should work? # Match all the input files to their respective C# project.
input_files = [ os.path.normpath(x) for x in sys.argv ]
projects = { path: [
f for f in sys.argv if os.path.commonpath([f, path]) == path
] for path in [ os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True) ] }
# Run dotnet format on all projects with more than 0 modified files.
for (path, files) in projects.items():
if len(files) > 0:
command = f"dotnet format {path} --include {' '.join(files)}"
os.system(command) |
Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com>
790a39d
to
97851f0
Compare
Thanks, I gave it a try and it's actually faster than I expected.
So I added your changes to the PR. |
Thanks! |
pre-commit
Python tool #88866.