Redirect F509 to PLE1300
This commit is contained in:
@@ -102,7 +102,6 @@ linter.rules.enabled = [
|
||||
percent-format-mixed-positional-and-named (F506),
|
||||
percent-format-positional-count-mismatch (F507),
|
||||
percent-format-star-requires-sequence (F508),
|
||||
percent-format-unsupported-format-character (F509),
|
||||
string-dot-format-invalid-format (F521),
|
||||
string-dot-format-extra-named-arguments (F522),
|
||||
string-dot-format-extra-positional-arguments (F523),
|
||||
@@ -164,7 +163,6 @@ linter.rules.should_fix = [
|
||||
percent-format-mixed-positional-and-named (F506),
|
||||
percent-format-positional-count-mismatch (F507),
|
||||
percent-format-star-requires-sequence (F508),
|
||||
percent-format-unsupported-format-character (F509),
|
||||
string-dot-format-invalid-format (F521),
|
||||
string-dot-format-extra-named-arguments (F522),
|
||||
string-dot-format-extra-positional-arguments (F523),
|
||||
|
||||
@@ -1098,17 +1098,10 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
|
||||
let location = expr.range();
|
||||
match pyflakes::cformat::CFormatSummary::try_from(value.to_str()) {
|
||||
Err(CFormatError {
|
||||
typ: CFormatErrorType::UnsupportedFormatChar(c),
|
||||
typ: CFormatErrorType::UnsupportedFormatChar(_),
|
||||
..
|
||||
}) => {
|
||||
if checker.enabled(Rule::PercentFormatUnsupportedFormatCharacter) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
pyflakes::rules::PercentFormatUnsupportedFormatCharacter {
|
||||
char: c,
|
||||
},
|
||||
location,
|
||||
));
|
||||
}
|
||||
// Unsupported format character violation is raised by `PLE1300`
|
||||
}
|
||||
Err(e) => {
|
||||
if checker.enabled(Rule::PercentFormatInvalidFormat) {
|
||||
|
||||
@@ -152,7 +152,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
||||
(Pyflakes, "506") => (RuleGroup::Stable, rules::pyflakes::rules::PercentFormatMixedPositionalAndNamed),
|
||||
(Pyflakes, "507") => (RuleGroup::Stable, rules::pyflakes::rules::PercentFormatPositionalCountMismatch),
|
||||
(Pyflakes, "508") => (RuleGroup::Stable, rules::pyflakes::rules::PercentFormatStarRequiresSequence),
|
||||
(Pyflakes, "509") => (RuleGroup::Stable, rules::pyflakes::rules::PercentFormatUnsupportedFormatCharacter),
|
||||
(Pyflakes, "509") => (RuleGroup::Removed, rules::pyflakes::rules::PercentFormatUnsupportedFormatCharacter),
|
||||
(Pyflakes, "521") => (RuleGroup::Stable, rules::pyflakes::rules::StringDotFormatInvalidFormat),
|
||||
(Pyflakes, "522") => (RuleGroup::Stable, rules::pyflakes::rules::StringDotFormatExtraNamedArguments),
|
||||
(Pyflakes, "523") => (RuleGroup::Stable, rules::pyflakes::rules::StringDotFormatExtraPositionalArguments),
|
||||
|
||||
@@ -103,6 +103,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
||||
("TRY200", "B904"),
|
||||
("PGH001", "S307"),
|
||||
("PGH002", "G010"),
|
||||
("F509", "PLE1300"),
|
||||
// Test redirect by exact code
|
||||
#[cfg(any(feature = "test-rules", test))]
|
||||
("RUF940", "RUF950"),
|
||||
|
||||
@@ -75,7 +75,6 @@ mod tests {
|
||||
#[test_case(Rule::PercentFormatMixedPositionalAndNamed, Path::new("F50x.py"))]
|
||||
#[test_case(Rule::PercentFormatPositionalCountMismatch, Path::new("F50x.py"))]
|
||||
#[test_case(Rule::PercentFormatStarRequiresSequence, Path::new("F50x.py"))]
|
||||
#[test_case(Rule::PercentFormatUnsupportedFormatCharacter, Path::new("F50x.py"))]
|
||||
#[test_case(Rule::StringDotFormatInvalidFormat, Path::new("F521.py"))]
|
||||
#[test_case(Rule::StringDotFormatExtraNamedArguments, Path::new("F522.py"))]
|
||||
#[test_case(Rule::StringDotFormatExtraPositionalArguments, Path::new("F523.py"))]
|
||||
|
||||
@@ -297,6 +297,10 @@ impl Violation for PercentFormatStarRequiresSequence {
|
||||
}
|
||||
}
|
||||
|
||||
/// ## Removed
|
||||
///
|
||||
/// This rule is a subset of [PLE1300] which should be used instead.
|
||||
///
|
||||
/// ## What it does
|
||||
/// Checks for `printf`-style format strings with invalid format characters.
|
||||
///
|
||||
@@ -317,11 +321,14 @@ impl Violation for PercentFormatStarRequiresSequence {
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting)
|
||||
///
|
||||
/// [PLE1300]: https://docs.astral.sh/ruff/rules/bad-string-format-character/
|
||||
#[violation]
|
||||
pub struct PercentFormatUnsupportedFormatCharacter {
|
||||
pub(crate) char: char,
|
||||
}
|
||||
|
||||
/// F509
|
||||
impl Violation for PercentFormatUnsupportedFormatCharacter {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F50x.py:4:1: F509 `%`-format string has unsupported format character `j`
|
||||
|
|
||||
2 | '%s %(foo)s' % {'foo': 'bar'} # F506
|
||||
3 | '%(foo)s %s' % {'foo': 'bar'} # F506
|
||||
4 | '%j' % (1,) # F509
|
||||
| ^^^^^^^^^^^ F509
|
||||
5 | '%s %s' % (1,) # F507
|
||||
6 | '%s %s' % (1, 2, 3) # F507
|
||||
|
|
||||
|
||||
|
||||
@@ -22,10 +22,21 @@ use crate::checkers::ast::Checker;
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// # `z` is not a valid format type.
|
||||
/// print("%z" % "1")
|
||||
/// print("%z" % 1)
|
||||
///
|
||||
/// print("{:z}".format("1"))
|
||||
/// print("{:z}".format(1))
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// print("%d" % 1)
|
||||
///
|
||||
/// print("{:d}".format(1))
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting)
|
||||
/// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format)
|
||||
#[violation]
|
||||
pub struct BadStringFormatCharacter {
|
||||
format_char: char,
|
||||
|
||||
1
ruff.schema.json
generated
1
ruff.schema.json
generated
@@ -2988,7 +2988,6 @@
|
||||
"F506",
|
||||
"F507",
|
||||
"F508",
|
||||
"F509",
|
||||
"F52",
|
||||
"F521",
|
||||
"F522",
|
||||
|
||||
Reference in New Issue
Block a user