Skip to content

Commit

Permalink
Add invalid-ignore-comment rule (#15094)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Dec 23, 2024
1 parent 2835d94 commit 8d32708
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ a = 10 / 0 # knot: ignore[division-by-zero,]

```py
# error: [division-by-zero]
# error: [invalid-ignore-comment] "Invalid `knot: ignore` comment: expected a alphanumeric character or `-` or `_` as code"
a = 10 / 0 # knot: ignore[*-*]
```

Expand All @@ -138,9 +139,18 @@ future.

```py
# error: [unresolved-reference]
# error: [invalid-ignore-comment] "Invalid `knot: ignore` comment: expected a comma separating the rule codes"
a = x / 0 # knot: ignore[division-by-zero unresolved-reference]
```

## Missing closing bracket

```py
# error: [unresolved-reference] "Name `x` used when not defined"
# error: [invalid-ignore-comment] "Invalid `knot: ignore` comment: expected a comma separating the rule codes"
a = x / 2 # knot: ignore[unresolved-reference
```

## Empty codes

An empty codes array suppresses no-diagnostics and is always useless
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ a = test \

```py
# error: [unresolved-reference]
# error: [invalid-ignore-comment]
a = test + 2 # type: ignoree
```

Expand Down
3 changes: 2 additions & 1 deletion crates/red_knot_python_semantic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::hash::BuildHasherDefault;
use rustc_hash::FxHasher;

use crate::lint::{LintRegistry, LintRegistryBuilder};
use crate::suppression::{UNKNOWN_RULE, UNUSED_IGNORE_COMMENT};
use crate::suppression::{INVALID_IGNORE_COMMENT, UNKNOWN_RULE, UNUSED_IGNORE_COMMENT};
pub use db::Db;
pub use module_name::ModuleName;
pub use module_resolver::{resolve_module, system_module_search_paths, KnownModule, Module};
Expand Down Expand Up @@ -50,4 +50,5 @@ pub fn register_lints(registry: &mut LintRegistryBuilder) {
types::register_lints(registry);
registry.register_lint(&UNUSED_IGNORE_COMMENT);
registry.register_lint(&UNKNOWN_RULE);
registry.register_lint(&INVALID_IGNORE_COMMENT);
}
Loading

0 comments on commit 8d32708

Please sign in to comment.