Add known problems to compare-to-empty-string documentation (#5879)

## Summary

Add known problems to `compare-to-empty-string` documentation. Related
to #5873.

Tweaked the example in the documentation to be a tad more concise and
correct (that the rule is most applicable when comparing to a `str`
variable).

## Test Plan

`python scripts/check_docs_formatted.py`
This commit is contained in:
Tom Kuson 2023-07-19 23:12:27 +01:00 committed by GitHub
parent 9834c69c98
commit 23cde4d1f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,22 +15,30 @@ use crate::checkers::ast::Checker;
/// the value can be something else Python considers falsy, such as `None` or
/// `0` or another empty container, then the code is not equivalent.
///
/// ## Known problems
/// High false positive rate, as the check is context-insensitive and does not
/// consider the type of the variable being compared ([#4282]).
///
/// ## Example
/// ```python
/// def foo(x):
/// if x == "":
/// print("x is empty")
/// x: str = ...
///
/// if x == "":
/// print("x is empty")
/// ```
///
/// Use instead:
/// ```python
/// def foo(x):
/// if not x:
/// print("x is empty")
/// x: str = ...
///
/// if not x:
/// print("x is empty")
/// ```
///
/// ## References
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
///
/// [#4282]: https://github.com/astral-sh/ruff/issues/4282
#[violation]
pub struct CompareToEmptyString {
existing: String,