ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Respect pylint ignore directives

Open LefterisJP opened this issue 2 years ago • 5 comments

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.

LefterisJP avatar Dec 11 '22 23:12 LefterisJP

+1 for this feature

joshuachapnick-bc avatar Jan 02 '23 13:01 joshuachapnick-bc

I think there are two pieces here:

  1. Supporting Pylint directives for rules that are mapped explicitly to existing Pylint rules (anything in PLR, PLC, etc.).
  2. 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.

charliermarsh avatar Jan 17 '23 12:01 charliermarsh

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.

LefterisJP avatar Jan 17 '23 13:01 LefterisJP

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.

sbrugman avatar Jan 24 '23 23:01 sbrugman

A fixer which transforms the pylint-comments into ruff noqa-comments would be helpful.

-# pylint: disable-msg=R0133
+# noqa: PLR0133

spaceone avatar Jan 30 '23 15:01 spaceone

+1

coby-soffer avatar May 06 '23 21:05 coby-soffer

+1 here as well

StefanKX avatar Jan 16 '24 06:01 StefanKX

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.

kaddkaka avatar Feb 27 '24 09:02 kaddkaka