mirror of https://github.com/astral-sh/ruff
Add docs for PLC rules (#4224)
This commit is contained in:
parent
bb2cbf1f25
commit
6db1a32eb9
|
|
@ -51,6 +51,30 @@ impl std::fmt::Display for EmptyStringCmpop {
|
|||
}
|
||||
}
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for comparisons to empty strings.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// An empty string is falsy, so it is unnecessary to compare it to `""`. If
|
||||
/// the value can be something else Python considers falsy, such as `None` or
|
||||
/// `0` or another empty container, then the code is not equivalent.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// def foo(x):
|
||||
/// if x == "":
|
||||
/// print("x is empty")
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// def foo(x):
|
||||
/// if not x:
|
||||
/// print("x is empty")
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
|
||||
#[violation]
|
||||
pub struct CompareToEmptyString {
|
||||
pub existing: String,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,25 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary direct calls to lambda expressions.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Calling a lambda expression directly is unnecessary. The expression can be
|
||||
/// executed inline instead to improve readability.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// area = (lambda r: 3.14 * r ** 2)(radius)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// area = 3.14 * radius ** 2
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation](https://docs.python.org/3/reference/expressions.html#lambda)
|
||||
#[violation]
|
||||
pub struct UnnecessaryDirectLambdaCall;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,21 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for import aliases that do not rename the original package.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// The import alias is redundant and should be removed to avoid confusion.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// import numpy as numpy
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// import numpy as np
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UselessImportAlias;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue