Uh oh!
There was an error while loading. Please reload this page.
chore: add clang-format + codespell lint gate - #48
Merged
Conversation
balbastyforce-pushed
the
claude/18-cpp-lint-format
branch
from
August 1, 2026 20:15
abb3c49 to
cc6184eCompareThe six C++/CUDA repos had no formatting, lint or spell-check configuration of any kind, while the five Python repos have run ruff + codespell since they were created (fastfields-lib#18, item D6). Adds, identically across all six C++ repos: * `.clang-format` -- derived from the code that is already here rather than taken off the shelf: 4-space indent (the dominant indent level in every repo), an 80-column limit (the p90 line length is 68-78), `T * p` / `T & r` middle alignment, function braces on their own line with control-flow braces attached, and `CUDEV`/`CUGLOB`/`CUHOST` declared as attribute macros so clang-format stops parsing them as return types. * `.codespellrc` -- the same checks the Python repos run, with the project's domain vocabulary (`nd`, `numer`, `mone`, the `t<name>` DLTensor locals, M. Unser) allow-listed and the vendored `dlpack.h` skipped. * `.github/workflows/lint.yaml` -- codespell (blocking, pinned to the same 2.4.3 the reusable python-lint.yml pins) plus a clang-format check. The clang-format check is scoped to the lines a pull request touches (`git clang-format --diff <merge-base>`) rather than the whole tree. The tree predates the config and is hand-column-aligned in many places, so a whole-tree `--dry-run --Werror` flags essentially every file; gating on that would mean either a permanently red main or a mass reformat bundled into an unrelated change. Diff-scoped checking makes new and modified code conform from now on and leaves the one-shot reformat as its own reviewable PR. No source file is reformatted here. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AjQcY78NgbagPSbPJRr6Z
balbastyforce-pushed
the
claude/18-cpp-lint-format
branch
from
August 1, 2026 20:32
cc6184e to
9515880CompareUh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #18 — item D6, "No C++ lint/format/codespell". The five Python
repos have run
ruff+codespellsince they were created; none of the sixC++/CUDA repos had a
.clang-format, a.clang-tidyor any spell-check.This is one of six identical PRs, one per C++ repo (
fastfields-kernels,-cpu-impl,-cuda-impl,-cpu-lib,-cuda-lib,-lib). The three filesadded are byte-identical across all six.
What this adds
.clang-format— derived from the code that is already here, notpicked off the shelf. I measured the tree before choosing anything:
4-space is the dominant indent level in every repo (including
kernels,where a handful of files such as
distance/l1.hare 2-space outliers), thep90 line length is 68–78 so the column limit is 80, and the code
consistently spells pointers/references
scalar_t * f/DLTensor & out(
PointerAlignment: Middle). Function braces go on their own line withcontrol-flow braces attached (
BreakBeforeBraces: Stroustrup), matching theexisting sources.
CUDEV/CUGLOB/CUHOSTare declared asAttributeMacrosso clang-format stops parsing them as a return type and mangling the
signature that follows, and
FF_NAMESPACE_BEGIN/_ENDasStatementMacros..codespellrc— the same check the Python repos run, with thisproject's vocabulary allow-listed (
ndfor N-dimensional,numer/denom,monefor the literal −1, thet<name>DLTensor locals in the C++ tests,unserfor M. Unser of the cited B-spline papers, …) and the vendoreddlpack.hskipped..github/workflows/lint.yaml— a thin, self-contained per-repo workflowalongside the existing
test.yaml, matching the shape of the Python repos'lint.yaml: a blockingcodespelljob pinned to the same 2.4.3 thatfastfields/.github's reusablepython-lint.ymlpins, plus aclang-formatjob. Both carry theconcurrencygroup andtimeout-minutesthe other C++ gates already have.No source file is reformatted in this PR.
Honest note: the clang-format check is diff-scoped, not whole-tree
The task asked for
clang-format --dry-run --Werrorover the tracked files,and asked me to confirm it passes before opening the PR. It does not pass,
and no configuration can make it pass. I measured this rather than assuming
it — with the config in this PR,
clang-formatwould rewrite:fastfields-kernelsfastfields-cpu-implfastfields-cuda-implfastfields-cpu-libfastfields-cuda-libfastfields-libStock LLVM/Google styles are worse (≈89 k changed lines each); the config here
is the best fit I could find (≈63 k). The residual is irreducible: much of the
code is hand column-aligned —
DLTensor & out ,in the parameterlists, the backslash-aligned dispatch macro blocks — which clang-format cannot
reproduce by design.
So the whole-tree gate had exactly two possible outcomes, and CONTRIBUTING.md
rules out both: a permanently red
main, or a mass reformat bundled into atooling PR ("never bundle"). The workflow therefore checks only the lines a
pull request actually touches, via
git clang-format --diff <merge-base>— the incremental-adoption pattern LLVMitself uses. New and modified code conforms from now on; the one-shot reformat
stays available as its own reviewable change.
Verification
codespellexits 0 in this repo with the committed.codespellrc(checked with the pinned 2.4.3, the same version CI installs).
and prints
no modified files to format— this PR passes its own gate.void ff_fmt_probe ( int*x ){if(x){*x=1 ;}}toposdef.cppand re-runningthe exact CI command produced a failing diff proposing
void ff_fmt_probe(int * x)with the brace on its own line andint * xspacing — i.e. it enforces the project's real style on new lines while
leaving the untouched legacy lines in the same file alone. (Probe reverted;
not in the diff.)
clang-format 18; the workflow pinsclang-format-18so formatting cannot drift with the runner image.Workstream: claude-jitfields-to-fastfields
🤖 Generated with Claude Code
Generated by Claude Code