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:
Charlie Marsh 2024-01-04 10:02:23 -04:00 committed by GitHub
parent f0d43dafcf
commit 328262bfac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 141 additions and 25 deletions

View file

@ -148,6 +148,7 @@ pub fn check_path(
match tokens.into_ast_source(source_kind, source_type) {
Ok(python_ast) => {
let cell_offsets = source_kind.as_ipy_notebook().map(Notebook::cell_offsets);
let notebook_index = source_kind.as_ipy_notebook().map(Notebook::index);
if use_ast {
diagnostics.extend(check_ast(
&python_ast,
@ -161,6 +162,7 @@ pub fn check_path(
package,
source_type,
cell_offsets,
notebook_index,
));
}
if use_imports {