ruff
ruff copied to clipboard
Respect pylint ignore directives
It would be really cool for a codebase moving from pylint slowly to ruff to be able to understand and respect pylint directives.
For example ARG
module has flake8-unused-arguments. That is very similar to something pylint does. And as usual if somewhere you want to disable the warning you can add the proper pylint directive. For this it would be # pylint: disable=unused-argument
.
It would be cool if ruff understood those directives even for other modules like flake8-unused-arguments which do the same thing.
+1 for this feature
I think there are two pieces here:
- Supporting Pylint directives for rules that are mapped explicitly to existing Pylint rules (anything in
PLR
,PLC
, etc.). - Supporting Pylint directives for rules that aren't currently mapped, but have analogs.
I'm open to supporting (1), but it does require a decent amount of work, since Pylint provides a lot of flexibility in where enables and disables are placed (scopes, blocks, single lines, etc.).
(Unrelated to this issue, but I do eventually want to add Ruff's own system for ignores that's decoupled from Flake8 (while continuing to support Flake8's noqa
), and that system would definitely support multi-line ignores.)
I'm hesitant to support (2). It feels hard to get right, since it requires that (e.g.) we're reporting errors on the exact same lines.
I guess (1) is already good enough.
For (2) there is some easy wins. For example at rotki we disable the ruff "BLE" check due to also running pylint with that check on and ruff not respecting/seeing the ignores.
In the case of replacing pylint entirely with ruff, there could simply be a rule RUFF9XX that detects pylint directives, and as autofix removes them. This could be simple to implement and helpful to start. When explicit mapping is available, the fix could be changed to use flake8 or ruff directives.
A fixer which transforms the pylint-comments into ruff noqa-comments would be helpful.
-# pylint: disable-msg=R0133
+# noqa: PLR0133
+1
+1 here as well
A fixer which transforms the pylint-comments into ruff noqa-comments would be helpful.
-# pylint: disable-msg=R0133 +# noqa: PLR0133
Pylint disable support rule names. Without rule names, this lowers the value of the waiver comment.
-# pylint: disable=comparison-of-constants +# noqa: PLR0133
After this transformation the next person arriving at the code will not easily understand why the disable is there.
After ruff adopts #1773 "human-friendly rules names", this transformation feels more attractive.