Linter and Formatter
Enforces a consistent coding style across the project, and catches bugs before they come. To do so, we use Ruff.
The Ruff Linter
The linter is a program which will raise errors if your code does not respect the rules defined in the config.
To check all the backend code, run:
pipenv run lint
The linter is run in real-time in VScode, if you have the Ruff extension installed. It will show the errors directly in the editor, and propose a fix for some of them.
If you want to add an exception (for example when the linter raises an error that is impossible to fix), you can ignore that error by adding a comment with the error code:
my_variable = 1 # noqa: F001
You can also ignore an error for the entire file:
# ruff: noqa: F001
Ruff is a re-implementation of Flake8 in Rust, allowing faster linting and also proposing auto-fixing. You can fix the fixable errors by running:
pipenv run lint:fix
Each error has a unique code, composed of a letter (which indicates which plugin of Flake8 raised the error) and a number. You can find the list of all errors here, or by clicking on the error code in the VScode editor.
The configuration of the selected rules are stored in the pyproject.toml
file.
The Ruff Formatter
The Ruff formatter is based on black
, a program which will automatically
format your code to respect the rules defined in the config. It will be executed
by running:
pipenv run lint:fix
Or by saving your file in VSCode, if you have the Ruff extension installed.