-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore RUF011 documentation (#9758)
- Loading branch information
Showing
6 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use ruff_diagnostics::Violation; | ||
use ruff_macros::{derive_message_formats, violation}; | ||
|
||
/// ## Removed | ||
/// This rule was implemented in `flake8-bugbear` and has been remapped to [B035] | ||
/// | ||
/// ## What it does | ||
/// Checks for dictionary comprehensions that use a static key, like a string | ||
/// literal or a variable defined outside the comprehension. | ||
/// | ||
/// ## Why is this bad? | ||
/// Using a static key (like a string literal) in a dictionary comprehension | ||
/// is usually a mistake, as it will result in a dictionary with only one key, | ||
/// despite the comprehension iterating over multiple values. | ||
/// | ||
/// ## Example | ||
/// ```python | ||
/// data = ["some", "Data"] | ||
/// {"key": value.upper() for value in data} | ||
/// ``` | ||
/// | ||
/// Use instead: | ||
/// ```python | ||
/// data = ["some", "Data"] | ||
/// {value: value.upper() for value in data} | ||
/// ``` | ||
/// | ||
/// [B035]: https://docs.astral.sh/ruff/rules/static-key-dict-comprehension/ | ||
#[violation] | ||
pub struct RuffStaticKeyDictComprehension; | ||
|
||
impl Violation for RuffStaticKeyDictComprehension { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Dictionary comprehension uses static key") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters