From 4a12ebb9b11de976e6a836dea4d3454764599829 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 11 Feb 2023 23:58:24 -0500 Subject: [PATCH] Improve f-string-missing-placeholders documentation (#2800) --- .../pyflakes/rules/f_string_missing_placeholders.rs | 9 +++++++-- docs/rules/f-string-missing-placeholders.md | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs b/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs index e6c01437d9..2e7cf65c1b 100644 --- a/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs +++ b/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs @@ -13,8 +13,13 @@ define_violation!( /// /// ## Why is this bad? /// F-strings are a convenient way to format strings, but they are not - /// necessary if there are no placeholder expressions to format. In this case, - /// a regular string should be used instead. + /// necessary if there are no placeholder expressions to format. In this + /// case, a regular string should be used instead, as an f-string without + /// placeholders can be confusing for readers, who may expect such a + /// placeholder to be present. + /// + /// An f-string without any placeholders could also indicate that the + /// author forgot to add a placeholder expression. /// /// ## Example /// ```python diff --git a/docs/rules/f-string-missing-placeholders.md b/docs/rules/f-string-missing-placeholders.md index 5863792ea5..8134b32198 100644 --- a/docs/rules/f-string-missing-placeholders.md +++ b/docs/rules/f-string-missing-placeholders.md @@ -9,8 +9,13 @@ Checks for f-strings that do not contain any placeholder expressions. ## Why is this bad? F-strings are a convenient way to format strings, but they are not -necessary if there are no placeholder expressions to format. In this case, -a regular string should be used instead. +necessary if there are no placeholder expressions to format. In this +case, a regular string should be used instead, as an f-string without +placeholders can be confusing for readers, who may expect such a +placeholder to be present. + +An f-string without any placeholders could also indicate that the +author forgot to add a placeholder expression. ## Example ```python