-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
MNT Make ruff check line-too-long (E501) #31214
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
I don't get that "E" and "F" rules were dropped but there still are "E***" and "F***" exceptions. |
#31015 changed from [tool.ruff.lint]
# On top of the default `select` (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
extend-select = ["B", "Q"] Not sure how often |
The
From
|
Additionally, Conflicting lint rules should be avoided when using Ruff as a formatter. Specifically about
|
I recommend using |
But the formatter doesn't split long strings. In some cases like the ones identified in this PR it's acceptable but if I write something like warnings.warn(
"a very looo ... ooong string"
) it's pretty bad to keep as is imo. To me it's a regression compared to our previous state when we didn't have to care about that, while now I have to split them manually, and be extra careful when reviewing PRs that they don't introduce such behavior. |
Just don't split strings. See for example what the Linux kernel coding style has to say about user-visible strings:
I can revert |
This is C code and the motivation is to be able to grep. I think that breaking strings in Pyhon like this "this is the beginning "
"and this is the end" means implicit concatenation and the intrepreter treats it a 1 line string. On the other hand, it also says
and having a string that spans 3 screens is really not readable at all. |
I have no issue with ruff formatting. I'd just like to have a way to enforce the 88 chars limits, even on strings. |
It's the formatter's job to break lines. Unfortunately, unlike black, ruff currently doesn't process strings the way you would like. This is tracked in issue astral-sh/ruff#6936. Until the above issue is addressed, you could indeed re-enable |
I'm in favor of enabling E501 |
To try to clarify the situation, there are a few different things:
Footnotes
|
pyproject.toml
Outdated
@@ -137,7 +137,7 @@ preview = true | |||
# This enables us to use the explicit preview rules that we want only | |||
explicit-preview-rules = true | |||
# all rules can be found here: https://docs.astral.sh/ruff/rules/ | |||
extend-select = ["W", "I", "CPY001", "RUF"] | |||
extend-select = ["E", "W", "I", "CPY001", "RUF"] |
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 think it's best to explicitly enable E501
, not all E
rules:
E1
rules are about indentation. They are redundant when using a formatter.E2
rules are about missing or extra spaces. They are redundant when using a formatter.E3
rules are about missing or extra lines. They are redundant when using a formatter.E4
rules are enabled by default.E501
can be explicitly enabled as discussed.E502
is about extra backslahes. It is redundant when using a formatter.E7
rules are enabled by default.E9
rules are enabled by default.
I recommend letting ruff do the right thing by default (["E4", "E7", "E9"]
) and enabling only E501
as an additional rule.
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.
Yeah I wasn't sure about it but let's keep it more specific indeed for now.
One question: should we removed "E111", "E114", "E117"
from our ignore list since there are not enabled in ruff
by default? Or should we keep it just in case one day we add E
again (or something more generic than E501
) to avoid having to spend time in the ruff doc to figure this kind of tiny details all over again.
Ruff default that extend-select
extends is ["E4", "E7", "E9", "F"]
.
I am slightly leaning towards keeeping the full ignore list in sync with the ruff doc even if it means ignoring things that are not selected.
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 have copied over all of the Conflicting lint rules, whether their respective ruleset is currently selected or not - just in case a ruleset is selected in the future. That's perhaps overkill, feel free to remove from the ignore list the rules from unselected rulesets.
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.
LGTM.
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.
Thanks
It seems like checking too-long-lines was lost in #31015.
For now I added only
E501
for checking too-long-lines but maybe we want to add more.@DimitriPapadopoulos can you explain the reasoning behind your changes in
pyproject.toml
. I was not able to find any discussion about this in your PR.cc @jeremiedbb.