mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-28 15:33:50 +00:00
Avoid B015
,B018
for last expression in a cell (#8815)
## Summary This PR updates `B015` and `B018` to ignore last top-level expressions in each cell of a Jupyter Notebook. Part of #8669 ## Test Plan Add test cases for both rules and update the snapshots.
This commit is contained in:
parent
727e389cac
commit
5b726f70f4
11 changed files with 454 additions and 1 deletions
|
@ -1,7 +1,9 @@
|
|||
use std::fmt;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use ruff_text_size::TextSize;
|
||||
use itertools::Itertools;
|
||||
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
|
||||
use crate::schema::{Cell, SourceValue};
|
||||
|
||||
|
@ -187,6 +189,17 @@ impl CellOffsets {
|
|||
pub(crate) fn push(&mut self, offset: TextSize) {
|
||||
self.0.push(offset);
|
||||
}
|
||||
|
||||
/// Returns the range of the cell containing the given offset, if any.
|
||||
pub fn containing_range(&self, offset: TextSize) -> Option<TextRange> {
|
||||
self.iter().tuple_windows().find_map(|(start, end)| {
|
||||
if *start <= offset && offset < *end {
|
||||
Some(TextRange::new(*start, *end))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for CellOffsets {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue