Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chkstyle/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ def check_notebook(path: str) -> list[tuple]:
"Check Jupyter notebook for style violations."
with open(path, encoding="utf-8") as f: nb = json.load(f)
violations = []
for cell in nb.get("cells", []):
for idx, cell in enumerate(nb.get("cells", [])):
if cell.get("cell_type") != "code": continue
cell_id = cell.get("id", "unknown")
source_lines = cell.get("source", [])
if isinstance(source_lines, str): source = source_lines
else: source = "".join(source_lines)
if not source.strip(): continue
cell_path = f"{path}:cell[{cell_id}]"
cell_path = f"{path}:cell[{idx:03d}#{cell_id}]"
cell_violations = check_source(source, cell_path)
violations.extend(cell_violations)
return violations
Expand Down
2 changes: 1 addition & 1 deletion tests/test_chkstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_chkstyle_notebook_shows_cell_id_in_path(tmp_path):
violations = _check_nb(tmp_path, ["x: int = 1\n"])
assert len(violations) == 1
vpath, lineno, msg, lines = violations[0]
assert ":cell[cell0]" in vpath and lineno == 1
assert ":cell[000#cell0]" in vpath and lineno == 1

def test_chkstyle_notebook_shows_line_within_cell(tmp_path):
violations = _check_nb(tmp_path, ["# ok\n# still ok\nx: int = 1\n"])
Expand Down