mirror of https://github.com/astral-sh/ruff
[`ruff`] Use DiagnosticTag for more flake8 and numpy rules (#20758)
This commit is contained in:
parent
9b9c9ae092
commit
f715d70be1
|
|
@ -1091,9 +1091,12 @@ fn suspicious_function(
|
|||
] => checker.report_diagnostic_if_enabled(SuspiciousInsecureCipherModeUsage, range),
|
||||
|
||||
// Mktemp
|
||||
["tempfile", "mktemp"] => {
|
||||
checker.report_diagnostic_if_enabled(SuspiciousMktempUsage, range)
|
||||
}
|
||||
["tempfile", "mktemp"] => checker
|
||||
.report_diagnostic_if_enabled(SuspiciousMktempUsage, range)
|
||||
.map(|mut diagnostic| {
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
diagnostic
|
||||
}),
|
||||
|
||||
// Eval
|
||||
["" | "builtins", "eval"] => {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ pub(crate) fn bytestring_attribute(checker: &Checker, attribute: &Expr) {
|
|||
["collections", "abc", "ByteString"] => ByteStringOrigin::CollectionsAbc,
|
||||
_ => return,
|
||||
};
|
||||
checker.report_diagnostic(ByteStringUsage { origin }, attribute.range());
|
||||
let mut diagnostic = checker.report_diagnostic(ByteStringUsage { origin }, attribute.range());
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
}
|
||||
|
||||
/// PYI057
|
||||
|
|
@ -94,7 +95,9 @@ pub(crate) fn bytestring_import(checker: &Checker, import_from: &ast::StmtImport
|
|||
|
||||
for name in names {
|
||||
if name.name.as_str() == "ByteString" {
|
||||
let mut diagnostic =
|
||||
checker.report_diagnostic(ByteStringUsage { origin }, name.range());
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -898,7 +898,9 @@ fn check_test_function_args(checker: &Checker, parameters: &Parameters, decorato
|
|||
/// PT020
|
||||
fn check_fixture_decorator_name(checker: &Checker, decorator: &Decorator) {
|
||||
if is_pytest_yield_fixture(decorator, checker.semantic()) {
|
||||
let mut diagnostic =
|
||||
checker.report_diagnostic(PytestDeprecatedYieldFixture, decorator.range());
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ enum Argumentable {
|
|||
|
||||
impl Argumentable {
|
||||
fn check_for(self, checker: &Checker, name: String, range: TextRange) {
|
||||
match self {
|
||||
let mut diagnostic = match self {
|
||||
Self::Function => checker.report_diagnostic(UnusedFunctionArgument { name }, range),
|
||||
Self::Method => checker.report_diagnostic(UnusedMethodArgument { name }, range),
|
||||
Self::ClassMethod => {
|
||||
|
|
@ -234,6 +234,7 @@ impl Argumentable {
|
|||
}
|
||||
Self::Lambda => checker.report_diagnostic(UnusedLambdaArgument { name }, range),
|
||||
};
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Unnecessary);
|
||||
}
|
||||
|
||||
const fn rule_code(self) -> Rule {
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ pub(crate) fn deprecated_function(checker: &Checker, expr: &Expr) {
|
|||
},
|
||||
expr.range(),
|
||||
);
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
diagnostic.try_set_fix(|| {
|
||||
let (import_edit, binding) = checker.importer().get_or_import_symbol(
|
||||
&ImportRequest::import_from("numpy", replacement),
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ pub(crate) fn deprecated_type_alias(checker: &Checker, expr: &Expr) {
|
|||
},
|
||||
expr.range(),
|
||||
);
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
let type_name = match type_name {
|
||||
"unicode" => "str",
|
||||
_ => type_name,
|
||||
|
|
|
|||
Loading…
Reference in New Issue