[ty] Make `unused-ignore-comment` disabled by default for now (#17955)

This commit is contained in:
Alex Waygood 2025-05-08 17:21:34 +01:00 committed by GitHub
parent 6a5533c44c
commit da8540862d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 41 deletions

View File

@ -4,3 +4,4 @@
# Enable off-by-default rules. # Enable off-by-default rules.
[rules] [rules]
possibly-unresolved-reference = "warn" possibly-unresolved-reference = "warn"
unused-ignore-comment = "warn"

View File

@ -59,13 +59,7 @@ type KeyDiagnosticFields = (
Severity, Severity,
); );
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[( static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[];
DiagnosticId::lint("unused-ignore-comment"),
Some("/src/tomllib/_parser.py"),
Some(22299..22333),
"Unused blanket `type: ignore` directive",
Severity::Warning,
)];
fn tomllib_path(file: &TestFile) -> SystemPathBuf { fn tomllib_path(file: &TestFile) -> SystemPathBuf {
SystemPathBuf::from("src").join(file.name()) SystemPathBuf::from("src").join(file.name())

View File

@ -1495,36 +1495,6 @@ a = 20 / 0 # ty: ignore[division-by-zero]
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Fsuppression.rs#L40) * [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Fsuppression.rs#L40)
</details> </details>
## `unused-ignore-comment`
**Default level**: warn
<details>
<summary>detects unused <code>type: ignore</code> comments</summary>
### What it does
Checks for `type: ignore` or `ty: ignore` directives that are no longer applicable.
### Why is this bad?
A `type: ignore` directive that no longer matches any diagnostic violations is likely
included by mistake, and should be removed to avoid confusion.
### Examples
```py
a = 20 / 2 # ty: ignore[division-by-zero]
```
Use instead:
```py
a = 20 / 2
```
### Links
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unused-ignore-comment)
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Fsuppression.rs#L15)
</details>
## `possibly-unresolved-reference` ## `possibly-unresolved-reference`
**Default level**: ignore **Default level**: ignore
@ -1552,3 +1522,33 @@ print(x) # NameError: name 'x' is not defined
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L836) * [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L836)
</details> </details>
## `unused-ignore-comment`
**Default level**: ignore
<details>
<summary>detects unused <code>type: ignore</code> comments</summary>
### What it does
Checks for `type: ignore` or `ty: ignore` directives that are no longer applicable.
### Why is this bad?
A `type: ignore` directive that no longer matches any diagnostic violations is likely
included by mistake, and should be removed to avoid confusion.
### Examples
```py
a = 20 / 2 # ty: ignore[division-by-zero]
```
Use instead:
```py
a = 20 / 2
```
### Links
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unused-ignore-comment)
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Fsuppression.rs#L15)
</details>

View File

@ -345,7 +345,7 @@ info: `lint:duplicate-base` is enabled by default
``` ```
``` ```
warning: lint:unused-ignore-comment info: lint:unused-ignore-comment
--> src/mdtest_snippet.py:72:9 --> src/mdtest_snippet.py:72:9
| |
70 | A, 70 | A,
@ -388,7 +388,7 @@ info: `lint:duplicate-base` is enabled by default
``` ```
``` ```
warning: lint:unused-ignore-comment info: lint:unused-ignore-comment
--> src/mdtest_snippet.py:81:13 --> src/mdtest_snippet.py:81:13
| |
79 | ): 79 | ):

View File

@ -33,7 +33,7 @@ declare_lint! {
pub(crate) static UNUSED_IGNORE_COMMENT = { pub(crate) static UNUSED_IGNORE_COMMENT = {
summary: "detects unused `type: ignore` comments", summary: "detects unused `type: ignore` comments",
status: LintStatus::preview("1.0.0"), status: LintStatus::preview("1.0.0"),
default_level: Level::Warn, default_level: Level::Ignore,
} }
} }

View File

@ -813,7 +813,7 @@
"unused-ignore-comment": { "unused-ignore-comment": {
"title": "detects unused `type: ignore` comments", "title": "detects unused `type: ignore` comments",
"description": "## What it does\nChecks for `type: ignore` or `ty: ignore` directives that are no longer applicable.\n\n## Why is this bad?\nA `type: ignore` directive that no longer matches any diagnostic violations is likely\nincluded by mistake, and should be removed to avoid confusion.\n\n## Examples\n```py\na = 20 / 2 # ty: ignore[division-by-zero]\n```\n\nUse instead:\n\n```py\na = 20 / 2\n```", "description": "## What it does\nChecks for `type: ignore` or `ty: ignore` directives that are no longer applicable.\n\n## Why is this bad?\nA `type: ignore` directive that no longer matches any diagnostic violations is likely\nincluded by mistake, and should be removed to avoid confusion.\n\n## Examples\n```py\na = 20 / 2 # ty: ignore[division-by-zero]\n```\n\nUse instead:\n\n```py\na = 20 / 2\n```",
"default": "warn", "default": "ignore",
"oneOf": [ "oneOf": [
{ {
"$ref": "#/definitions/Level" "$ref": "#/definitions/Level"