diff --git a/nbqa/__main__.py b/nbqa/__main__.py index df606cfa..dbce5f0b 100644 --- a/nbqa/__main__.py +++ b/nbqa/__main__.py @@ -360,7 +360,7 @@ def _run_command( # pylint: disable=too-many-locals if main_command == "mypy" and "MYPY_FORCE_COLOR" not in my_env: my_env["MYPY_FORCE_COLOR"] = "1" - if main_command == "ruff": + if main_command == "ruff" and not sub_commands: sub_commands.insert(0, "check") if shell: diff --git a/tests/tools/test_ruff_works.py b/tests/tools/test_ruff_works.py index 5934c0b1..5b35e321 100644 --- a/tests/tools/test_ruff_works.py +++ b/tests/tools/test_ruff_works.py @@ -1,6 +1,7 @@ """Check :code:`ruff` works as intended.""" import os +from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -109,3 +110,20 @@ def test_ruff_isort(capsys: "CaptureFixture") -> None: out, err = capsys.readouterr() assert out == "" assert err == "" + + +def test_ruff_format(capsys: "CaptureFixture", tmp_notebook_for_testing: Path) -> None: + """ + Should ignore cell with all magics. + + Parameters + ---------- + capsys + Pytest fixture to capture stdout and stderr. + """ + + main(["ruff format", str(tmp_notebook_for_testing)]) + + out, err = capsys.readouterr() + assert out == "1 file reformatted\n" + assert err == ""