Enable ruff rules only on specific files
Asked Answered
E

1

6

I work on a large project and I'd slowly like to enfore pydocstyle using ruff. However, many files will fail on e.g. D103 "undocumented public function". I'd like to start with enforcing it on a few specific files, so I'd like to write something like

select = ["D"]

[tool.ruff.ignore-except-per-file] # this config does not exist
# ignore D103 but on all files, except the ones that pass
"properly_formatted_module1.py" = ["D103"]
"properly_formatted_module2.py" = ["D103"]

I don't think this is possible; the only way I see is to explicitly write down ALL of the file names in a [tool.ruff.extend-per-file-ignores]. There are a few hunderd of them so that's not really nice to do.

Euripides answered 20/1 at 17:31 Comment(1)
Had the same question. We have a Kubeflow project with certain restrictions around imports in certain functions. I constantly violate them on accident. This lint would be really helpfulStarobin
P
3

You can invert the file selection in the (extend-)per-file-ignores section to ignore for example D103 on all files except the ones that do match the pattern.

from the Ruff documentation for the per-file-ignores:

A list of mappings from file pattern to rule codes or prefixes to exclude, when considering any matching files. An initial '!' negates the file pattern.

And the corresponding example in a pyproject.toml:

# Ignore `D` rules everywhere except for the `src/` directory.
"!src/**.py" = ["D"]
Perpend answered 20/6 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.