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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: UnboundLocalError in marimo check --strict --format json (#11076)
Themiyaae50a63ef942
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.pyindex 3e2739ae31..52cf914ff8 100644--- a/marimo/_cli/cli.py+++ b/marimo/_cli/cli.py@@ -1579,16 +1579,16 @@ def check(lint_config=lint_config,)+ # Get counts from linter (fix happens automatically during streaming)+ fixed = linter.fixed_count+ total_issues = linter.issues_count+if formatter == "json":# JSON output - let linter handle the collection and formattingresult = linter.get_json_result()# Always output to stdout for JSON, regardless of errorsclick.echo(json.dumps(result), err=False)else:- # Get counts from linter (fix happens automatically during streaming)- fixed = linter.fixed_count- total_issues = linter.issues_count-# Final summaryif fixed > 0:click.echo(f"Updated {fixed} file{'s' if fixed > 1 else ''}.")diff --git a/tests/_cli/test_cli_check.py b/tests/_cli/test_cli_check.pyindex 58598d9526..8f65115644 100644--- a/tests/_cli/test_cli_check.py+++ b/tests/_cli/test_cli_check.py@@ -1,6 +1,7 @@# Copyright 2026 Marimo. All rights reserved."""CLI tests for the marimo check command."""+import jsonimport tempfilefrom click.testing import CliRunner@@ -199,3 +200,64 @@ if __name__ == "__main__":"invalid-syntax" in result.outputor "error" in result.output.lower())++ def test_check_command_json_strict_clean_notebook(self):+ """JSON + strict on a clean notebook should exit 0 with valid JSON."""+ runner = CliRunner()++ with tempfile.NamedTemporaryFile(+ mode="w", suffix=".py", delete=False+ ) as f:+ f.write("""+import marimo++__generated_with = "0.1.0"+app = marimo.App()++def _():+ x = 1+ return (x,)++if __name__ == "__main__":+ app.run()+""")+ f.flush()++ result = runner.invoke(+ check, [f.name, "--strict", "--format", "json"]+ )++ assert result.exit_code == 0, result.output+ payload = json.loads(result.output)+ assert payload["issues"] == []+ assert payload["summary"]["total_issues"] == 0+ assert payload["summary"]["errored"] is False++ def test_check_command_json_strict_with_issues(self):+ """JSON + strict should still fail when there are lint issues."""+ runner = CliRunner()++ with tempfile.NamedTemporaryFile(+ mode="w", suffix=".py", delete=False+ ) as f:+ f.write("""+import marimo++app = marimo.App()++def _():+ y = 2+ return (y,)+""")+ f.flush()++ result = runner.invoke(+ check, [f.name, "--strict", "--format", "json"]+ )++ assert result.exit_code == 1, result.output+ payload = json.loads(result.output)+ assert payload["summary"]["total_issues"] > 0+ assert len(payload["issues"]) > 0