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"