mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Use SourceKind::diff
for formatter (#8240)
## Summary This PR refactors the formatter diff code to reuse the `SourceKind::diff` logic. This has the benefit that the Notebook diff now includes the cell numbers which was not present before. ## Test Plan Update the snapshots and verified the cell numbers.
This commit is contained in:
parent
88c8b47326
commit
a7d1f7e1ec
4 changed files with 46 additions and 23 deletions
|
@ -2,7 +2,7 @@ use std::io;
|
|||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::Result;
|
||||
use similar::TextDiff;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -88,7 +88,12 @@ impl SourceKind {
|
|||
}
|
||||
|
||||
/// Write a diff of the transformed source file to `stdout`.
|
||||
pub fn diff(&self, other: &Self, path: Option<&Path>, writer: &mut dyn Write) -> Result<()> {
|
||||
pub fn diff(
|
||||
&self,
|
||||
other: &Self,
|
||||
path: Option<&Path>,
|
||||
writer: &mut dyn Write,
|
||||
) -> io::Result<()> {
|
||||
match (self, other) {
|
||||
(SourceKind::Python(src), SourceKind::Python(dst)) => {
|
||||
let text_diff = TextDiff::from_lines(src, dst);
|
||||
|
@ -154,7 +159,7 @@ impl SourceKind {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
_ => bail!("cannot diff Python source code with Jupyter notebook source code"),
|
||||
_ => panic!("cannot diff Python source code with Jupyter notebook source code"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue