Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make C413 fix as suggested for reversed call #4891

Merged
merged 3 commits into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,6 @@
use rustpython_parser::ast::{self, Expr, Ranged};

use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
use ruff_macros::{derive_message_formats, violation};

use crate::checkers::ast::Checker;
Expand Down Expand Up @@ -85,9 +85,14 @@ pub(crate) fn unnecessary_call_around_sorted(
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.try_set_fix_from_edit(|| {
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)
diagnostic.try_set_fix(|| {
let edit =
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)?;
if outer == "reversed" {
Ok(Fix::suggested(edit))
} else {
Ok(Fix::automatic(edit))
}
});
}
checker.diagnostics.push(diagnostic);
Expand Down
Expand Up @@ -12,7 +12,7 @@ C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()`
|
= help: Remove unnecessary `list` call

Suggested fix
Fix
1 1 | x = [2, 3, 1]
2 2 | list(x)
3 |-list(sorted(x))
Expand Down