Skip to content

Commit

Permalink
Fix documented examples for unnecessary-subscript-reversal
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Oct 3, 2023
1 parent 3ccd1d5 commit 26ee2a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
4 changes: 1 addition & 3 deletions crates/ruff_linter/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
);
}
if checker.enabled(Rule::UnnecessarySubscriptReversal) {
flake8_comprehensions::rules::unnecessary_subscript_reversal(
checker, expr, func, args,
);
flake8_comprehensions::rules::unnecessary_subscript_reversal(checker, call);
}
if checker.enabled(Rule::UnnecessaryMap) {
flake8_comprehensions::rules::unnecessary_map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ use crate::checkers::ast::Checker;
///
/// ## Examples
/// ```python
/// reversed(iterable[::-1])
/// sorted(iterable[::-1])
/// set(iterable[::-1])
/// sorted(iterable)[::-1]
/// reversed(iterable[::-1])
/// ```
///
/// Use instead:
/// ```python
/// reversed(iterable)
/// sorted(iterable)
/// set(iterable)
/// sorted(iterable, reverse=True)
/// iterable
/// ```
#[violation]
pub struct UnnecessarySubscriptReversal {
Expand All @@ -40,16 +40,11 @@ impl Violation for UnnecessarySubscriptReversal {
}

/// C415
pub(crate) fn unnecessary_subscript_reversal(
checker: &mut Checker,
expr: &Expr,
func: &Expr,
args: &[Expr],
) {
let Some(first_arg) = args.first() else {
pub(crate) fn unnecessary_subscript_reversal(checker: &mut Checker, call: &ast::ExprCall) {
let Some(first_arg) = call.arguments.args.first() else {
return;
};
let Some(func) = func.as_name_expr() else {
let Some(func) = call.func.as_name_expr() else {
return;
};
if !matches!(func.id.as_str(), "reversed" | "set" | "sorted") {
Expand Down Expand Up @@ -98,6 +93,6 @@ pub(crate) fn unnecessary_subscript_reversal(
UnnecessarySubscriptReversal {
func: func.id.to_string(),
},
expr.range(),
call.range(),
));
}

0 comments on commit 26ee2a2

Please sign in to comment.