-
Notifications
You must be signed in to change notification settings - Fork 81
MAINT: add config for ruff formatter #754
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
Conversation
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.
I'm not a fan of formatters, but if others think that this is useful, I'm not opposed to it.
|
I'm fine with adding this setting too. Not a user myself, but if it helps others then a few lines of tool config doesn't hurt. |
|
Not directly involved in mesonpy development but FWIW... I'm not a fan of autoformatters either. Actually, when someone does use an autoformatter and that autoformatter is named either "black" or "ruff", I will review their formatting like I review any other code and I will ask them to undo all changes made by those two tools since it looks really ugly. While Meson does use single quotes, and telling an autoformatter to use single quotes produces output more aligned with Meson's coding style than use of the autoformatter without that setting, it's not enough to make it helpful when developing on Meson. So, it does depend on whether the meson-python project devs view ruff as "eh, personally I wouldn't bother" or "please revert the style choices the autoformatter just made". In the former case, it may make sense to merge this PR. In the latter case, I'd suggest adding a ruff lint rule under the Q (flake8-quotes) section to check in CI that the correct project-specific quoting style is used, and auto fix them with |
|
It may independently be worth configuring the linter to check the quoting style. Interestingly, ruff doesn't have a consistent configuration schema, so you will have to configure single quotes separately for the linter and the autoformatter or they will produce different results ( This isn't a bug, it's officially documented behavior that you have to set it twice. :/ |
What I thought this would be doing is align style choices for code already written by the author of a PR with what Either way, yeah the PR diffs should be minimal, that's always important - a formatting should never increase those. |
Autoformatters traditionally discard all formatting in the file, converting the file to an abstract syntax tree and then re-rendering the entire file from scratch using its own internally preferred style (which I personally believe I have never actually seen anyone organically write -- it will never match any code other than something already processed by the autoformatter). If any lines in the file still look the same after the autoformatter runs, it's because those lines happened to be what the autoformatter does anyway. Typically this is because the autoformatter is mandatorily enforced on every commit. It's of course possible to hack around this with janky ecosystem wrappers that use |
That's already check if I'm not mistaken.
My strategy is usually to apply the formatter automatically on save but then only stage the lines relevant for the given PR. |
I don't see it in
Sure, but the js world has autoformatters written by people with more taste and less toxic ableism. :) Black is simply bad at autoformatting, to the people that don't like it. For example, my personal belief is that black is a mixture of:
with no actual exceptions. I wouldn't mind using an autoformatter if the results did what I wanted, rather than made my eyes bleed and destroyed my interest in contributing at all to projects that use that formatting. The point of tools is to automate stuff you want to do, not automate stuff you don't want to do. The JavaScript world understands that -- the python world doesn't (and probably never will). |
It's enforced by pre-commit-hook, I think here meson-python/.pre-commit-config.yaml Line 21 in 9d46f41
|
|
Please squash the commits. |
Ohhhh I see. I think it would be worth moving that, yes, given that the pre-commit-hook thing already seems to be running ruff, and that would also speed it up because it doesn't have to run as many distinct shell commands (one per id of that hooks collection thing). |
|
See #757 |
Add configuration for the ruff formatter to enforce single quotes for strings, otherwise it constantly reformats the strings to double-quotes.