ruff/crates
Samuel Cormier-Iijima c306f85691
F841: support fixing unused assignments in tuples by renaming variables (#9107)
## Summary

A fairly common pattern which triggers F841 is unused variables from
tuple assignments, e.g.:

    user, created = User.objects.get_or_create(...)
          ^ F841: Local variable `created` is assigned to but never used

This error is currently not auto-fixable.

This PR adds support for fixing the error automatically by renaming the
unused variable to have a leading underscore (i.e. `_created`) **iff**
the `dummy-variable-rgx` setting would match it.

I considered using `renamers::Renamer` here, but because by the nature
of the error there should be no references to it, that seemed like
overkill. Also note that the fix might break by shadowing the new name
if it is already used elsewhere in the scope. I left it as is because

1. the renamed variable matches the "unused" regex, so it should
hopefully not already be used,
2. the fix is marked as unsafe so it should be reviewed manually
anyways, and
3. I'm not actually sure how to check the scope for the new variable
name 😅
2023-12-12 13:23:46 -05:00
..
flake8_to_ruff Bump version to v0.1.7 (#8999) 2023-12-04 16:28:23 -05:00
ruff_benchmark Bump ureq from 2.8.0 to 2.9.1 (#8993) 2023-12-04 09:53:25 -06:00
ruff_cache Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_cli Hide unsafe fix suggestions when explicitly disabled (#9095) 2023-12-11 15:42:53 -06:00
ruff_dev Update ruff-dev to use SourceKind (#8878) 2023-11-28 14:27:35 -06:00
ruff_diagnostics Update applicability messages for clarity in tests (#8541) 2023-11-07 16:11:43 +00:00
ruff_formatter remove several uses of unsafe (#8600) 2023-11-28 09:50:03 -05:00
ruff_index Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_linter F841: support fixing unused assignments in tuples by renaming variables (#9107) 2023-12-12 13:23:46 -05:00
ruff_macros remove several uses of unsafe (#8600) 2023-11-28 09:50:03 -05:00
ruff_notebook Allow transparent cell magics (#8911) 2023-12-07 14:15:43 -06:00
ruff_python_ast Introduce StringLike enum (#9016) 2023-12-07 16:39:13 +00:00
ruff_python_codegen New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
ruff_python_formatter ruff_python_formatter: implement "dynamic" line width mode for docstring code formatting (#9098) 2023-12-12 09:58:07 -05:00
ruff_python_index Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_python_literal remove several uses of unsafe (#8600) 2023-11-28 09:50:03 -05:00
ruff_python_parser New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
ruff_python_resolver Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_python_semantic Allow matplotlib.use calls to intersperse imports (#9094) 2023-12-11 17:06:25 +00:00
ruff_python_stdlib Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_python_trivia Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_shrinking Bump version to v0.1.7 (#8999) 2023-12-04 16:28:23 -05:00
ruff_source_file remove several uses of unsafe (#8600) 2023-11-28 09:50:03 -05:00
ruff_text_size Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
ruff_wasm Bump serde-wasm-bindgen from 0.6.1 to 0.6.3 (#9089) 2023-12-11 08:52:07 +00:00
ruff_workspace Hide unsafe fix suggestions when explicitly disabled (#9095) 2023-12-11 15:42:53 -06:00