mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Add cell indexes to all diagnostics (#9387)
## Summary Ensures that any lint rules that include line locations render them as relative to the cell (and include the cell number) when inside a Jupyter notebook. Closes https://github.com/astral-sh/ruff/issues/6672. ## Test Plan `cargo test`
This commit is contained in:
parent
f0d43dafcf
commit
328262bfac
10 changed files with 141 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
|||
use std::cmp::Ordering;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
|
@ -253,3 +253,20 @@ impl Debug for SourceLocation {
|
|||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub enum SourceRow {
|
||||
/// A row within a cell in a Jupyter Notebook.
|
||||
Notebook { cell: OneIndexed, line: OneIndexed },
|
||||
/// A row within a source file.
|
||||
SourceFile { line: OneIndexed },
|
||||
}
|
||||
|
||||
impl Display for SourceRow {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
SourceRow::Notebook { cell, line } => write!(f, "cell {cell}, line {line}"),
|
||||
SourceRow::SourceFile { line } => write!(f, "line {line}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue