Add pygrep-hooks documentation (#4131)

This commit is contained in:
Tom Kuson 2023-04-27 19:33:07 +01:00 committed by GitHub
parent 3c9f5e2fdc
commit 3e81403fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 0 deletions

View File

@ -6,3 +6,4 @@ trivias = "trivias"
hel = "hel" hel = "hel"
whos = "whos" whos = "whos"
spawnve = "spawnve" spawnve = "spawnve"
ned = "ned"

View File

@ -6,6 +6,29 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::newlines::Line; use ruff_python_ast::newlines::Line;
/// ## What it does
/// Check for `noqa` annotations that suppress all diagnostics, as opposed to
/// targeting specific diagnostics.
///
/// ## Why is this bad?
/// Suppressing all diagnostics can hide issues in the code.
///
/// Blanket `noqa` annotations are also more difficult to interpret and
/// maintain, as the annotation does not clarify which diagnostics are intended
/// to be suppressed.
///
/// ## Example
/// ```python
/// from .base import * # noqa
/// ```
///
/// Use instead:
/// ```python
/// from .base import * # noqa: F403
/// ```
///
/// ## References
/// - [Ruff documentation](https://beta.ruff.rs/docs/configuration/#error-suppression)
#[violation] #[violation]
pub struct BlanketNOQA; pub struct BlanketNOQA;

View File

@ -7,6 +7,29 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::newlines::Line; use ruff_python_ast::newlines::Line;
/// ## What it does
/// Check for `type: ignore` annotations that suppress all type warnings, as
/// opposed to targeting specific type warnings.
///
/// ## Why is this bad?
/// Suppressing all warnings can hide issues in the code.
///
/// Blanket `type: ignore` annotations are also more difficult to interpret and
/// maintain, as the annotation does not clarify which warnings are intended
/// to be suppressed.
///
/// ## Example
/// ```python
/// from foo import secrets # type: ignore
/// ```
///
/// Use instead:
/// ```python
/// from foo import secrets # type: ignore[attr-defined]
/// ```
///
/// ## References
/// - [mypy](https://mypy.readthedocs.io/en/stable/common_issues.html#spurious-errors-and-locally-silencing-the-checker)
#[violation] #[violation]
pub struct BlanketTypeIgnore; pub struct BlanketTypeIgnore;

View File

@ -5,6 +5,31 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker; use crate::checkers::ast::Checker;
/// ## What it does
/// Check for usages of the deprecated `warn` method from the `logging` module.
///
/// ## Why is this bad?
/// The `warn` method is deprecated. Use `warning` instead.
///
/// ## Example
/// ```python
/// import logging
///
///
/// def foo():
/// logging.warn("Something happened")
/// ```
///
/// Use instead:
/// ```python
/// import logging
///
/// def foo():
/// logging.warning("Something happened")
/// ```
///
/// ## References
/// - [Python documentation](https://docs.python.org/3/library/logging.html#logging.Logger.warning)
#[violation] #[violation]
pub struct DeprecatedLogWarn; pub struct DeprecatedLogWarn;

View File

@ -5,6 +5,29 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker; use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for usages of the builtin `eval()` function.
///
/// ## Why is this bad?
/// The `eval()` function is insecure as it enables arbitrary code execution.
///
/// ## Example
/// ```python
/// def foo():
/// x = eval(input("Enter a number: "))
/// ...
/// ```
///
/// Use instead:
/// ```python
/// def foo():
/// x = input("Enter a number: ")
/// ...
/// ```
///
/// ## References
/// - [Python documentation](https://docs.python.org/3/library/functions.html#eval)
/// - [_Eval really is dangerous_ by Ned Batchelder](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html)
#[violation] #[violation]
pub struct Eval; pub struct Eval;