-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
ruff is an extremely fast linter for Python written in Rust, and a drop-in replacement for flake8.
Before I'm going to open a PR, I'd like to discuss this first.
Ruff is still in its early development, but I don't see a problem switching to it already, especially because some big/popular Python projects have already shifted towards it (see the links above).
The main benefits of switching are
- it's very fast, with support for caching (not too relevant for Streamlink though)
- its migration is very easy compared to other linters like Black
- it's compatible with the default Black config (except for the line-length)
- it has near identical rule sets compared to flake8 (= pyflakes + pycodestyle)
- it has lots of rules from various other linters and flake8 plugins built in, e.g.
- isort (its rules are slightly different from the currently used flake8-import-order plugin with the pycharm profile)
- flake8-commas
- flake8-quotes
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
- there's no mandatory ini-config nonsense and its config is defined in pyproject.toml, where it belongs
- rules with auto-fix upgrades can be added gradually, which is very much preferred when transitioning and cleaning up old code
- various editor integrations are available
Potential concerns
- installing binary wheels (or compiling its Rust code from source) is required, but wheels are all available on PyPI, so installing on any platform is not an issue at all (none of that is relevant for packagers though)
- it doesn't have a plugin system (yet), but it's not relevant for Streamlink anyway and also not necessary
- some upstream configs from built-in plugins are not available yet, resulting in a slightly different code-style that can't be adjusted
So if I was going to open a PR with a replacement for flake8, I would very much like to also fix some still outstanding style issues with Streamlink's code base, namely:
- enforce double quotes everywhere
- enforce trailing commas everywhere
- set the number of empty lines after import statements to 2 (the default is 1, but it's stupid, considering that functions and classes on the global module scope must be separated by 2 lines)
- maybe also pep8-naming conventions, but I'm not sure about that yet
I would submit the automated changes in a separate PR though (for the sake of readability of the first PR's diff) and probably add the resulting commit IDs after the merge to .git-blame-ignore-revs in a third PR, maybe also with other automated major code-style-altering commits from the past:
Other linter rules with "non-trivial" code-improvement changes, like flake8-bugbear, flake8-comprehensions or flake8-simplify can be added later on.
Things that will be kept from the current flake8 config is the line length of 128 instead of the default 88.
Ruff does support PR diff annotations for errors/warnings via --format=github. That could be added and explored, but it probably would be a bit messy if someone submits a PR with lots of code-style issues.
- init: replace flake8 with ruff and add basic config
tools: replace flake8 with ruff #5149 - rules with trivial changes: Add missing "I" rules (isort), add "Q" (quotes) and "COM" (commas) rules
chore: add "I", "TID", "Q", and "COM" rules to ruff config #5150 - git blame: ignore commits of previous step in
.git-blame-ignore-revs
tools: add .git-blame-ignore-revs #5154 - CI: take a look at GitHub annotations
- more rules: with minor code refactorings
chore: add "C4" and "ISC" rules to ruff config #5153