mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Add docs for f-string-missing-placeholders and unused-variable (#2790)
This commit is contained in:
parent
ac4e212ed2
commit
418808895e
5 changed files with 104 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue