-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary This PR refactors the `NotebookIndex` struct to use `OneIndexed` to make the intent of the code clearer. ## Test Plan Update the existing test case and run `cargo test` to verify the change. - [x] Verify `--diff` output - [x] Verify the diagnostics output - [x] Verify `--show-source` output
- Loading branch information
1 parent
c1fdb9c
commit cd564c4
Showing
6 changed files
with
80 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use ruff_source_file::OneIndexed; | ||
|
||
/// Jupyter Notebook indexing table | ||
/// | ||
/// When we lint a jupyter notebook, we have to translate the row/column based on | ||
/// [`ruff_text_size::TextSize`] to jupyter notebook cell/row/column. | ||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
pub struct NotebookIndex { | ||
/// Enter a row (1-based), get back the cell (1-based) | ||
pub(super) row_to_cell: Vec<u32>, | ||
pub(super) row_to_cell: Vec<OneIndexed>, | ||
/// Enter a row (1-based), get back the row in cell (1-based) | ||
pub(super) row_to_row_in_cell: Vec<u32>, | ||
pub(super) row_to_row_in_cell: Vec<OneIndexed>, | ||
} | ||
|
||
impl NotebookIndex { | ||
/// Returns the cell number (1-based) for the given row (1-based). | ||
pub fn cell(&self, row: usize) -> Option<u32> { | ||
self.row_to_cell.get(row).copied() | ||
pub fn cell(&self, row: OneIndexed) -> Option<OneIndexed> { | ||
self.row_to_cell.get(row.to_zero_indexed()).copied() | ||
} | ||
|
||
/// Returns the row number (1-based) in the cell (1-based) for the | ||
/// given row (1-based). | ||
pub fn cell_row(&self, row: usize) -> Option<u32> { | ||
self.row_to_row_in_cell.get(row).copied() | ||
pub fn cell_row(&self, row: OneIndexed) -> Option<OneIndexed> { | ||
self.row_to_row_in_cell.get(row.to_zero_indexed()).copied() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters