Setting up Ruff (Python Linter)

839 views Asked by At

As far as I understood ruff implements pycodestyle rules by default. However, when I run my code through pycodestyle I get:

test.py:5:1: E302 expected 2 blank lines, found 1
test.py:8:1: E302 expected 2 blank lines, found 1
test.py:13:9: E129 visually indented line with same indent as next logical line
test.py:22:1: E305 expected 2 blank lines after class or function definition, found 1
test.py:32:5: E265 block comment should start with '# '
test.py:34:5: E265 block comment should start with '# '
test.py:43:14: W292 no newline at end of file

While ruff gives me all good.

Anyone can tell me why that is the case?

3

There are 3 answers

0
Samuel Rodríguez On

It is finally merged. You just have to enable the preview flag

Just add this to your .toml file

[tool.ruff.lint]
preview = true
0
Bekzod On

As it says in documentation:

By default, Ruff enables Flake8's F rules, along with a subset of the E rules

To capture all pydocstyle rules (E, W), you should configure ruff in pyproject.toml as follows:

[tool.ruff.lint]
extend-select = ["W", "E"]
preview = true
0
MAKI On

As for 09.09.23, merge request for errors E301-6 is not approved yet. Same thing for other errors by pycodestyle.

You can check errors that are handled by ruff here.