[`ruff`] Use `DiagnosticTag` for more pyupgrade rules (#20734)

This commit is contained in:
Takayuki Maeda 2025-10-08 13:52:43 +09:00 committed by GitHub
parent 5d3a35e071
commit abbbe8f3af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 0 deletions

View File

@ -43,6 +43,7 @@ where
T: Ranged,
{
let mut diagnostic = checker.report_diagnostic(DeprecatedCElementTree, node.range());
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
let contents = checker.locator().slice(node);
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
contents.replacen("cElementTree", "ElementTree", 1),

View File

@ -265,6 +265,7 @@ pub(crate) fn deprecated_mock_attribute(checker: &Checker, attribute: &ast::Expr
},
attribute.value.range(),
);
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
"mock".to_string(),
attribute.value.range(),
@ -313,6 +314,7 @@ pub(crate) fn deprecated_mock_import(checker: &Checker, stmt: &Stmt) {
},
name.range(),
);
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
if let Some(content) = content.as_ref() {
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
content.clone(),
@ -351,6 +353,7 @@ pub(crate) fn deprecated_mock_import(checker: &Checker, stmt: &Stmt) {
},
stmt.range(),
);
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
if let Some(indent) = indentation(checker.source(), stmt) {
diagnostic.try_set_fix(|| {
format_import_from(stmt, indent, checker.locator(), checker.stylist())

View File

@ -98,6 +98,7 @@ pub(crate) fn deprecated_unittest_alias(checker: &Checker, expr: &Expr) {
},
expr.range(),
);
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
format!("self.{target}"),
expr.range(),

View File

@ -68,6 +68,7 @@ pub(crate) fn replace_universal_newlines(checker: &Checker, call: &ast::ExprCall
};
let mut diagnostic = checker.report_diagnostic(ReplaceUniversalNewlines, arg.range());
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
if call.arguments.find_keyword("text").is_some() {
diagnostic.try_set_fix(|| {

View File

@ -57,6 +57,7 @@ pub(crate) fn typing_text_str_alias(checker: &Checker, expr: &Expr) {
.is_some_and(|qualified_name| matches!(qualified_name.segments(), ["typing", "Text"]))
{
let mut diagnostic = checker.report_diagnostic(TypingTextStrAlias, expr.range());
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
diagnostic.try_set_fix(|| {
let (import_edit, binding) = checker.importer().get_or_import_builtin_symbol(
"str",