Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: lint configuration (#8560)

Dylan Madisettia1633ca844df
diff --git a/marimo/_ai/_tools/tools/lint.py b/marimo/_ai/_tools/tools/lint.py
index 964b81e0f4..d87bb1737a 100644
--- a/marimo/_ai/_tools/tools/lint.py
+++ b/marimo/_ai/_tools/tools/lint.py
@@ -72,6 +72,8 @@ class LintNotebook(ToolBase[LintNotebookArgs, LintNotebookOutput]):
session = self.context.get_session(args.session_id)
notebook_ir = session.app_file_manager.app.to_ir()
+ # TODO: Use lint config from session.config_manager once the AI
+ # agent can use context to decide whether to ignore a rule.
rule_engine = RuleEngine.create_default()
diagnostics = await rule_engine.check_notebook(notebook_ir)
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py
index 791d280463..4c5c54cf6e 100644
--- a/marimo/_cli/cli.py
+++ b/marimo/_cli/cli.py
@@ -1447,6 +1447,26 @@ def shell_completion() -> None:
type=click.Choice(["full", "json"], case_sensitive=False),
help="Output format for diagnostics.",
)
+ "--select",
+ "select_rules",
+ default=None,
+ type=str,
+ help=(
+ "Comma-separated rule codes/prefixes to enable, replacing config. "
+ "e.g. --select MB,MR001"
+ ),
+)
+ "--ignore",
+ "ignore_rules",
+ default=None,
+ type=str,
+ help=(
+ "Comma-separated rule codes/prefixes to ignore. "
+ "e.g. --ignore MF004,MF007"
+ ),
+)
@click.argument("files", nargs=-1, type=click.UNPROCESSED)
def check(
fix: bool,
@@ -1455,12 +1475,18 @@ def check(
unsafe_fixes: bool,
ignore_scripts: bool,
formatter: str,
+ select_rules: str | None,
+ ignore_rules: str | None,
files: tuple[str, ...],
) -> None:
if not files:
# If no files are provided, we lint the current directory
files = ("**/*.py", "**/*.md", "**/*.qmd")
+ from marimo._lint import resolve_lint_config
+
+ lint_config = resolve_lint_config(select_rules, ignore_rules)
+
# Pass click.echo directly as pipe for streaming output, or None for JSON
pipe = click.echo if verbose and formatter != "json" else None
linter = run_check(
@@ -1470,6 +1496,7 @@ def check(
unsafe_fixes=unsafe_fixes,
ignore_scripts=ignore_scripts,
formatter=formatter,
+ lint_config=lint_config,
)
if formatter == "json":
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index 67ee2edd26..4b8f11d955 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -503,6 +503,26 @@ class DiagnosticsConfig(TypedDict, total=False):
sql_linter: bool
+@dataclass
+class LintConfig(TypedDict, total=False):
+ """Configuration for lint rule selection.
+
+ Follows ruff-inspired semantics for selecting which rules to run
+ during ``marimo check``.
+
+ **Keys.**
+
+ - ``select``: list of rule code prefixes that replaces the default
+ enabled set. Use ``"ALL"`` to select all rules.
+ Example: ``["MB", "MR001"]``
+ - ``ignore``: list of rule code prefixes to remove from the
+ enabled set.
+ """
+
+ select: list[str]
+ ignore: list[str]
+
+
@dataclass
class SnippetsConfig(TypedDict):
"""Configuration for snippets.
@@ -600,6 +620,7 @@ class MarimoConfig(TypedDict):
ai: NotRequired[AiConfig]
language_servers: NotRequired[LanguageServersConfig]
diagnostics: NotRequired[DiagnosticsConfig]
+ lint: NotRequired[LintConfig]
experimental: NotRequired[ExperimentalConfigType]
snippets: NotRequired[SnippetsConfig]
datasources: NotRequired[DatasourcesConfig]
@@ -669,6 +690,7 @@ class PartialMarimoConfig(TypedDict, total=False):
ai: NotRequired[AiConfig]
language_servers: NotRequired[LanguageServersConfig]
diagnostics: NotRequired[DiagnosticsConfig]
+ lint: NotRequired[LintConfig]
experimental: NotRequired[ExperimentalConfigType]
snippets: SnippetsConfig
datasources: NotRequired[DatasourcesConfig]
diff --git a/marimo/_lint/__init__.py b/marimo/_lint/__init__.py
index ee8b0ac40f..7115019ae2 100644
--- a/marimo/_lint/__init__.py
+++ b/marimo/_lint/__init__.py
@@ -12,6 +12,8 @@ from marimo._utils.files import async_expand_file_patterns
if TYPE_CHECKING:
from collections.abc import Callable
+ from marimo._config.config import LintConfig
+
# Define severity ordering (lower index = higher priority)
SEVERITY_ORDER = {
@@ -21,6 +23,38 @@ SEVERITY_ORDER = {
}
+def resolve_lint_config(
+ select_rules: str | None,
+ ignore_rules: str | None,
+) -> LintConfig | None:
+ """Resolve lint config from config files and CLI overrides."""
+ import os
+
+ from marimo._config.manager import get_default_config_manager
+
+ config_mgr = get_default_config_manager(current_path=os.getcwd())
+ full_config = config_mgr.get_config(hide_secrets=False)
+ lint_config: LintConfig = {
+ k: v
+ for k, v in full_config.get("lint", {}).items()
+ if k in ("select", "ignore")
+ } # type: ignore[assignment]
+
+ # CLI --select replaces config select entirely
+ if select_rules is not None:
+ lint_config["select"] = [
+ s.strip() for s in select_rules.split(",") if s.strip()
+ ]
+
+ # CLI --ignore appends to config ignore
+ if ignore_rules is not None:
+ parsed = [s.strip() for s in ignore_rules.split(",") if s.strip()]
+ existing = list(lint_config.get("ignore") or [])
+ lint_config["ignore"] = existing + parsed
+
+ return lint_config if lint_config else None
+
+
def run_check(
file_patterns: tuple[str, ...],
pipe: Callable[[str], None] | None = None,
@@ -28,6 +62,7 @@ def run_check(
unsafe_fixes: bool = False,
ignore_scripts: bool = False,
formatter: str = "full",
+ lint_config: LintConfig | None = None,
) -> Linter:
"""Run linting checks on files matching patterns (CLI entry point).
@@ -41,6 +76,7 @@ def run_check(
unsafe_fixes: Whether to enable unsafe fixes that may change behavior
ignore_scripts: Whether to ignore files not recognizable as marimo notebooks
formatter: Output format for diagnostics ("full" or "json")
+ lint_config: Optional lint rule selection config
Returns:
Linter with per-file status and diagnostics
@@ -54,6 +90,7 @@ def run_check(
unsafe_fixes=unsafe_fixes,
ignore_scripts=ignore_scripts,
formatter=formatter,
+ lint_config=lint_config,
)
linter.run_streaming(files_to_check)
return linter
@@ -116,6 +153,7 @@ __all__ = [
"EarlyStoppingConfig",
"RuleEngine",
"run_check",
+ "resolve_lint_config",
"collect_messages",
"Linter",
"FileStatus",
diff --git a/marimo/_lint/linter.py b/marimo/_lint/linter.py
index d0f0206a08..eff36a9db4 100644
--- a/marimo/_lint/linter.py
+++ b/marimo/_lint/linter.py
@@ -22,6 +22,7 @@ from marimo._utils import async_path
if TYPE_CHECKING:
from collections.abc import AsyncIterator, Callable, Iterator
+ from marimo._config.config import LintConfig
from marimo._lint.rules.base import LintRule
@@ -88,17 +89,23 @@ class Linter:
rules: list[LintRule] | None = None,
ignore_scripts: bool = False,
formatter: str = "full",
+ lint_config: LintConfig | None = None,
):
if rules is not None:
self.rule_engine = RuleEngine(rules, early_stopping)
else:
- self.rule_engine = RuleEngine.create_default(early_stopping)
+ self.rule_engine = RuleEngine.create_default(
+ early_stopping, lint_config=lint_config
+ )
self.pipe = pipe
self.fix_files = fix_files
self.unsafe_fixes = unsafe_fixes
self.ignore_scripts = ignore_scripts
self.formatter = formatter
self.files: list[FileStatus] = []
+ self._lint_config = lint_config
+ self._early_stopping = early_stopping
+ self._explicit_rules = rules is not None
# Create rule lookup for unsafe fixes
self.rule_lookup = {rule.code: rule for rule in self.rule_engine.rules}
@@ -110,6 +117,42 @@ class Linter:
self.fixed_count: int = 0
self.issues_count: int = 0
+ def _rule_engine_for_file(self, file_path: str) -> RuleEngine:
+ """Return a RuleEngine for the given file.
+
+ If the file contains PEP 723 ``[tool.marimo.lint]`` metadata and no
+ explicit rules were provided, create a per-file engine that merges
+ the file-level config with the global lint config.
+ """
+ if self._explicit_rules:
+ return self.rule_engine
+
+ from marimo._config.manager import ScriptConfigManager
+
+ try:
+ file_config = ScriptConfigManager(file_path).get_config(
+ hide_secrets=False
+ )
+ except Exception:
+ return self.rule_engine
+
+ file_lint = file_config.get("lint")
+ if not file_lint:
+ return self.rule_engine
+
+ # Merge: file-level config is additive to the global config
+ merged: LintConfig = {**self._lint_config} if self._lint_config else {}
+ if "select" in file_lint:
+ existing = list(merged.get("select") or [])
+ merged["select"] = existing + file_lint["select"]
+ if "ignore" in file_lint:
+ existing = list(merged.get("ignore") or [])
+ merged["ignore"] = existing + file_lint["ignore"]
+
+ return RuleEngine.create_default(
+ self._early_stopping, lint_config=merged
+ )
+
async def _process_single_file(self, file: Path) -> FileStatus:
"""Process a single file and return its status."""
file_path = str(file)
@@ -179,16 +222,15 @@ class Linter:
)
elif load_result.notebook is not None:
try:
+ rule_engine = self._rule_engine_for_file(file_path)
# Check notebook with all rules including parsing
- file_status.diagnostics = (
- await self.rule_engine.check_notebook(
- load_result.notebook,
- load_result.contents or "",
- # Add parsing rule if there's captured output
- stdout=stdout.getvalue().strip(),
- stderr=stderr.getvalue().strip(),
- logs=logs,
- )
+ file_status.diagnostics = await rule_engine.check_notebook(
+ load_result.notebook,
+ load_result.contents or "",
+ # Add parsing rule if there's captured output
+ stdout=stdout.getvalue().strip(),
+ stderr=stderr.getvalue().strip(),
+ logs=logs,
)
except Exception as e:
# Handle other parsing errors
diff --git a/marimo/_lint/rule_engine.py b/marimo/_lint/rule_engine.py
index c46bd8d636..2f6f4f0e19 100644
--- a/marimo/_lint/rule_engine.py
+++ b/marimo/_lint/rule_engine.py
@@ -13,6 +13,7 @@ if TYPE_CHECKING:
import logging
from collections.abc import AsyncIterator
+ from marimo._config.config import LintConfig
from marimo._lint.diagnostic import Diagnostic
from marimo._lint.rules.base import LintRule
@@ -140,9 +141,21 @@ class RuleEngine:
@classmethod
def create_default(
- cls, early_stopping: Optional[EarlyStoppingConfig] = None
+ cls,
+ early_stopping: Optional[EarlyStoppingConfig] = None,
+ lint_config: Optional[LintConfig] = None,
) -> RuleEngine:
- """Create a RuleEngine with all default rules."""
- # TODO: Filter rules based on user configuration if needed
- rules = [rule() for rule in RULE_CODES.values()]
+ """Create a RuleEngine with rules filtered by configuration.
+
+ Args:
+ early_stopping: Early stopping configuration.
+ lint_config: Optional lint rule selection config. If None,
+ all rules are enabled (backward compatible).
+ """
+ if lint_config is not None:
+ from marimo._lint.rule_selector import resolve_rules
+
+ rules = resolve_rules(lint_config)
+ else:
+ rules = [rule() for rule in RULE_CODES.values()]
return cls(rules, early_stopping)
diff --git a/marimo/_lint/rule_selector.py b/marimo/_lint/rule_selector.py
new file mode 100644
index 0000000000..b32ae12ce4
--- /dev/null
+++ b/marimo/_lint/rule_selector.py
@@ -0,0 +1,61 @@
+# Copyright 2026 Marimo. All rights reserved.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from marimo._config.config import LintConfig
+ from marimo._lint.rules.base import LintRule
+
+
+def _matches_any_prefix(code: str, prefixes: list[str]) -> bool:
+ """Check if a rule code matches any of the given prefixes.
+
+ "ALL" matches everything. Otherwise, prefix matching:
+ "MB" matches "MB001", "MF0" matches "MF001", "MF001" is exact.
+ """
+ for prefix in prefixes:
+ if prefix == "ALL" or code.startswith(prefix):
+ return True
+ return False
+
+
+def resolve_rules(
+ config: LintConfig,
+ all_rules: dict[str, type[LintRule]] | None = None,
+) -> list[LintRule]:
+ """Resolve a LintConfig into a concrete list of enabled LintRule instances.
+
+ Algorithm:
+ 1. If config.select is non-empty, start with matching rules.
+ Otherwise, start with ALL available rules.
+ 2. Remove rules matching config.ignore prefixes.
+ 3. Return instantiated rules in sorted code order.
+
+ Args:
+ config: LintConfig with optional ``select`` and ``ignore`` keys.
+ all_rules: Available rule classes keyed by code.
+ Defaults to ``RULE_CODES`` when None.
+
+ Returns:
+ Instantiated LintRule list, sorted by code.
+ """
+ if all_rules is None:
+ from marimo._lint.rules import RULE_CODES
+
+ all_rules = RULE_CODES
+
+ codes = set(all_rules.keys())
+ select = config.get("select")
+ ignore = config.get("ignore")
+
+ # Step 1: base set
+ if select:
+ codes = {c for c in codes if _matches_any_prefix(c, select)}
+
+ # Step 2: remove ignored
+ if ignore:
+ codes = {c for c in codes if not _matches_any_prefix(c, ignore)}
+
+ # Step 3: instantiate in deterministic order
+ return [all_rules[c]() for c in sorted(codes)]
diff --git a/packages/openapi/api.yaml b/packages/openapi/api.yaml
index 02beee20ab..cfe73fa037 100644
--- a/packages/openapi/api.yaml
+++ b/packages/openapi/api.yaml
@@ -2647,6 +2647,25 @@ components:
- data
title: LayoutConfig
type: object
+ LintConfig:
+ description: "Configuration for lint rule selection.\n\n Follows ruff-inspired\
+ \ semantics for selecting which rules to run\n during ``marimo check``.\n\
+ \n **Keys.**\n\n - ``select``: list of rule code prefixes that replaces\
+ \ the default\n enabled set. Use ``\"ALL\"`` to select all rules.\n \
+ \ Example: ``[\"MB\", \"MR001\"]``\n - ``ignore``: list of rule code\
+ \ prefixes to remove from the\n enabled set."
+ properties:
+ ignore:
+ items:
+ type: string
+ type: array
+ select:
+ items:
+ type: string
+ type: array
+ required: []
+ title: LintConfig
+ type: object
ListDataSourceConnectionCommand:
description: "List data source schemas.\n\n Retrieves available schemas for\
\ a data source engine.\n\n Attributes:\n engine: Data source engine\
@@ -2967,6 +2986,8 @@ components:
$ref: '#/components/schemas/KeymapConfig'
language_servers:
$ref: '#/components/schemas/LanguageServersConfig'
+ lint:
+ $ref: '#/components/schemas/LintConfig'
mcp:
$ref: '#/components/schemas/MCPConfig'
package_management:
diff --git a/packages/openapi/src/api.ts b/packages/openapi/src/api.ts
index 4bd142a730..75fd64ddec 100644
--- a/packages/openapi/src/api.ts
+++ b/packages/openapi/src/api.ts
@@ -4869,6 +4869,25 @@ export interface components {
data: Record<string, any>;
type: string;
};
+ /**
+ * LintConfig
+ * @description Configuration for lint rule selection.
+ *
+ * Follows ruff-inspired semantics for selecting which rules to run
+ * during ``marimo check``.
+ *
+ * **Keys.**
+ *
+ * - ``select``: list of rule code prefixes that replaces the default
+ * enabled set. Use ``"ALL"`` to select all rules.
+ * Example: ``["MB", "MR001"]``
+ * - ``ignore``: list of rule code prefixes to remove from the
+ * enabled set.
+ */
+ LintConfig: {
+ ignore?: string[];
+ select?: string[];
+ };
/**
* ListDataSourceConnectionCommand
* @description List data source schemas.
@@ -5056,6 +5075,7 @@ export interface components {
formatting: components["schemas"]["FormattingConfig"];
keymap: components["schemas"]["KeymapConfig"];
language_servers?: components["schemas"]["LanguageServersConfig"];
+ lint?: components["schemas"]["LintConfig"];
mcp?: components["schemas"]["MCPConfig"];
package_management: components["schemas"]["PackageManagementConfig"];
runtime: components["schemas"]["RuntimeConfig"];
diff --git a/tests/_lint/test_files/empty_cell_with_lint_config.py b/tests/_lint/test_files/empty_cell_with_lint_config.py
new file mode 100644
index 0000000000..61a610e2eb
--- /dev/null
+++ b/tests/_lint/test_files/empty_cell_with_lint_config.py
@@ -0,0 +1,23 @@
+# /// script
+# [tool.marimo.lint]
+# ignore = ["MF004"]
+# ///
+import marimo
+
+__generated_with = "0.15.5"
+app = marimo.App()
+
+
+def _():
+ return
+
+
+def normal_cell():
+ x = 1
+ return (x,)
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/tests/_lint/test_lint_config_integration.py b/tests/_lint/test_lint_config_integration.py
new file mode 100644
index 0000000000..36f9e09a3b
--- /dev/null
+++ b/tests/_lint/test_lint_config_integration.py
@@ -0,0 +1,102 @@
+# Copyright 2026 Marimo. All rights reserved.
+"""Integration tests for lint config flowing through the pipeline."""
+
+from __future__ import annotations
+
+from marimo._lint.linter import Linter
+from marimo._lint.rule_engine import RuleEngine
+
+
+class TestRuleEngineConfig:
+ def test_create_default_no_config(self):
+ engine = RuleEngine.create_default()
+ from marimo._lint.rules import RULE_CODES
+
+ assert len(engine.rules) == len(RULE_CODES)
+
+ def test_create_default_with_select(self):
+ engine = RuleEngine.create_default(lint_config={"select": ["MB"]})
+ assert all(r.code.startswith("MB") for r in engine.rules)
+ assert len(engine.rules) == 5
+
+ def test_create_default_with_ignore(self):
+ engine = RuleEngine.create_default(lint_config={"ignore": ["MF001"]})
+ codes = {r.code for r in engine.rules}
+ assert "MF001" not in codes
+
+ def test_create_default_empty_config(self):
+ engine = RuleEngine.create_default(lint_config={})
+ from marimo._lint.rules import RULE_CODES
+
+ assert len(engine.rules) == len(RULE_CODES)
+
+
+class TestLinterConfig:
+ def test_linter_with_lint_config(self):
+ linter = Linter(lint_config={"select": ["MB"]})
+ assert all(r.code.startswith("MB") for r in linter.rule_engine.rules)
+
+ def test_linter_with_ignore(self):
+ linter = Linter(lint_config={"ignore": ["MF"]})
+ assert not any(
+ r.code.startswith("MF") for r in linter.rule_engine.rules
+ )
+
+ def test_linter_explicit_rules_ignores_config(self):
+ """When explicit rules are passed, lint_config is not used."""
+ from marimo._lint.rules.breaking import UnparsableRule
+
+ explicit = [UnparsableRule()]
+ linter = Linter(rules=explicit, lint_config={"select": ["MF"]})
+ assert len(linter.rule_engine.rules) == 1
+ assert linter.rule_engine.rules[0].code == "MB001"
+
+ def test_linter_no_config(self):
+ linter = Linter()
+ from marimo._lint.rules import RULE_CODES
+
+ assert len(linter.rule_engine.rules) == len(RULE_CODES)
+
+
+class TestPep723LintConfig:
+ """Test that PEP 723 inline script metadata can configure lint rules."""
+
+ FILE = "tests/_lint/test_files/empty_cell_with_lint_config.py"
+
+ def _read_and_parse(self):
+ from marimo._ast.parse import parse_notebook
+
+ with open(self.FILE) as f:
+ code = f.read()
+ return parse_notebook(code, filepath=self.FILE), code
+
+ def test_empty_cell_ignored_via_pep723_lint_config(self):
+ """MF004 is suppressed when the notebook's PEP 723 metadata ignores it."""
+ from marimo._config.manager import ScriptConfigManager
+
+ notebook, _ = self._read_and_parse()
+
+ # Read lint config from the notebook's PEP 723 metadata
+ script_mgr = ScriptConfigManager(self.FILE)
+ config = script_mgr.get_config(hide_secrets=False)
+ lint_config = config.get("lint")
+ assert lint_config is not None, (
+ "Expected [tool.marimo.lint] in metadata"
+ )
+ assert "MF004" in lint_config.get("ignore", [])
+
+ from tests._lint.utils import lint_notebook
+
+ diagnostics = lint_notebook(notebook, lint_config=lint_config)
+ codes = [d.code for d in diagnostics]
+ assert "MF004" not in codes
+
+ def test_empty_cell_detected_without_config(self):
+ """Without lint config, the empty cell IS detected as MF004."""
+ notebook, _ = self._read_and_parse()
+
+ from tests._lint.utils import lint_notebook
+
+ diagnostics = lint_notebook(notebook)
+ codes = [d.code for d in diagnostics]
+ assert "MF004" in codes
diff --git a/tests/_lint/test_rule_selector.py b/tests/_lint/test_rule_selector.py
new file mode 100644
index 0000000000..5db60cc660
--- /dev/null
+++ b/tests/_lint/test_rule_selector.py
@@ -0,0 +1,82 @@
+# Copyright 2026 Marimo. All rights reserved.
+"""Unit tests for lint rule selection."""
+
+from __future__ import annotations
+
+from marimo._lint.rule_selector import resolve_rules
+from marimo._lint.rules import RULE_CODES
+
+
+class TestResolveRules:
+ def test_empty_config_returns_all_rules(self):
+ rules = resolve_rules({})
+ assert len(rules) == len(RULE_CODES)
+
+ def test_select_by_category_prefix(self):
+ rules = resolve_rules({"select": ["MB"]})
+ assert all(r.code.startswith("MB") for r in rules)
+ assert len(rules) == 5
+
+ def test_select_exact_code(self):
+ rules = resolve_rules({"select": ["MB001"]})
+ assert len(rules) == 1
+ assert rules[0].code == "MB001"
+
+ def test_select_multiple_prefixes(self):
+ rules = resolve_rules({"select": ["MB", "MR"]})
+ codes = {r.code for r in rules}
+ assert all(c.startswith(("MB", "MR")) for c in codes)
+ assert len(rules) == 7 # 5 MB + 2 MR
+
+ def test_select_all(self):
+ rules = resolve_rules({"select": ["ALL"]})
+ assert len(rules) == len(RULE_CODES)
+
+ def test_ignore_single_rule(self):
+ rules = resolve_rules({"ignore": ["MF004"]})
+ codes = {r.code for r in rules}
+ assert "MF004" not in codes
+ assert len(rules) == len(RULE_CODES) - 1
+
+ def test_ignore_category(self):
+ rules = resolve_rules({"ignore": ["MF"]})
+ assert not any(r.code.startswith("MF") for r in rules)
+
+ def test_select_and_ignore(self):
+ rules = resolve_rules({"select": ["MB"], "ignore": ["MB001"]})
+ codes = {r.code for r in rules}
+ assert "MB001" not in codes
+ assert all(c.startswith("MB") for c in codes)
+ assert len(rules) == 4
+
+ def test_partial_prefix(self):
+ rules = resolve_rules({"select": ["MB00"]})
+ assert all(r.code.startswith("MB00") for r in rules)
+ assert len(rules) > 0
+
+ def test_unknown_prefix_returns_empty(self):
+ rules = resolve_rules({"select": ["XX"]})
+ assert len(rules) == 0
+
+ def test_sorted_order(self):
+ rules = resolve_rules({})
+ codes = [r.code for r in rules]
+ assert codes == sorted(codes)
+
+ def test_custom_all_rules(self):
+ from marimo._lint.rules.breaking import UnparsableRule
+ from marimo._lint.rules.runtime import SelfImportRule
+
+ custom = {"MB001": UnparsableRule, "MR001": SelfImportRule}
+ rules = resolve_rules({"select": ["MB"]}, all_rules=custom)
+ assert len(rules) == 1
+ assert rules[0].code == "MB001"
+
+ def test_ignore_all_returns_empty(self):
+ rules = resolve_rules({"ignore": ["ALL"]})
+ assert len(rules) == 0
+
+ def test_select_all_ignore_some(self):
+ rules = resolve_rules({"select": ["ALL"], "ignore": ["MF"]})
+ assert not any(r.code.startswith("MF") for r in rules)
+ assert any(r.code.startswith("MB") for r in rules)
diff --git a/tests/_lint/utils.py b/tests/_lint/utils.py
index 636c91b6bb..b453f4fafa 100644
--- a/tests/_lint/utils.py
+++ b/tests/_lint/utils.py
@@ -1,13 +1,22 @@
"""Utilities for lint tests."""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
from marimo._lint.diagnostic import Diagnostic
from marimo._lint.rule_engine import RuleEngine
from marimo._schemas.serialization import NotebookSerializationV1
+if TYPE_CHECKING:
+ from marimo._config.config import LintConfig
+
def lint_notebook(
- notebook: NotebookSerializationV1, contents: str = ""
+ notebook: NotebookSerializationV1,
+ contents: str = "",
+ lint_config: LintConfig | None = None,
) -> list[Diagnostic]:
"""Lint a notebook and return all diagnostics found."""
- rule_engine = RuleEngine.create_default()
+ rule_engine = RuleEngine.create_default(lint_config=lint_config)
return rule_engine.check_notebook_sync(notebook, contents)