-
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
Display fixes by default (#7352) #12595
Changes from all commits
b824fd3
1f07f5f
8fabf4f
fde34bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,16 @@ impl<'a> Diff<'a> { | |
|
||
impl Display for Diff<'_> { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
// TODO: Instead of hard-coding this in, the `TextEmitter` should be | ||
// handling it. See https://github.com/astral-sh/ruff/issues/12597 for | ||
// further discussion. | ||
if matches!( | ||
self.fix.applicability(), | ||
Applicability::Unsafe | Applicability::DisplayOnly | ||
) { | ||
return Ok(()); | ||
} | ||
Comment on lines
+39
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that we won't see unsafe fixes in snapshot tests anymore? I would find this concerning because it means we loose all test coverage for unsafe fixes (of which there are plenty) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to address this before merging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we realized this late in our time working on it yesterday. It may warrant going ahead and doing the bit I highlighted in #12597, etc. I think this was a case where trying to keep the change minimal actually makes it harder to land—this particularly bit of coupling wasn’t obvious to me until the very end when we changed from including all the CTAs to including none of them, and turning off. I think it probably needs the aforementioned refactor (where the |
||
|
||
// TODO(dhruvmanila): Add support for Notebook cells once it's user-facing | ||
let mut output = String::with_capacity(self.source_code.source_text().len()); | ||
let mut last_end = TextSize::default(); | ||
|
@@ -53,14 +63,6 @@ impl Display for Diff<'_> { | |
|
||
let diff = TextDiff::from_lines(self.source_code.source_text(), &output); | ||
|
||
let message = match self.fix.applicability() { | ||
// TODO(zanieb): Adjust this messaging once it's user-facing | ||
Applicability::Safe => "Safe fix", | ||
Applicability::Unsafe => "Unsafe fix", | ||
Applicability::DisplayOnly => "Display-only fix", | ||
}; | ||
writeln!(f, "ℹ {}", message.blue())?; | ||
|
||
let (largest_old, largest_new) = diff | ||
.ops() | ||
.last() | ||
|
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.
Should this be gated behind preview mode to get some user feedback before enabling it for everyone?
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 don't think it's strictly necessary, but we may want to do so if it's going to change significantly (i.e. by being split into follow-ups)