Support negated patterns in [extend-]per-file-ignores (#10852)

Fixes #3172 

## Summary

Allow prefixing [extend-]per-file-ignores patterns with `!` to negate
the pattern; listed rules / prefixes will be ignored in all files that
don't match the pattern.

## Test Plan

Added tests for the feature.

Rendered docs and checked rendered output.
This commit is contained in:
Carl Meyer 2024-04-09 21:53:41 -06:00 committed by GitHub
parent 42d52ebbec
commit 02e88fdbb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 130 additions and 19 deletions

View file

@ -905,7 +905,8 @@ pub struct LintCommonOptions {
// Tables are required to go last.
/// A list of mappings from file pattern to rule codes or prefixes to
/// exclude, when considering any matching files.
/// exclude, when considering any matching files. An initial '!' negates
/// the file pattern.
#[option(
default = "{}",
value_type = "dict[str, list[RuleSelector]]",
@ -914,6 +915,8 @@ pub struct LintCommonOptions {
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
# Ignore `D` rules everywhere except for the `src/` directory.
"!src/**.py" = ["F401"]
"#
)]
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,