5.4 just fmt and just lint

Read the tutorial. Build it yourself is the other way to read this part.

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at 7c1670fd52a0, partway through step-05. The code before this part

To look at this code on your machine, run these commands. The first one makes a clone, if this folder has none:

[ -d cheesecracker ] || git clone https://github.com/rahuldave/cheesecracker
cd cheesecracker
git fetch --quiet --tags --force origin
git switch --detach 7c1670fd52a0
just setup

The whole tutorial then makes a change in a hurry. It adds ruff, one tool that does two jobs. As a formatter, it lays out the code in one fixed way. As a linter, it checks the code against rules. The tutorial gives ruff the rules of flake8, an older linter. The formatter and the linter get a recipe each.

5.4 just fmt and just lint run ruff

Two recipes give the formatter and the linter short names. Each passes on to ruff any words that you type after it.

± See the change to justfile

The recipe fmt runs uv run ruff format, and lint runs uv run ruff check. So just fmt --check checks the layout, and just lint --fix fixes what ruff can fix.

just fmt --check

The recipe fails as ruff format --check did, with 2 files would be reformatted.

What changed

  • justfile: the recipes fmt and lint. 8 lines added. The file
    • look at uv run ruff check "$@"

The diff of justfile
@@ -44,3 +44,11 @@ stop:
 # Run the tests, and show which lines of the package api they ran. Extra arguments go to pytest: just cov tests/unit
 cov *args:
     uv run pytest --cov=api --cov-report=term-missing "$@"
+
+# Format the code, one way. Extra arguments go to ruff: just fmt --check, just fmt --diff
+fmt *args:
+    uv run ruff format "$@"
+
+# Check the code against the rules in pyproject.toml. Extra arguments go to ruff: just lint --fix
+lint *args:
+    uv run ruff check "$@"

This change on GitHub

This part ends at the code at b947593e84b7, partway through step-05. The code after this part