-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Both rules check for invalid format character in % format style string.
The implementation is almost the same:
F509
ruff/crates/ruff_linter/src/checkers/ast/analyze/expression.rs
Lines 1087 to 1100 in 1f748b8
| match pyflakes::cformat::CFormatSummary::try_from(value.to_str()) { | |
| Err(CFormatError { | |
| typ: CFormatErrorType::UnsupportedFormatChar(c), | |
| .. | |
| }) => { | |
| if checker.enabled(Rule::PercentFormatUnsupportedFormatCharacter) { | |
| checker.diagnostics.push(Diagnostic::new( | |
| pyflakes::rules::PercentFormatUnsupportedFormatCharacter { | |
| char: c, | |
| }, | |
| location, | |
| )); | |
| } | |
| } |
PLE1300
ruff/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs
Lines 117 to 125 in 1f748b8
| // Parse the format string (e.g. `"%s"`) into a list of `PercentFormat`. | |
| if let Err(format_error) = CFormatString::from_str(string) { | |
| if let CFormatErrorType::UnsupportedFormatChar(format_char) = format_error.typ { | |
| checker.diagnostics.push(Diagnostic::new( | |
| BadStringFormatCharacter { format_char }, | |
| expr.range(), | |
| )); | |
| } | |
| }; |
There's one difference which can be noticed when an implicitly concatenated string is used. F509 looks at the concatenated string while PLE1300 looks at each part of an implicitly concatenated string. Refer to https://play.ruff.rs/6efd9945-2a3b-43e4-b9b7-a8d041b98318.
Reference:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule