Record the two things that can change#
A lint or scan result is a function of two inputs: the files it read and the tool that read them, including the tool's defaults. A finding that "appeared overnight" means one of those changed. Developers usually check the first and forget the second, because CI images and unpinned requirements upgrade tools without a commit in the repository.
Collect two records for the last clean run and the first failing one. The first is the tool's exact version, printed by the job. The second is a manifest of the files it actually checked, with a hash of each. Ruff prints the file list with --show-files, which also answers whether an exclude pattern changed:
$ ruff check --show-files src
/.../runA/src/billing/_schema.py
/.../runA/src/billing/invoices.py
$ ruff check --show-files src | xargs sha256sum
If the versions differ and the manifests match, the tool changed. If the manifests differ and the versions match, the code changed, whether or not anyone edited it by hand.
Same code, two ruff versions#
This constructed module has no ruff configuration, so ruff applies its default rule set:
# src/billing/invoices.py
import datetime
import subprocess
def stamp(invoice_id, tags=[]):
tags.append(datetime.datetime.now().isoformat())
return tags
def render(path):
return subprocess.run("pandoc " + path, shell=True, check=True)
Ruff 0.15.22 passes it. Ruff 0.16.0, a minor release, reports two findings on the same file:
$ ruff --version && ruff check --no-cache --output-format concise src
ruff 0.15.22
All checks passed!
$ ruff --version && ruff check --no-cache --output-format concise src
ruff 0.16.0
src/billing/invoices.py:5:28: B006 Do not use mutable data structures for argument defaults
src/billing/invoices.py:6:17: DTZ005 `datetime.datetime.now()` called without a `tz` argument
Found 2 errors.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
The file is byte-for-byte the same in both runs. To see what changed in the tool, dump each version's resolved settings and compare the enabled rules:
$ ruff check --show-settings src/billing/invoices.py > settings-0.16.0.txt # and for 0.15.22
$ # enabled-*.txt: the rules listed under linter.rules.enabled, one per line
$ wc -l < enabled-0.15.22.txt; wc -l < enabled-0.16.0.txt
59
413
$ diff enabled-0.15.22.txt enabled-0.16.0.txt | grep -E "mutable-argument-default|call-datetime-now"
> call-datetime-now-without-tzinfo (DTZ005)
> mutable-argument-default (B006)
The default set grew from 59 rules to 413, and both new findings come from rules that were not enabled before.
Read the changelog at the tag#
The settings diff says which rules changed. The changelog says why, and whether the change is intended. Ruff's CHANGELOG at the 0.16.0 tag lists it first under breaking changes: "Ruff now enables a much larger set of rules by default (413, up from 59)." The project's versioning policy at 0.16.0 explains why this arrived in a minor version: Ruff "uses the minor version number for breaking changes", and its list of minor-version changes includes "Stable rules are added to the default set" and "Stable rules are removed from the default set".
The second line matters on the next upgrade. The CHANGELOG at 0.17.0 removes several datetime rules from the default set, including DTZ005: they "are no longer enabled by default". The same release changes the default Python version when none is configured: "Ruff now defaults to Python 3.11 instead of 3.10". Rules that depend on the target version can start or stop firing from that alone. A project that relies on defaults inherits each of these changes.
Fix, or pin and schedule#
Treat each new finding on its merits; the version change explains why it appeared, not whether it is wrong. Here B006 points at a real bug: the default list is shared between calls, so every call to stamp() without tags appends to the same list. That one is worth fixing now. DTZ005 depends on whether the code needs time-zone-aware timestamps; a billing system usually does, but that is a decision for the owners, not an automatic fix.
When the new findings are many, or block an unrelated change, pin the tool so the upgrade happens in one reviewed change of its own. Ruff can enforce its own version from configuration. The required-version option is documented as "Useful for unifying results across many environments":
[tool.ruff]
required-version = "==0.15.22"
$ ruff check --no-cache src # with ruff 0.16.0 installed
ruff failed
Cause: Required version `==0.15.22` does not match the running version `0.16.0`
The run fails loudly instead of quietly applying different rules. Pin the version in the requirements or CI image as well, and open the upgrade as its own task with the changelog entry and the new findings attached. Selecting rules explicitly with lint.select instead of relying on the default set has the same effect on rule membership, though rule behaviour can still change in a minor release.
When the code did change#
The same symptom can have the other cause. In this constructed case the tool is pinned at 0.16.0 for both runs, and nobody edited a Python file by hand between them:
$ ruff --version && ruff check --no-cache --output-format concise src # run A
ruff 0.16.0
All checks passed!
$ ruff --version && ruff check --no-cache --output-format concise src # run B
ruff 0.16.0
src/billing/_schema.py:5:31: B006 Do not use mutable data structures for argument defaults
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
The version line rules out the tool. The input manifests (the first 12 hex digits of each sha256sum) find the cause:
$ diff manifest-runA.txt manifest-runB.txt
1c1
< 1a4450bbd4ef src/billing/_schema.py
---
> ebf97e1eed1e src/billing/_schema.py
_schema.py is generated. Its header changed from # Generated by schemagen 2.3.0 to # Generated by schemagen 2.4.0, and the new generator emits a validate(record, required=["id"]) function. The input changed through a dependency upgrade, which is still a code change: the generated function ships, and the finding is about code that runs. Fix it in the generator or its configuration, or pin the generator version until that fix lands. Excluding the generated file from the linter would hide the bug, not resolve it.
Lockfile changes, regenerated protocol buffers, vendored updates and files produced during the build all reach the analyzer this way. A file manifest records each of them, because it lists what the analyzer read rather than what was committed.
Decide from the version and the manifest#
| What changed between runs | Evidence to collect | Decision |
|---|---|---|
| Tool version, inputs identical | Both versions, matching manifests, changelog entry at the new tag | Fix real findings now, or pin the old version and schedule the upgrade |
| Tool version, default rule set changed | --show-settings diff of enabled rules | Select rules explicitly or pin; review the new rules as one change |
| Tool version, default Python target changed | The changelog entry and the project's configured target | Set the target version explicitly |
| Inputs changed, tool identical | Manifest diff naming the file, and the source of the change (generator, lockfile, build step) | Treat as a code change: fix at the source or pin the generator |
| Neither changed | Two identical runs | Look for nondeterminism, such as caches or file ordering, before triaging |
An analyzer upgrade can also make findings disappear, which deserves the same check; the guide to findings that disappeared after a refactor covers the code side of that question. When an upgrade arrives as a dependency bot's pull request, the guide to reviewing dependency bot pull requests covers what to check before merging it.