From da8540862dc6958868918ca694db0b2b8c6d8fc1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 8 May 2025 17:21:34 +0100 Subject: [PATCH] [ty] Make `unused-ignore-comment` disabled by default for now (#17955) --- .github/mypy-primer-ty.toml | 1 + crates/ruff_benchmark/benches/ty.rs | 8 +-- crates/ty/docs/rules.md | 60 +++++++++---------- ...__bases__`_lists_with_duplicate_bases.snap | 4 +- crates/ty_python_semantic/src/suppression.rs | 2 +- ty.schema.json | 2 +- 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/.github/mypy-primer-ty.toml b/.github/mypy-primer-ty.toml index 981f7d77c8..0e8e75303e 100644 --- a/.github/mypy-primer-ty.toml +++ b/.github/mypy-primer-ty.toml @@ -4,3 +4,4 @@ # Enable off-by-default rules. [rules] possibly-unresolved-reference = "warn" +unused-ignore-comment = "warn" diff --git a/crates/ruff_benchmark/benches/ty.rs b/crates/ruff_benchmark/benches/ty.rs index 65731e9a91..028a3e8563 100644 --- a/crates/ruff_benchmark/benches/ty.rs +++ b/crates/ruff_benchmark/benches/ty.rs @@ -59,13 +59,7 @@ type KeyDiagnosticFields = ( Severity, ); -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, -)]; +static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[]; fn tomllib_path(file: &TestFile) -> SystemPathBuf { SystemPathBuf::from("src").join(file.name()) diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 81162cb9ec..d5eab62611 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -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) -## `unused-ignore-comment` - -**Default level**: warn - -
-detects unused type: ignore comments - -### 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) -
- ## `possibly-unresolved-reference` **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) +## `unused-ignore-comment` + +**Default level**: ignore + +
+detects unused type: ignore comments + +### 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) +
+ diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Order_tests_-_`__bases__`_lists_with_duplicate_bases.snap b/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Order_tests_-_`__bases__`_lists_with_duplicate_bases.snap index efe5a34412..2b9a33d7f1 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Order_tests_-_`__bases__`_lists_with_duplicate_bases.snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/mro.md_-_Method_Resolution_Order_tests_-_`__bases__`_lists_with_duplicate_bases.snap @@ -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 | 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 | 79 | ): diff --git a/crates/ty_python_semantic/src/suppression.rs b/crates/ty_python_semantic/src/suppression.rs index dcccf57194..dc8713b988 100644 --- a/crates/ty_python_semantic/src/suppression.rs +++ b/crates/ty_python_semantic/src/suppression.rs @@ -33,7 +33,7 @@ declare_lint! { pub(crate) static UNUSED_IGNORE_COMMENT = { summary: "detects unused `type: ignore` comments", status: LintStatus::preview("1.0.0"), - default_level: Level::Warn, + default_level: Level::Ignore, } } diff --git a/ty.schema.json b/ty.schema.json index 96ff87a26f..1d3f6b6f44 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -813,7 +813,7 @@ "unused-ignore-comment": { "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```", - "default": "warn", + "default": "ignore", "oneOf": [ { "$ref": "#/definitions/Level"