godot icon indicating copy to clipboard operation
godot copied to clipboard

Replace `black` formatter with `ruff`

Open Chubercik opened this issue 10 months ago • 3 comments

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)>

Chubercik avatar Apr 10 '24 00:04 Chubercik

Messed up SCons pretty badly, will tend to that tomorrow.. 😪

Chubercik avatar Apr 10 '24 01:04 Chubercik

You used a merge commit to update your branch, please use rebase in the future instead, see here

AThousandShips avatar Apr 10 '24 18:04 AThousandShips

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 avatar Apr 10 '24 21:04 Repiteo

@Repiteo's changes/additions lgtm!

will's son

Chubercik avatar May 21 '24 20:05 Chubercik

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.

Calinou avatar May 21 '24 22:05 Calinou

Thanks!

akien-mga avatar May 22 '24 07:05 akien-mga

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).

bruvzg avatar Jun 03 '24 10:06 bruvzg