Migrate to ruff

We've thought about migrating to ruff to replace many of our current cluster of linters for a while: mostly for speed, but we've also seen a bug in the unmaintained pydocstyle that would apparently be fixed that way.

Today I ran into another problem: I was going through loose ends from my patches to drop Python 3.11 support and tried to switch to the much nicer PEP 695 syntax for generics, but found that it confuses pydocstyle into thinking that anything using that syntax is undocumented.

I have most of a branch to switch to ruff. There are a few things worth discussing at least briefly first, because while it's possible to get pretty close to our current linting options, we can't have a perfect match.

  • There isn't really an equivalent of flake8-rst-docstrings. I'm inclined to chalk that up to "we don't care all that much", and ruff's docstring linting will most likely improve over time anyway.
  • U100 and U101 from flake8-unused-arguments are replaced by several ARG* codes. To avoid causing problems for people with flake8 editor integration, I suggest that we add appropriate noqa: ARG* suppressions alongside the existing noqa: U* (so we'd have noqa: ARG002, U100 or similar), and either let the noqa: U* suppressions wither naturally over time or remove them in bulk at some later date.
  • We can switch linting and formatting in different steps, and I think we should. ruff's formatter nearly matches black, but there are various intentional differences.
  • People with flake8/black/etc. editor integration might need to adjust slightly. I haven't really looked into the details yet, but ALE (for vim/neovim) supports ruff, so it shouldn't be too difficult and will probably be faster.
  • I'm inclined to do this in a few steps, first updating noqa comments and such, then adding the ruff linter and removing superseded linters, then switching to the ruff formatter.
  • Once we've switched, it will probably be worth seeing if there are any other rules we can enable to cheaply ratchet up our static analysis. There's quite an interesting menu.

Any other thoughts or objections?

Edited by Colin Watson
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information