Closed seisman closed 9 months ago
Opened a PR to replace flakeheaven
and isort
with ruff
at #2747, so that we can move ahead with the Python 3.12 support.
It should also be possible to replace pylint
with ruff
(see https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-pylint), which would:
make lint
(which is slow) from the Makefile (i.e. only have make check
and make format
)ruff
can actually automatically fix some pylint rules (see those marked with 🛠️ at https://docs.astral.sh/ruff/rules/#pylint-pl)So should we replace pylint
with ruff
? Vote :+1: for yes, :-1: for no. If everyone is generally in favour, we can open a PR after #2747 is merged.
So should we replace
pylint
withruff
?
Instead of replacing pylint
with ruff
, I think we can use both to see if there are any linting issues reported by pylint but not detected by ruff
. We can then decide if we want to remove pylint
before releasing v0.11.0. So I propose to have two separate PRs:
ruff
as a linting toolpylint
before v0.11.0ruff supports many groups of rules (https://docs.astral.sh/ruff/rules/). I think we should go through the available rules and apply the rules that make sense to our project.
ruff v0.1.8 provides the following linters/rules:
ruff linter | awk '{printf("- [ ] [`%s`](https://docs.astral.sh/ruff/rules/#%s-%s): %s\n"), $1, tolower($2), tolower($1), $2}'
F
: Pyflakes #2747E/W
: pycodestyle #2747C90
: mccabeI
: isort #2747N
: pep8-naming #2877D
: pydocstyleUP
: pyupgrade #2749YTT
: flake8-2020 #2878ANN
: flake8-annotationsASYNC
: flake8-asyncTRIO
: flake8-trioS
: flake8-bandit #2892BLE
: flake8-blind-except #2878FBT
: flake8-boolean-trapB
: flake8-bugbear #2825A
: flake8-builtins #2882COM
: flake8-commasCPY
: flake8-copyrightC4
: flake8-comprehensions #2887DTZ
: flake8-datetimezT10
: flake8-debuggerDJ
: flake8-djangoEM
: flake8-errmsgEXE
: flake8-executable #2898 FA
: flake8-future-annotations #2855ISC
: flake8-implicit-str-concat #2837ICN
: flake8-import-conventions #2878LOG
: flake8-loggingG
: flake8-logging-formatINP
: flake8-no-pep420PIE
: flake8-pie #2866T20
: flake8-print #2894PYI
: flake8-pyi.pyi
files]PT
: flake8-pytest-style #2899Q
: flake8-quotesruff format
already enforces consistent quote style. The rules are redundant]RSE
: flake8-raise #2878RET
: flake8-return #2897SLF
: flake8-selfSLOT
: flake8-slotsSIM
: flake8-simplify #2829TID
: flake8-tidy-imports #2878TCH
: flake8-type-checking #2878INT
: flake8-gettextARG
: flake8-unused-arguments #2900PTH
: flake8-use-pathlib [too many violations. Address #1834 first]TD
: flake8-todosFIX
: flake8-fixmeERA
: eradicatePD
: pandas-vet #2830PGH
: pygrep-hooks #2878PL
: Pylint #2815TRY
: tryceratopsFLY
: flynt #2835NPY
: NumPy-specific #2782AIR
: AirflowPERF
: Perflint #2886FURB
: refurb [preview only]RUF
: Ruff-specific #2901I've enabled ~32 rulesets that make sense to our project. Closing the issue now and we may revisit it in the feature if new ruff versions provide more rulesets.
- [ ]
FURB
: refurb [preview only]
I've been trying out some of these FURB
rules in preview by running ruff check . --statistics
, and got the following output at commit 41a0fe0a6a79849565348203737360855d40add8 (those marked with an asterisk * are automatically fixable):
ruff check . --statistics
16 PLR6201 [*] Use a `set` literal when testing for membership
15 PLC0415 [ ] `import` should be at the top-level of a file
15 PLW1514 [*] `pathlib.Path(...).open` in text mode without explicit `encoding` argument
8 E226 [*] Missing whitespace around arithmetic operator
4 S404 [ ] `subprocess` module is possibly insecure
3 PLR6104 [*] Use `+=` to perform an augmented assignment directly
3 FURB113 [*] Use `lines.extend(('WARNING:', f' {warnmsg}'))` instead of repeatedly calling `lines.append()`
2 PLC1901 [ ] `err == ""` can be simplified to `not err` as an empty string is falsey
2 PLW3201 [ ] Bad or misspelled dunder method name `_repr_html_`
1 PLR0904 [ ] Too many public methods (30 > 20)
1 PLR0917 [ ] Too many positional arguments (11/10)
1 PLW0108 [*] Lambda may be unnecessary; consider inlining inner function
1 RUF027 [*] Possible f-string without an `f` prefix
Thinking of applying PLR6201
and maybe PLW1514
, does that sound ok?
Sounds good.
It seems ruff has been very hot recently. The README says it can replace flake8 and pylint, and more importantly, it's 10-100x faster.
Someone interested may try it and tell us how it works for the PyGMT project.