godot
godot copied to clipboard
Replace `black` formatter with `ruff`
This PR replaces black
static checking suite with ruff
.
It's a pretty big change, and I understand it warrants discussion, which I welcome and look forward to.
The basic premise of this change is that the ruff
linter and formatter is slowly creeping its way to becoming the new standard - more importantly, it promises orders of magnitude better performance than previously available solutions.
If this is a welcome change we might want to also update Godot's code style guidelines doc entry.
From ruff
's README file:
- 10-100x faster than existing linters (like Flake8) and formatters (like Black)
- Installable via
pip
-
pyproject.toml
support - Python 3.12 compatibility
- Drop-in parity with Flake8, isort, and Black
- Built-in caching, to avoid re-analyzing unchanged files
- Fix support, for automatic error correction (e.g., automatically remove unused imports)
- Over 800 built-in rules, with native re-implementations of popular Flake8 plugins, like flake8-bugbear
- First-party editor integrations for VS Code and more
- Monorepo-friendly, with hierarchical and cascading configuration
Local usage ought to be similar to that of black
:
pip3 install ruff --user
ruff -l 120 <path/to/file(s)>
Messed up SCons
pretty badly, will tend to that tomorrow.. 😪
You used a merge commit to update your branch, please use rebase in the future instead, see here
Holy hell, ruff is making an insanely good first impression! A linter/formatter that has the capability of recognizing SConstruct in editor without major tweaking is amazing. VSCode can even recognize a .ruff.toml
file natively, so local formatting can actually occur right out of the box. When you have the chance, be sure to add a .ruff.toml
to the repo root with this content:
extend-exclude = ["thirdparty"]
extend-include = ["SConstruct", "SCSub"]
line-length = 120
target-version = "py38"
@Repiteo's changes/additions lgtm!
Tested locally, it works as expected.
I suggest adding this in pyproject.toml
(after the [tool.ruff]
section) to enable isort functionality in ruff check --fix
(note that this does not affect ruff format
):
[tool.ruff.lint]
extend-select = [
"I", # isort
]
This way, contributors won't need to install isort separately anymore.
Thanks!
This is causing issues on macOS, since the downloaded ruff
binary is ~unsigned~unnotarized and can't run (it's fixable by removing the quarantine flag or re-signing it manually, but pretty annoying).