Skip to content
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

Support for clang-format and possibly rustfmt #366

Closed
tgross35 opened this issue May 5, 2022 · 3 comments
Closed

Support for clang-format and possibly rustfmt #366

tgross35 opened this issue May 5, 2022 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@tgross35
Copy link

tgross35 commented May 5, 2022

Hello!

Is there any chance you could use the same (incredible) logic used for black/isort/flake8 and add options for clang-format and rustfmt? There are some precommit hooks out there (https://github.com/doublify/pre-commit-rust, https://github.com/pre-commit/mirrors-clang-format and a couple others for clang-format) but they don't handle running only on changed lines as well (if at all).

This would be an excellent feature for any large projects that use C or rust extensions.

Extra bonus if you somehow include the pep7 compliant clang format file by default https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db

@tgross35
Copy link
Author

tgross35 commented May 5, 2022

Prettier would be very nice too, for yaml/json/toml/etc

Perhaps darker could somehow expose something generic where it uses the existing core diff logic, but allows the user to add any number of custom formatters

@akaihola akaihola added the enhancement New feature or request label May 8, 2022
@akaihola akaihola added this to the 1.7.0 milestone May 8, 2022
@akaihola
Copy link
Owner

akaihola commented May 8, 2022

@tgross35 this is a great idea and something I have been thinking about in the past. There's nothing inherent in Darker that would prevent serving needs for other languages than Python.

And actually there are some existing issues and PRs which will help a bit towards this goal:

Once Black reformatting is no more done by default by Darker, we could indeed support all of these:

  • darker --format=black .
  • darker --format=prettier .
  • darker --format=clang-format .
  • darker --format=rustfmt .

I guess each of these options could automatically determine the file extensions to look for when discovering files to process.

Linters (the --lint/-L option) will be a bit more complicated to adapt since Darker just blindly passes each modified .py file to any binaries mentioned by the --lint/-L option. So either Darker has to grow awareness of specific linters and the file types they support, or alternatively, only one reformatter would be allowed per invocation, and the file extensions matched by the reformatter option would apply to all linters as well.

Let's keep this feature on the drawing board and hope others who are interested in it will find this issue as well!

@tgross35
Copy link
Author

tgross35 commented May 9, 2022

Thank you for the very thorough answer! I didn't even realize the general idea was more or less already a work in progress so I'll get rid of this issue. I look forward to seeing whatever comes of it

@tgross35 tgross35 closed this as completed May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants