Skip to content

build: broaden the ruff rule set and lint conanfile.py - #66

Merged
megabyde merged 1 commit into
mainfrom
build/broaden-ruff-rules
Jul 26, 2026
Merged

build: broaden the ruff rule set and lint conanfile.py#66
megabyde merged 1 commit into
mainfrom
build/broaden-ruff-rules

Conversation

@megabyde

Copy link
Copy Markdown
Owner

Problem

ruff.toml set only line-length, so ruff ran at its default E4,E7,E9,F while clang-tidy ran with
bugprone-*, misc-*, modernize-*, performance-*, and readability-* all as errors. Import
order, obsolete syntax, and common bug patterns went unchecked.

Separately, conanfile.py was neither linted nor formatted: PYTHON_SOURCES covered scripts/ only.

Fix

Select E,F,I,UP,B,SIM,RUF,ANN, and add conanfile.py to PYTHON_SOURCES. ruff format already
agrees with that file, so it brings no churn.

The trap, and why known-third-party is load-bearing

Enabling I naively makes the recipe worse. The repo's conan/ directory (it holds
settings_user.yml) shadows the conan package name, so isort's src detection classifies
from conan import ConanFile as first-party and splits it away from its siblings:

-from conan import ConanFile
 from conan.tools.build import check_min_cppstd
 from conan.tools.cmake import CMakeConfigDeps, CMakeToolchain, cmake_layout
 from conan.tools.files import load
+
+from conan import ConanFile

Confirmed by running the identical file in a scratch directory with and without a conan/ present:
without it ruff reports the imports already correct, with it ruff produces the split above.

known-third-party = ["conan"] restores the correct grouping, and as a result conanfile.py is
untouched by this PR. Flagging it because a future reader could reasonably delete that setting as
redundant.

Choices worth a second opinion

  • ANN is included. It already passes on scripts/, so it costs nothing today and keeps the
    existing annotations from rotting. Ignored for conanfile.py, whose methods are Conan callbacks
    reached through an untyped API. Happy to drop it.
  • RUF012 ignored for conanfile.py — it flags options / default_options and suggests
    ClassVar or __init__; neither applies, since Conan reads them off the class.
  • D (docstrings) left out — it wants 5 more docstrings on short helpers, which read as noise.

Verification

  • ruff check and ruff format --check clean over scripts/ and conanfile.py
  • make lint and make format-check both exit 0
  • conanfile.py byte-identical to main
  • recipe still functions: conan install exits 0 and conan inspect resolves version: 0.1.0, so
    set_version() still parses CMakeLists.txt
  • the only code change is rename.py's import block

Scope

Half of the test/lint-depth work item. The branch-coverage floor is not here: measuring it turned up
evidence that changes the recommendation, so it needs a decision rather than a quiet bundling.

ruff.toml set only line-length, leaving ruff at its default E4,E7,E9,F, so
import order, obsolete syntax, and common bug patterns went unchecked while
clang-tidy ran with nearly everything enabled. Select E,F,I,UP,B,SIM,RUF,ANN
so both languages are held to comparable standards. ANN already passes and
keeps the scripts' annotations from rotting.

conanfile.py was neither linted nor formatted, because PYTHON_SOURCES covered
scripts/ only. Add it. ruff format already agrees with the file, so this
brings no churn. RUF012 and ANN are ignored there: Conan reads options and
default_options off the recipe class, and calls its methods through an
untyped API.

known-third-party = ["conan"] is load-bearing rather than cosmetic. The
repository's conan/ directory shadows the package name, so isort's src
detection treats `from conan import ConanFile` as first-party and splits it
away from the conan.tools imports it belongs with. Confirmed by running the
same file in a directory with and without a conan/ present. Without this
setting, enabling I would reorder the recipe's imports and lock in the worse
grouping.

The only code change is rename.py's import block.
@megabyde
megabyde force-pushed the build/broaden-ruff-rules branch from db46a41 to 1334444 Compare July 26, 2026 06:05
@megabyde
megabyde merged commit b8436e0 into main Jul 26, 2026
15 checks passed
@megabyde
megabyde deleted the build/broaden-ruff-rules branch July 26, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant