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.
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"]
That’s right, hoelzeli, but something missing from the Ruff documentation is that you can also use a comma-delimited pattern to negate specific filenames.
For example, instead of negating all of src/**.py you can negate just two files like this:
"!src/{foo.py,bar.py}" = ["D"]
This is the only solution that works for me because it does not tolerate multiple separate negate patterns for the same lint rule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With