mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:54:42 +00:00
Stabilize unused-unpacked-variable
(RUF059
) (#20233)
The tests looked good. For the docs, I added a `## See also` section pointing to the closely-related F841 (unused-variable) and the corresponding section to F841 pointing back to RUF059. It seems like you'd probably want both of these active or at least to know about the other when reading the docs.
This commit is contained in:
parent
1cf6c2439f
commit
1de9dac9d5
4 changed files with 16 additions and 2 deletions
|
@ -1046,7 +1046,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Ruff, "056") => (RuleGroup::Preview, rules::ruff::rules::FalsyDictGetFallback),
|
||||
(Ruff, "057") => (RuleGroup::Stable, rules::ruff::rules::UnnecessaryRound),
|
||||
(Ruff, "058") => (RuleGroup::Stable, rules::ruff::rules::StarmapZip),
|
||||
(Ruff, "059") => (RuleGroup::Preview, rules::ruff::rules::UnusedUnpackedVariable),
|
||||
(Ruff, "059") => (RuleGroup::Stable, rules::ruff::rules::UnusedUnpackedVariable),
|
||||
(Ruff, "060") => (RuleGroup::Preview, rules::ruff::rules::InEmptyCollection),
|
||||
(Ruff, "061") => (RuleGroup::Preview, rules::ruff::rules::LegacyFormPytestRaises),
|
||||
(Ruff, "063") => (RuleGroup::Preview, rules::ruff::rules::AccessAnnotationsFromClassDict),
|
||||
|
|
|
@ -119,7 +119,7 @@ expression: value
|
|||
},
|
||||
{
|
||||
"fullDescription": {
|
||||
"text": "## What it does\nChecks for the presence of unused variables in function scopes.\n\n## Why is this bad?\nA variable that is defined but not used is likely a mistake, and should\nbe removed to avoid confusion.\n\nIf a variable is intentionally defined-but-not-used, it should be\nprefixed with an underscore, or some other value that adheres to the\n[`lint.dummy-variable-rgx`] pattern.\n\n## Example\n```python\ndef foo():\n x = 1\n y = 2\n return x\n```\n\nUse instead:\n```python\ndef foo():\n x = 1\n return x\n```\n\n## Fix safety\n\nThis rule's fix is marked as unsafe because removing an unused variable assignment may\ndelete comments that are attached to the assignment.\n\n## Options\n- `lint.dummy-variable-rgx`\n"
|
||||
"text": "## What it does\nChecks for the presence of unused variables in function scopes.\n\n## Why is this bad?\nA variable that is defined but not used is likely a mistake, and should\nbe removed to avoid confusion.\n\nIf a variable is intentionally defined-but-not-used, it should be\nprefixed with an underscore, or some other value that adheres to the\n[`lint.dummy-variable-rgx`] pattern.\n\n## Example\n```python\ndef foo():\n x = 1\n y = 2\n return x\n```\n\nUse instead:\n```python\ndef foo():\n x = 1\n return x\n```\n\n## Fix safety\n\nThis rule's fix is marked as unsafe because removing an unused variable assignment may\ndelete comments that are attached to the assignment.\n\n## See also\n\nThis rule does not apply to bindings in unpacked assignments (e.g. `x, y = 1, 2`). See\n[`unused-unpacked-variable`][RUF059] for this case.\n\n## Options\n- `lint.dummy-variable-rgx`\n\n[RUF059]: https://docs.astral.sh/ruff/rules/unused-unpacked-variable/\n"
|
||||
},
|
||||
"help": {
|
||||
"text": "Local variable `{name}` is assigned to but never used"
|
||||
|
|
|
@ -43,8 +43,15 @@ use crate::{Edit, Fix, FixAvailability, Violation};
|
|||
/// This rule's fix is marked as unsafe because removing an unused variable assignment may
|
||||
/// delete comments that are attached to the assignment.
|
||||
///
|
||||
/// ## See also
|
||||
///
|
||||
/// This rule does not apply to bindings in unpacked assignments (e.g. `x, y = 1, 2`). See
|
||||
/// [`unused-unpacked-variable`][RUF059] for this case.
|
||||
///
|
||||
/// ## Options
|
||||
/// - `lint.dummy-variable-rgx`
|
||||
///
|
||||
/// [RUF059]: https://docs.astral.sh/ruff/rules/unused-unpacked-variable/
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct UnusedVariable {
|
||||
pub name: String,
|
||||
|
|
|
@ -36,8 +36,15 @@ use crate::{Edit, Fix, FixAvailability, Violation};
|
|||
/// return x
|
||||
/// ```
|
||||
///
|
||||
/// ## See also
|
||||
///
|
||||
/// This rule applies only to unpacked assignments. For regular assignments, see
|
||||
/// [`unused-variable`][F841].
|
||||
///
|
||||
/// ## Options
|
||||
/// - `lint.dummy-variable-rgx`
|
||||
///
|
||||
/// [F841]: https://docs.astral.sh/ruff/rules/unused-variable/
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct UnusedUnpackedVariable {
|
||||
pub name: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue