jellycell.lint.rules

Lint rule registry and rule implementations.

Each rule is a function (Project) -> list[Violation]. Fixers apply auto-fixes for violations marked fixable=True.

Rules in this file:

  • layout — all declared path roots exist (always on).

  • pep723-position — the PEP-723 block (if any) is at the top (always on).

  • enforce-artifact-pathsjc.save / jc.figure / jc.table calls write into paths.artifacts. Gated by lint.enforce_artifact_paths.

  • enforce-declared-deps — named cells that reference another cell’s name via jc.load must declare it in deps= (or have it picked up by the AST walker). Gated by lint.enforce_declared_deps.

  • deps-no-comma — catches deps=a,b,c tags that nbformat would reject at validation time; auto-fixes to one deps= tag per dep.

  • warn-on-large-cell-output — cached outputs exceeding the size threshold get a (non-fixable) warning. Gated by lint.warn_on_large_cell_output.

Module Contents

Classes

Violation

A single lint finding.

Functions

rule_layout

Check that declared path roots exist (spec §2.1).

fix_layout

Create the missing directory.

rule_pep723_position

Check every notebook’s PEP-723 block is at the top of the file (spec §7).

fix_pep723_position

Auto-fix by moving the block to the top of the file.

rule_enforce_artifact_paths

AST-scan notebooks for jc.save/figure/table calls with paths outside artifacts/.

rule_enforce_declared_deps

Cells that jc.load(...) from another cell’s artifact must declare the dep.

rule_deps_no_comma

Catch deps=a,b,c — nbformat rejects any tag containing a comma.

fix_deps_no_comma

Rewrite "deps=a,b,c" into "deps=a", "deps=b", "deps=c" in place.

rule_warn_on_large_cell_output

Cached cells whose total output size exceeds warn_on_large_cell_output.

run_all

Run every registered rule. Returns violations in a stable order.

auto_fix

Apply registered fixers. Returns the list of remaining violations.

Data

API

class jellycell.lint.rules.Violation

A single lint finding.

fixable=True indicates a registered fixer exists and can attempt to resolve this violation automatically.

rule: str

None

path: pathlib.Path | None

None

line: int | None

None

message: str

None

fixable: bool

None

jellycell.lint.rules.RuleFn

None

jellycell.lint.rules.FixerFn

None

jellycell.lint.rules.rule_layout(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

Check that declared path roots exist (spec §2.1).

jellycell.lint.rules.fix_layout(project: jellycell.paths.Project, violation: jellycell.lint.rules.Violation) bool

Create the missing directory.

jellycell.lint.rules.rule_pep723_position(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

Check every notebook’s PEP-723 block is at the top of the file (spec §7).

jellycell.lint.rules.fix_pep723_position(project: jellycell.paths.Project, violation: jellycell.lint.rules.Violation) bool

Auto-fix by moving the block to the top of the file.

jellycell.lint.rules.rule_enforce_artifact_paths(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

AST-scan notebooks for jc.save/figure/table calls with paths outside artifacts/.

jellycell.lint.rules.rule_enforce_declared_deps(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

Cells that jc.load(...) from another cell’s artifact must declare the dep.

jellycell.lint.rules.rule_deps_no_comma(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

Catch deps=a,b,c — nbformat rejects any tag containing a comma.

nbformat’s tag schema enforces ^[^,]+$ on every individual tag string, so a comma-separated deps form (deps=a,b,c) raises NotebookValidationError on first jellycell run. The valid form is one deps= tag per dep — jellycell concatenates them at parse time. Fix is mechanical; registered as fixable.

jellycell.lint.rules.fix_deps_no_comma(project: jellycell.paths.Project, violation: jellycell.lint.rules.Violation) bool

Rewrite "deps=a,b,c" into "deps=a", "deps=b", "deps=c" in place.

jellycell.lint.rules.rule_warn_on_large_cell_output(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

Cached cells whose total output size exceeds warn_on_large_cell_output.

jellycell.lint.rules.RULES: dict[str, jellycell.lint.rules.RuleFn]

None

jellycell.lint.rules.FIXERS: dict[str, jellycell.lint.rules.FixerFn]

None

jellycell.lint.rules.run_all(project: jellycell.paths.Project) list[jellycell.lint.rules.Violation]

Run every registered rule. Returns violations in a stable order.

jellycell.lint.rules.auto_fix(project: jellycell.paths.Project, violations: list[jellycell.lint.rules.Violation]) list[jellycell.lint.rules.Violation]

Apply registered fixers. Returns the list of remaining violations.

Violations are considered “remaining” if:

  • fixable is False, or

  • No fixer is registered for the rule, or

  • The fixer returned False (couldn’t fix).