-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Warn about incompatible formatter options #8088
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
Rule::BadQuotesInlineString, | ||
Rule::BadQuotesMultilineString, | ||
Rule::BadQuotesDocstring, | ||
Rule::AvoidableEscapedQuote, |
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.
One tricky thing here is that these don't necessarily conflict with the formatter. Some of them do overlap, but in a way that's at least consistent. Some of them are also arguably complimentary (like MissingTrailingComma
, I think, is arguably complimentary, since it will insert trailing commas that the formatter will then respect).
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.
COM812
is conflicting because it disallows:
class PhotoMetadata:
"""Metadata about a photo."""
def __init__(
self, file: Path, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u
):
...
My goal is to only warn about rules that are incompatible. E.g. I excluded
- E501 because there are valid use cases to use it alongside the formatter, even though it's mostly redundant
E701
: while redundant, it doesn't conflict with the formatter.
Is your feedback mainly about the naming of the variables or the wording of the warning message? I'm trying to understand what I should change.
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 I'm just trying to understand what we consider to be a conflict (and, based on that answer, perhaps looking to refine the list, or change the wording of the message).
For example, above, if you ran the linter, wouldn't COM812
just insert a trailing comma at the end, and then the formatter would in turn split the arguments over multiple lines? So it's not like the two tools would go back and forth endlessly disagreeing with one another, as they would if you set BadQuotes
to divergent values. The COM812
case feels like it fits some definition of a conflict though, like: formatted code can introduce these violations.
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.
For example, above, if you ran the linter, wouldn't COM812 just insert a trailing comma at the end, and then the formatter would in turn split the arguments over multiple lines?
That's correct. But it requires that you need to run formatter
, linter
, and formatter
again to get a stable result which doesn't seem ideal. I see incompatibilities as everything that leads to a bad experience.
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.
So, anything that might trigger or require some command to be repeated, even if that cycle isn't infinite. In that case, we probably want to include ISC001?
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.
Probably we should. This rule won't be conflicting with the preview style but the formatter could produce code today that conflicts with it
e7d0144
to
213ea75
Compare
0419447
to
d9c9718
Compare
|
||
if !incompatible_rules.is_empty() { | ||
incompatible_rules.sort(); | ||
warn!("The following rules can cause conflicts when used with the formatter: {}. We recommend disabling these rules when using Ruff's formatter to avoid unexpected behavior. To disable the rules, change your configuration and either remove the rules from the `select` or `extend-select` options or add the rules to the `ignore` option.", incompatible_rules.join(", ")) |
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.
Small nudges on the comment:
The following rules may cause conflicts when used with the formatter: {}.
To avoid unexpected behavior, we recommend disabling these rules, either
by removing them from your `select` or `extend-select`, or adding them to
your `ignore`.
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.
"your ignore" sounds a bit strange. I used your suggestion but changed it to "from the select
or extend-select
configuration.
} | ||
|
||
if !incompatible_options.is_empty() { | ||
warn!("The following isort options are incompatible with the formatter: {}. We recommend disabling these isort options when using Ruff's formatter by removing them from the configuration.", incompatible_options.join(", ")) |
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.
Small nudges on the comment:
The following isort options may cause conflicts when used with the formatter: {}.
To avoid unexpected behavior, we recommend disabling these options by removing
them from your configuration.
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.
Much better
d9c9718
to
e1e53d2
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
This rule is fairly important to us and it's not clear how it conflicts, as we never had a conflict using this together with |
@smackesey Thanks for your feedback. I'm sorry, I was over-cautious with the warnings. #8192 refines the warnings. You should no longer see it, as long as you don't set |
@smackesey - We're planning to cut a release today that will include that fix. |
Summary
Warn users about options incompatible with the formatter when using
ruff format
Closes #7646
Test Plan
Added integration test