Add docs for f-string-missing-placeholders and unused-variable (#2790)

This commit is contained in:
Charlie Marsh 2023-02-11 21:48:36 -05:00 committed by GitHub
parent ac4e212ed2
commit 418808895e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 2 deletions

View file

@ -8,6 +8,26 @@ use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
/// ## What it does
/// 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.
///
/// ## Example
/// ```python
/// f"Hello, world!"
/// ```
///
/// Use instead:
/// ```python
/// "Hello, world!"
/// ```
///
/// ## References
/// * [PEP 498](https://www.python.org/dev/peps/pep-0498/)
pub struct FStringMissingPlaceholders;
);
impl AlwaysAutofixableViolation for FStringMissingPlaceholders {

View file

@ -16,6 +16,31 @@ use crate::source_code::Locator;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
/// ## What it does
/// Checks for the presence of unused variables in function scopes.
///
/// ## Why is this bad?
/// A variable that is defined but not used is likely a mistake, and should be
/// removed to avoid confusion.
///
/// If a variable is intentionally defined-but-not-used, it should be prefixed
/// with an underscore, or some other value that adheres to the
/// [`dummy-variable-rgx`](https://github.com/charliermarsh/ruff#dummy-variable-rgx) pattern.
///
/// ## Example
/// ```python
/// def foo():
/// x = 1
/// y = 2
/// return x
/// ```
///
/// Use instead:
/// ```python
/// def foo():
/// x = 1
/// return x
/// ```
pub struct UnusedVariable {
pub name: String,
}