Skip to content

Introduce pre-commit hooks (ruff + clang-format) - #239

Open
jonasleitner wants to merge 12 commits into
masterfrom
pre-commit
Open

Introduce pre-commit hooks (ruff + clang-format)#239
jonasleitner wants to merge 12 commits into
masterfrom
pre-commit

Conversation

@jonasleitner

@jonasleitner jonasleitner commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This PR sets up pre-commit for automatic linting and formatting using ruff (python) and clang-format (C++) and applies the hook to the code base. Therefore most of the changes introduced were automatically generated by ruff or clang-format.

Configuration

  • The line length for the python code was increased to 100 (previously 84), since I feel that 84 (or the ruff default 88) are often a bit short. This choice also decreased the number of ruff errors requiring manual fixes (see below).
  • The rules for ruff are not configured and thus the default set of rules is applied, which might change in future ruff versions.
  • The ruff and clang-format versions are pinned in the pre-commit configuration. They can be updated by running pre-commit autoupdate, which should be done every now and then. Note that every version update will probably require a (hopefully smaller!) PR similar to this one to apply the new rules and reformat the code base.
  • Formatting and linting in the CI and the stub file generation consistently use the pre-commit hook.

While this PR contains mostly changes introduced by ruff and clang-format, a few commits involved manual changes:

  • dd556fd: Setup and configuration of the pre-commit hook and its incorporation in the CI.
  • f012cb7: Fixing circular imports introduced by the automatic reordering of python imports.
  • a8c067d: Mostly generated by ruff but I adjusted like 1-2 of the unsafe fixes.
  • ad95a97: Manually fix the remaining like 160 ruff errors (mostly shebangs in non-executable files).
  • e6fec68: I added fmt: skip comments to avoid the reformatting of already nicely formatted equations. Probably I missed some places here...

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