Improve documentation for overlong-line rules (#5260)

Closes https://github.com/astral-sh/ruff/issues/5248.
This commit is contained in:
Charlie Marsh 2023-06-21 13:02:20 -04:00 committed by GitHub
parent ecf61d49fa
commit 0aa21277c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -10,7 +10,21 @@ use crate::settings::Settings;
/// ///
/// ## Why is this bad? /// ## Why is this bad?
/// For flowing long blocks of text (docstrings or comments), overlong lines /// For flowing long blocks of text (docstrings or comments), overlong lines
/// can hurt readability. /// can hurt readability. [PEP 8], for example, recommends that such lines be
/// limited to 72 characters.
///
/// In the context of this rule, a "doc line" is defined as a line consisting
/// of either a standalone comment or a standalone string, like a docstring.
///
/// In the interest of pragmatism, this rule makes a few exceptions when
/// determining whether a line is overlong. Namely, it ignores lines that
/// consist of a single "word" (i.e., without any whitespace between its
/// characters), and lines that end with a URL (as long as the URL starts
/// before the line-length threshold).
///
/// If `pycodestyle.ignore_overlong_task_comments` is `true`, this rule will
/// also ignore comments that start with any of the specified `task-tags`
/// (e.g., `# TODO:`).
/// ///
/// ## Example /// ## Example
/// ```python /// ```python
@ -26,6 +40,13 @@ use crate::settings::Settings;
/// Duis auctor purus ut ex fermentum, at maximus est hendrerit. /// Duis auctor purus ut ex fermentum, at maximus est hendrerit.
/// """ /// """
/// ``` /// ```
///
///
/// ## Options
/// - `task-tags`
/// - `pycodestyle.ignore-overlong-task-comments`
///
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
#[violation] #[violation]
pub struct DocLineTooLong(pub usize, pub usize); pub struct DocLineTooLong(pub usize, pub usize);

View File

@ -9,7 +9,18 @@ use crate::settings::Settings;
/// Checks for lines that exceed the specified maximum character length. /// Checks for lines that exceed the specified maximum character length.
/// ///
/// ## Why is this bad? /// ## Why is this bad?
/// Overlong lines can hurt readability. /// Overlong lines can hurt readability. [PEP 8], for example, recommends
/// limiting lines to 79 characters.
///
/// In the interest of pragmatism, this rule makes a few exceptions when
/// determining whether a line is overlong. Namely, it ignores lines that
/// consist of a single "word" (i.e., without any whitespace between its
/// characters), and lines that end with a URL (as long as the URL starts
/// before the line-length threshold).
///
/// If `pycodestyle.ignore_overlong_task_comments` is `true`, this rule will
/// also ignore comments that start with any of the specified `task-tags`
/// (e.g., `# TODO:`).
/// ///
/// ## Example /// ## Example
/// ```python /// ```python
@ -26,6 +37,9 @@ use crate::settings::Settings;
/// ///
/// ## Options /// ## Options
/// - `task-tags` /// - `task-tags`
/// - `pycodestyle.ignore-overlong-task-comments`
///
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
#[violation] #[violation]
pub struct LineTooLong(pub usize, pub usize); pub struct LineTooLong(pub usize, pub usize);