From 133444464a8db37ba4b2d669c0c758ecfb43b4c8 Mon Sep 17 00:00:00 2001 From: Yury Bayda Date: Sat, 25 Jul 2026 22:57:09 -0700 Subject: [PATCH] build: broaden the ruff rule set and lint conanfile.py 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. --- Makefile | 3 ++- README.md | 15 ++++++++++----- ruff.toml | 19 +++++++++++++++++++ scripts/rename.py | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 23b61ef..82ed179 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,8 @@ TIDY_SOURCES = $(shell find src tests -type f -name '*.cpp') # Conan's, not prettier's. PRETTIER_SOURCES = $(shell git ls-files '*.md' '*.json' '*.yml' '*.yaml' ':!conan.lock') MARKDOWN_SOURCES = $(shell git ls-files '*.md') -PYTHON_SOURCES = scripts/ +# Lint and format conanfile.py alongside the first-party Python scripts +PYTHON_SOURCES = scripts/ conanfile.py define require-tool command -v $(1) >/dev/null || $(DIE) "$(1) not found" diff --git a/README.md b/README.md index d0e8543..efed6af 100644 --- a/README.md +++ b/README.md @@ -221,15 +221,20 @@ make lint ``` `make format` and `make format-check` cover C++ sources (clang-format), `CMakeLists.txt` -(cmake-format, from the [cmakelang](https://cmake-format.readthedocs.io) package), Python scripts -([ruff](https://docs.astral.sh/ruff/) format), and tracked Markdown/JSON/YAML files -([prettier](https://prettier.io); `conan.lock` is excluded because Conan owns its formatting). -`make lint` runs clang-tidy against the debug compilation database, `cmake-lint` on -`CMakeLists.txt`, `ruff check` on `scripts/`, and +(cmake-format, from the [cmakelang](https://cmake-format.readthedocs.io) package), Python sources in +`scripts/` and `conanfile.py` ([ruff](https://docs.astral.sh/ruff/) format), and tracked +Markdown/JSON/YAML files ([prettier](https://prettier.io); `conan.lock` is excluded because Conan +owns its formatting). `make lint` runs clang-tidy against the debug compilation database, +`cmake-lint` on `CMakeLists.txt`, `ruff check` on those Python sources, and [markdownlint](https://github.com/DavidAnson/markdownlint-cli2) on Markdown files. Any reported finding fails the target. CI pins all lint and format tool versions in [`.github/ci.env`](.github/ci.env). +[`ruff.toml`](ruff.toml) extends Ruff's `E4`, `E7`, `E9`, and `F` defaults to all `E` checks, then +adds import ordering (`I`), Python modernization (`UP`), likely bugs (`B`), simplification (`SIM`), +Ruff-specific rules (`RUF`), and annotations (`ANN`). As with `.clang-tidy`, every finding fails the +lint target. + ## Coverage Build, test, and generate an HTML coverage report with an enforced line floor: diff --git a/ruff.toml b/ruff.toml index 9a0c900..2855294 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,3 +1,22 @@ # 100 columns, matching the repo-wide convention (.clang-format, .cmake-format.yaml, and # .editorconfig/markdownlint all use 100); ruff's default is 88. line-length = 100 + +[lint] +# Ruff enables E4, E7, E9, and F by default. Add all E checks plus import ordering, Python +# modernization, likely bugs, simplification, Ruff-specific rules, and annotations. As with +# clang-tidy, every finding is an error. ANN keeps existing type annotations complete. +select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "ANN"] + +[lint.isort] +# The local conan/ directory contains settings_user.yml, but its name shadows the third-party conan +# package. isort's source detection therefore classifies `from conan import ConanFile` as +# first-party and separates it from the conan.tools imports. Mark the package as third-party +# explicitly. +known-third-party = ["conan"] + +[lint.per-file-ignores] +# Conan reads the recipe's options and default_options class attributes as dictionaries, so +# RUF012's ClassVar/__init__ guidance does not apply. Conan also invokes recipe methods through an +# untyped callback API, where the annotations required by ANN would add no useful information. +"conanfile.py" = ["RUF012", "ANN"] diff --git a/scripts/rename.py b/scripts/rename.py index dbaffd3..8d9b109 100755 --- a/scripts/rename.py +++ b/scripts/rename.py @@ -12,11 +12,11 @@ from __future__ import annotations import argparse -from pathlib import Path import re import shutil import subprocess import sys +from pathlib import Path OLD_SNAKE = "cpp_boilerplate" OLD_KEBAB = "cpp-boilerplate"