Rename rules currently not conforming to naming convention (#15102)

## Summary

This pull request renames 19 rules which currently do not conform to
Ruff's [naming
convention](https://github.com/astral-sh/ruff/blob/main/CONTRIBUTING.md#rule-naming-convention).

## Description

Fixes astral-sh/ruff#15009.
This commit is contained in:
Enoch Kan 2024-12-23 21:48:45 +00:00 committed by GitHub
parent 97965ff114
commit 5bc9d6d3aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 251 additions and 249 deletions

View File

@ -799,7 +799,7 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) {
// ``` // ```
Rule::MissingTrailingComma, Rule::MissingTrailingComma,
// The formatter always removes blank lines before the docstring. // The formatter always removes blank lines before the docstring.
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
] { ] {
if setting.linter.rules.enabled(rule) { if setting.linter.rules.enabled(rule) {
incompatible_rules.insert(rule); incompatible_rules.insert(rule);
@ -830,7 +830,7 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) {
} }
// Validate all rules that rely on tab styles. // Validate all rules that rely on tab styles.
if setting.linter.rules.enabled(Rule::IndentWithSpaces) if setting.linter.rules.enabled(Rule::DocstringTabIndentation)
&& setting.formatter.indent_style.is_tab() && setting.formatter.indent_style.is_tab()
{ {
warn_user_once!("The `format.indent-style=\"tab\"` option is incompatible with `D206`, with requires space-based indentation. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `\"space\"`."); warn_user_once!("The `format.indent-style=\"tab\"` option is incompatible with `D206`, with requires space-based indentation. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `\"space\"`.");

View File

@ -1112,7 +1112,7 @@ def say_hy(name: str):
1 file reformatted 1 file reformatted
----- stderr ----- ----- stderr -----
warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`. warning: `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`. warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
warning: The following rules may cause conflicts when used with the formatter: `COM812`, `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration. warning: The following rules may cause conflicts when used with the formatter: `COM812`, `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.
"); ");

View File

@ -1037,7 +1037,7 @@ fn preview_enabled_all() {
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option). [*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
----- stderr ----- ----- stderr -----
warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`. warning: `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`. warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
"); ");
} }

View File

@ -1,4 +1,4 @@
"""Test: no-blank-line-after-function special-cases around comment handling.""" """Test: blank-line-after-function special-cases around comment handling."""
# OK # OK
def outer(): def outer():

View File

@ -34,40 +34,40 @@ pub(crate) fn definitions(checker: &mut Checker) {
let enforce_stubs_and_runtime = checker.enabled(Rule::IterMethodReturnIterable); let enforce_stubs_and_runtime = checker.enabled(Rule::IterMethodReturnIterable);
let enforce_dunder_method = checker.enabled(Rule::BadDunderMethodName); let enforce_dunder_method = checker.enabled(Rule::BadDunderMethodName);
let enforce_docstrings = checker.any_enabled(&[ let enforce_docstrings = checker.any_enabled(&[
Rule::BlankLineAfterLastSection, Rule::MissingBlankLineAfterLastSection,
Rule::BlankLineAfterSummary, Rule::MissingBlankLineAfterSummary,
Rule::BlankLineBeforeClass, Rule::BlankLineBeforeClass,
Rule::BlankLinesBetweenHeaderAndContent, Rule::BlankLinesBetweenHeaderAndContent,
Rule::CapitalizeSectionName, Rule::NonCapitalizedSectionName,
Rule::DashedUnderlineAfterSection, Rule::MissingDashedUnderlineAfterSection,
Rule::DocstringStartsWithThis, Rule::DocstringStartsWithThis,
Rule::EmptyDocstring, Rule::EmptyDocstring,
Rule::EmptyDocstringSection, Rule::EmptyDocstringSection,
Rule::EndsInPeriod, Rule::MissingTrailingPeriod,
Rule::EndsInPunctuation, Rule::MissingTerminalPunctuation,
Rule::EscapeSequenceInDocstring, Rule::EscapeSequenceInDocstring,
Rule::FirstWordUncapitalized, Rule::FirstWordUncapitalized,
Rule::FitsOnOneLine, Rule::UnnecessaryMultilineDocstring,
Rule::IndentWithSpaces, Rule::DocstringTabIndentation,
Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummaryFirstLine,
Rule::MultiLineSummarySecondLine, Rule::MultiLineSummarySecondLine,
Rule::NewLineAfterLastParagraph, Rule::NewLineAfterLastParagraph,
Rule::NewLineAfterSectionName, Rule::MissingNewLineAfterSectionName,
Rule::NoBlankLineAfterFunction, Rule::BlankLineAfterFunction,
Rule::NoBlankLineAfterSection, Rule::NoBlankLineAfterSection,
Rule::NoBlankLineBeforeFunction, Rule::BlankLineBeforeFunction,
Rule::NoBlankLineBeforeSection, Rule::NoBlankLineBeforeSection,
Rule::NoSignature, Rule::SignatureInDocstring,
Rule::NonImperativeMood, Rule::NonImperativeMood,
Rule::OneBlankLineAfterClass, Rule::IncorrectBlankLineAfterClass,
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
Rule::OverIndentation, Rule::OverIndentation,
Rule::OverloadWithDocstring, Rule::OverloadWithDocstring,
Rule::SectionNameEndsInColon, Rule::MissingSectionNameColon,
Rule::SectionNotOverIndented, Rule::OverindentedSection,
Rule::SectionUnderlineAfterName, Rule::MissingSectionUnderlineAfterName,
Rule::SectionUnderlineMatchesSectionLength, Rule::MismatchedSectionUnderlineLength,
Rule::SectionUnderlineNotOverIndented, Rule::OverindentedSectionUnderline,
Rule::SurroundingWhitespace, Rule::SurroundingWhitespace,
Rule::TripleSingleQuotes, Rule::TripleSingleQuotes,
Rule::UnderIndentation, Rule::UnderIndentation,
@ -220,27 +220,24 @@ pub(crate) fn definitions(checker: &mut Checker) {
if !pydocstyle::rules::not_empty(checker, &docstring) { if !pydocstyle::rules::not_empty(checker, &docstring) {
continue; continue;
} }
if checker.enabled(Rule::FitsOnOneLine) { if checker.enabled(Rule::UnnecessaryMultilineDocstring) {
pydocstyle::rules::one_liner(checker, &docstring); pydocstyle::rules::one_liner(checker, &docstring);
} }
if checker.any_enabled(&[ if checker.any_enabled(&[Rule::BlankLineAfterFunction, Rule::BlankLineBeforeFunction]) {
Rule::NoBlankLineAfterFunction,
Rule::NoBlankLineBeforeFunction,
]) {
pydocstyle::rules::blank_before_after_function(checker, &docstring); pydocstyle::rules::blank_before_after_function(checker, &docstring);
} }
if checker.any_enabled(&[ if checker.any_enabled(&[
Rule::BlankLineBeforeClass, Rule::BlankLineBeforeClass,
Rule::OneBlankLineAfterClass, Rule::IncorrectBlankLineAfterClass,
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
]) { ]) {
pydocstyle::rules::blank_before_after_class(checker, &docstring); pydocstyle::rules::blank_before_after_class(checker, &docstring);
} }
if checker.enabled(Rule::BlankLineAfterSummary) { if checker.enabled(Rule::MissingBlankLineAfterSummary) {
pydocstyle::rules::blank_after_summary(checker, &docstring); pydocstyle::rules::blank_after_summary(checker, &docstring);
} }
if checker.any_enabled(&[ if checker.any_enabled(&[
Rule::IndentWithSpaces, Rule::DocstringTabIndentation,
Rule::OverIndentation, Rule::OverIndentation,
Rule::UnderIndentation, Rule::UnderIndentation,
]) { ]) {
@ -264,7 +261,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
if checker.enabled(Rule::EscapeSequenceInDocstring) { if checker.enabled(Rule::EscapeSequenceInDocstring) {
pydocstyle::rules::backslashes(checker, &docstring); pydocstyle::rules::backslashes(checker, &docstring);
} }
if checker.enabled(Rule::EndsInPeriod) { if checker.enabled(Rule::MissingTrailingPeriod) {
pydocstyle::rules::ends_with_period(checker, &docstring); pydocstyle::rules::ends_with_period(checker, &docstring);
} }
if checker.enabled(Rule::NonImperativeMood) { if checker.enabled(Rule::NonImperativeMood) {
@ -274,7 +271,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
&checker.settings.pydocstyle, &checker.settings.pydocstyle,
); );
} }
if checker.enabled(Rule::NoSignature) { if checker.enabled(Rule::SignatureInDocstring) {
pydocstyle::rules::no_signature(checker, &docstring); pydocstyle::rules::no_signature(checker, &docstring);
} }
if checker.enabled(Rule::FirstWordUncapitalized) { if checker.enabled(Rule::FirstWordUncapitalized) {
@ -283,7 +280,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
if checker.enabled(Rule::DocstringStartsWithThis) { if checker.enabled(Rule::DocstringStartsWithThis) {
pydocstyle::rules::starts_with_this(checker, &docstring); pydocstyle::rules::starts_with_this(checker, &docstring);
} }
if checker.enabled(Rule::EndsInPunctuation) { if checker.enabled(Rule::MissingTerminalPunctuation) {
pydocstyle::rules::ends_with_punctuation(checker, &docstring); pydocstyle::rules::ends_with_punctuation(checker, &docstring);
} }
if checker.enabled(Rule::OverloadWithDocstring) { if checker.enabled(Rule::OverloadWithDocstring) {
@ -291,20 +288,20 @@ pub(crate) fn definitions(checker: &mut Checker) {
} }
let enforce_sections = checker.any_enabled(&[ let enforce_sections = checker.any_enabled(&[
Rule::BlankLineAfterLastSection, Rule::MissingBlankLineAfterLastSection,
Rule::BlankLinesBetweenHeaderAndContent, Rule::BlankLinesBetweenHeaderAndContent,
Rule::CapitalizeSectionName, Rule::NonCapitalizedSectionName,
Rule::DashedUnderlineAfterSection, Rule::MissingDashedUnderlineAfterSection,
Rule::EmptyDocstringSection, Rule::EmptyDocstringSection,
Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummaryFirstLine,
Rule::NewLineAfterSectionName, Rule::MissingNewLineAfterSectionName,
Rule::NoBlankLineAfterSection, Rule::NoBlankLineAfterSection,
Rule::NoBlankLineBeforeSection, Rule::NoBlankLineBeforeSection,
Rule::SectionNameEndsInColon, Rule::MissingSectionNameColon,
Rule::SectionNotOverIndented, Rule::OverindentedSection,
Rule::SectionUnderlineAfterName, Rule::MissingSectionUnderlineAfterName,
Rule::SectionUnderlineMatchesSectionLength, Rule::MismatchedSectionUnderlineLength,
Rule::SectionUnderlineNotOverIndented, Rule::OverindentedSectionUnderline,
Rule::UndocumentedParam, Rule::UndocumentedParam,
]); ]);
if enforce_sections || enforce_pydoclint { if enforce_sections || enforce_pydoclint {

View File

@ -545,13 +545,13 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pydocstyle, "105") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedMagicMethod), (Pydocstyle, "105") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedMagicMethod),
(Pydocstyle, "106") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicNestedClass), (Pydocstyle, "106") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicNestedClass),
(Pydocstyle, "107") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicInit), (Pydocstyle, "107") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicInit),
(Pydocstyle, "200") => (RuleGroup::Stable, rules::pydocstyle::rules::FitsOnOneLine), (Pydocstyle, "200") => (RuleGroup::Stable, rules::pydocstyle::rules::UnnecessaryMultilineDocstring),
(Pydocstyle, "201") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineBeforeFunction), (Pydocstyle, "201") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineBeforeFunction),
(Pydocstyle, "202") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineAfterFunction), (Pydocstyle, "202") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineAfterFunction),
(Pydocstyle, "203") => (RuleGroup::Stable, rules::pydocstyle::rules::OneBlankLineBeforeClass), (Pydocstyle, "203") => (RuleGroup::Stable, rules::pydocstyle::rules::IncorrectBlankLineBeforeClass),
(Pydocstyle, "204") => (RuleGroup::Stable, rules::pydocstyle::rules::OneBlankLineAfterClass), (Pydocstyle, "204") => (RuleGroup::Stable, rules::pydocstyle::rules::IncorrectBlankLineAfterClass),
(Pydocstyle, "205") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineAfterSummary), (Pydocstyle, "205") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingBlankLineAfterSummary),
(Pydocstyle, "206") => (RuleGroup::Stable, rules::pydocstyle::rules::IndentWithSpaces), (Pydocstyle, "206") => (RuleGroup::Stable, rules::pydocstyle::rules::DocstringTabIndentation),
(Pydocstyle, "207") => (RuleGroup::Stable, rules::pydocstyle::rules::UnderIndentation), (Pydocstyle, "207") => (RuleGroup::Stable, rules::pydocstyle::rules::UnderIndentation),
(Pydocstyle, "208") => (RuleGroup::Stable, rules::pydocstyle::rules::OverIndentation), (Pydocstyle, "208") => (RuleGroup::Stable, rules::pydocstyle::rules::OverIndentation),
(Pydocstyle, "209") => (RuleGroup::Stable, rules::pydocstyle::rules::NewLineAfterLastParagraph), (Pydocstyle, "209") => (RuleGroup::Stable, rules::pydocstyle::rules::NewLineAfterLastParagraph),
@ -559,27 +559,27 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pydocstyle, "211") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineBeforeClass), (Pydocstyle, "211") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineBeforeClass),
(Pydocstyle, "212") => (RuleGroup::Stable, rules::pydocstyle::rules::MultiLineSummaryFirstLine), (Pydocstyle, "212") => (RuleGroup::Stable, rules::pydocstyle::rules::MultiLineSummaryFirstLine),
(Pydocstyle, "213") => (RuleGroup::Stable, rules::pydocstyle::rules::MultiLineSummarySecondLine), (Pydocstyle, "213") => (RuleGroup::Stable, rules::pydocstyle::rules::MultiLineSummarySecondLine),
(Pydocstyle, "214") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionNotOverIndented), (Pydocstyle, "214") => (RuleGroup::Stable, rules::pydocstyle::rules::OverindentedSection),
(Pydocstyle, "215") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionUnderlineNotOverIndented), (Pydocstyle, "215") => (RuleGroup::Stable, rules::pydocstyle::rules::OverindentedSectionUnderline),
(Pydocstyle, "300") => (RuleGroup::Stable, rules::pydocstyle::rules::TripleSingleQuotes), (Pydocstyle, "300") => (RuleGroup::Stable, rules::pydocstyle::rules::TripleSingleQuotes),
(Pydocstyle, "301") => (RuleGroup::Stable, rules::pydocstyle::rules::EscapeSequenceInDocstring), (Pydocstyle, "301") => (RuleGroup::Stable, rules::pydocstyle::rules::EscapeSequenceInDocstring),
(Pydocstyle, "400") => (RuleGroup::Stable, rules::pydocstyle::rules::EndsInPeriod), (Pydocstyle, "400") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingTrailingPeriod),
(Pydocstyle, "401") => (RuleGroup::Stable, rules::pydocstyle::rules::NonImperativeMood), (Pydocstyle, "401") => (RuleGroup::Stable, rules::pydocstyle::rules::NonImperativeMood),
(Pydocstyle, "402") => (RuleGroup::Stable, rules::pydocstyle::rules::NoSignature), (Pydocstyle, "402") => (RuleGroup::Stable, rules::pydocstyle::rules::SignatureInDocstring),
(Pydocstyle, "403") => (RuleGroup::Stable, rules::pydocstyle::rules::FirstWordUncapitalized), (Pydocstyle, "403") => (RuleGroup::Stable, rules::pydocstyle::rules::FirstWordUncapitalized),
(Pydocstyle, "404") => (RuleGroup::Stable, rules::pydocstyle::rules::DocstringStartsWithThis), (Pydocstyle, "404") => (RuleGroup::Stable, rules::pydocstyle::rules::DocstringStartsWithThis),
(Pydocstyle, "405") => (RuleGroup::Stable, rules::pydocstyle::rules::CapitalizeSectionName), (Pydocstyle, "405") => (RuleGroup::Stable, rules::pydocstyle::rules::NonCapitalizedSectionName),
(Pydocstyle, "406") => (RuleGroup::Stable, rules::pydocstyle::rules::NewLineAfterSectionName), (Pydocstyle, "406") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingNewLineAfterSectionName),
(Pydocstyle, "407") => (RuleGroup::Stable, rules::pydocstyle::rules::DashedUnderlineAfterSection), (Pydocstyle, "407") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingDashedUnderlineAfterSection),
(Pydocstyle, "408") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionUnderlineAfterName), (Pydocstyle, "408") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingSectionUnderlineAfterName),
(Pydocstyle, "409") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionUnderlineMatchesSectionLength), (Pydocstyle, "409") => (RuleGroup::Stable, rules::pydocstyle::rules::MismatchedSectionUnderlineLength),
(Pydocstyle, "410") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineAfterSection), (Pydocstyle, "410") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineAfterSection),
(Pydocstyle, "411") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineBeforeSection), (Pydocstyle, "411") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineBeforeSection),
(Pydocstyle, "412") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLinesBetweenHeaderAndContent), (Pydocstyle, "412") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLinesBetweenHeaderAndContent),
(Pydocstyle, "413") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineAfterLastSection), (Pydocstyle, "413") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingBlankLineAfterLastSection),
(Pydocstyle, "414") => (RuleGroup::Stable, rules::pydocstyle::rules::EmptyDocstringSection), (Pydocstyle, "414") => (RuleGroup::Stable, rules::pydocstyle::rules::EmptyDocstringSection),
(Pydocstyle, "415") => (RuleGroup::Stable, rules::pydocstyle::rules::EndsInPunctuation), (Pydocstyle, "415") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingTerminalPunctuation),
(Pydocstyle, "416") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionNameEndsInColon), (Pydocstyle, "416") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingSectionNameColon),
(Pydocstyle, "417") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedParam), (Pydocstyle, "417") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedParam),
(Pydocstyle, "418") => (RuleGroup::Stable, rules::pydocstyle::rules::OverloadWithDocstring), (Pydocstyle, "418") => (RuleGroup::Stable, rules::pydocstyle::rules::OverloadWithDocstring),
(Pydocstyle, "419") => (RuleGroup::Stable, rules::pydocstyle::rules::EmptyDocstring), (Pydocstyle, "419") => (RuleGroup::Stable, rules::pydocstyle::rules::EmptyDocstring),

View File

@ -142,9 +142,11 @@ fn cmp_fix(rule1: Rule, rule2: Rule, fix1: &Fix, fix2: &Fix) -> std::cmp::Orderi
.then_with(|| fix1.min_start().cmp(&fix2.min_start())) .then_with(|| fix1.min_start().cmp(&fix2.min_start()))
// Break ties in the event of overlapping rules, for some specific combinations. // Break ties in the event of overlapping rules, for some specific combinations.
.then_with(|| match (&rule1, &rule2) { .then_with(|| match (&rule1, &rule2) {
// Apply `EndsInPeriod` fixes before `NewLineAfterLastParagraph` fixes. // Apply `MissingTrailingPeriod` fixes before `NewLineAfterLastParagraph` fixes.
(Rule::EndsInPeriod, Rule::NewLineAfterLastParagraph) => std::cmp::Ordering::Less, (Rule::MissingTrailingPeriod, Rule::NewLineAfterLastParagraph) => std::cmp::Ordering::Less,
(Rule::NewLineAfterLastParagraph, Rule::EndsInPeriod) => std::cmp::Ordering::Greater, (Rule::NewLineAfterLastParagraph, Rule::MissingTrailingPeriod) => {
std::cmp::Ordering::Greater
}
// Apply `IfElseBlockInsteadOfDictGet` fixes before `IfElseBlockInsteadOfIfExp` fixes. // Apply `IfElseBlockInsteadOfDictGet` fixes before `IfElseBlockInsteadOfIfExp` fixes.
(Rule::IfElseBlockInsteadOfDictGet, Rule::IfElseBlockInsteadOfIfExp) => { (Rule::IfElseBlockInsteadOfDictGet, Rule::IfElseBlockInsteadOfIfExp) => {
std::cmp::Ordering::Less std::cmp::Ordering::Less

View File

@ -357,9 +357,9 @@ impl Rule {
pub const INCOMPATIBLE_CODES: &[(Rule, Rule, &str); 2] = &[ pub const INCOMPATIBLE_CODES: &[(Rule, Rule, &str); 2] = &[
( (
Rule::BlankLineBeforeClass, Rule::BlankLineBeforeClass,
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
"`one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are \ "`incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are \
incompatible. Ignoring `one-blank-line-before-class`.", incompatible. Ignoring `incorrect-blank-line-before-class`.",
), ),
( (
Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummaryFirstLine,

View File

@ -17,41 +17,41 @@ mod tests {
use super::settings::{Convention, Settings}; use super::settings::{Convention, Settings};
#[test_case(Rule::BlankLineAfterLastSection, Path::new("sections.py"))] #[test_case(Rule::MissingBlankLineAfterLastSection, Path::new("sections.py"))]
#[test_case(Rule::NoBlankLineAfterSection, Path::new("sections.py"))] #[test_case(Rule::NoBlankLineAfterSection, Path::new("sections.py"))]
#[test_case(Rule::BlankLineAfterLastSection, Path::new("D413.py"))] #[test_case(Rule::MissingBlankLineAfterLastSection, Path::new("D413.py"))]
#[test_case(Rule::BlankLineAfterSummary, Path::new("D.py"))] #[test_case(Rule::MissingBlankLineAfterSummary, Path::new("D.py"))]
#[test_case(Rule::NoBlankLineBeforeSection, Path::new("sections.py"))] #[test_case(Rule::NoBlankLineBeforeSection, Path::new("sections.py"))]
#[test_case(Rule::CapitalizeSectionName, Path::new("sections.py"))] #[test_case(Rule::NonCapitalizedSectionName, Path::new("sections.py"))]
#[test_case(Rule::DashedUnderlineAfterSection, Path::new("sections.py"))] #[test_case(Rule::MissingDashedUnderlineAfterSection, Path::new("sections.py"))]
#[test_case(Rule::UndocumentedParam, Path::new("canonical_google_examples.py"))] #[test_case(Rule::UndocumentedParam, Path::new("canonical_google_examples.py"))]
#[test_case(Rule::UndocumentedParam, Path::new("canonical_numpy_examples.py"))] #[test_case(Rule::UndocumentedParam, Path::new("canonical_numpy_examples.py"))]
#[test_case(Rule::UndocumentedParam, Path::new("sections.py"))] #[test_case(Rule::UndocumentedParam, Path::new("sections.py"))]
#[test_case(Rule::EndsInPeriod, Path::new("D.py"))] #[test_case(Rule::MissingTrailingPeriod, Path::new("D.py"))]
#[test_case(Rule::EndsInPeriod, Path::new("D400.py"))] #[test_case(Rule::MissingTrailingPeriod, Path::new("D400.py"))]
#[test_case(Rule::EndsInPeriod, Path::new("D400_415.py"))] #[test_case(Rule::MissingTrailingPeriod, Path::new("D400_415.py"))]
#[test_case(Rule::EndsInPunctuation, Path::new("D.py"))] #[test_case(Rule::MissingTerminalPunctuation, Path::new("D.py"))]
#[test_case(Rule::EndsInPunctuation, Path::new("D400_415.py"))] #[test_case(Rule::MissingTerminalPunctuation, Path::new("D400_415.py"))]
#[test_case(Rule::FirstWordUncapitalized, Path::new("D.py"))] #[test_case(Rule::FirstWordUncapitalized, Path::new("D.py"))]
#[test_case(Rule::FirstWordUncapitalized, Path::new("D403.py"))] #[test_case(Rule::FirstWordUncapitalized, Path::new("D403.py"))]
#[test_case(Rule::FitsOnOneLine, Path::new("D.py"))] #[test_case(Rule::UnnecessaryMultilineDocstring, Path::new("D.py"))]
#[test_case(Rule::IndentWithSpaces, Path::new("D.py"))] #[test_case(Rule::DocstringTabIndentation, Path::new("D.py"))]
#[test_case(Rule::UndocumentedMagicMethod, Path::new("D.py"))] #[test_case(Rule::UndocumentedMagicMethod, Path::new("D.py"))]
#[test_case(Rule::MultiLineSummaryFirstLine, Path::new("D.py"))] #[test_case(Rule::MultiLineSummaryFirstLine, Path::new("D.py"))]
#[test_case(Rule::MultiLineSummarySecondLine, Path::new("D.py"))] #[test_case(Rule::MultiLineSummarySecondLine, Path::new("D.py"))]
#[test_case(Rule::NewLineAfterLastParagraph, Path::new("D.py"))] #[test_case(Rule::NewLineAfterLastParagraph, Path::new("D.py"))]
#[test_case(Rule::NewLineAfterSectionName, Path::new("sections.py"))] #[test_case(Rule::MissingNewLineAfterSectionName, Path::new("sections.py"))]
#[test_case(Rule::NoBlankLineAfterFunction, Path::new("D.py"))] #[test_case(Rule::BlankLineAfterFunction, Path::new("D.py"))]
#[test_case(Rule::FitsOnOneLine, Path::new("D200.py"))] #[test_case(Rule::UnnecessaryMultilineDocstring, Path::new("D200.py"))]
#[test_case(Rule::NoBlankLineAfterFunction, Path::new("D202.py"))] #[test_case(Rule::BlankLineAfterFunction, Path::new("D202.py"))]
#[test_case(Rule::BlankLineBeforeClass, Path::new("D.py"))] #[test_case(Rule::BlankLineBeforeClass, Path::new("D.py"))]
#[test_case(Rule::NoBlankLineBeforeFunction, Path::new("D.py"))] #[test_case(Rule::BlankLineBeforeFunction, Path::new("D.py"))]
#[test_case(Rule::BlankLinesBetweenHeaderAndContent, Path::new("sections.py"))] #[test_case(Rule::BlankLinesBetweenHeaderAndContent, Path::new("sections.py"))]
#[test_case(Rule::BlankLinesBetweenHeaderAndContent, Path::new("sphinx.py"))] #[test_case(Rule::BlankLinesBetweenHeaderAndContent, Path::new("sphinx.py"))]
#[test_case(Rule::OverIndentation, Path::new("D.py"))] #[test_case(Rule::OverIndentation, Path::new("D.py"))]
#[test_case(Rule::OverIndentation, Path::new("D208.py"))] #[test_case(Rule::OverIndentation, Path::new("D208.py"))]
#[test_case(Rule::NoSignature, Path::new("D.py"))] #[test_case(Rule::SignatureInDocstring, Path::new("D.py"))]
#[test_case(Rule::NoSignature, Path::new("D402.py"))] #[test_case(Rule::SignatureInDocstring, Path::new("D402.py"))]
#[test_case(Rule::SurroundingWhitespace, Path::new("D.py"))] #[test_case(Rule::SurroundingWhitespace, Path::new("D.py"))]
#[test_case(Rule::DocstringStartsWithThis, Path::new("D.py"))] #[test_case(Rule::DocstringStartsWithThis, Path::new("D.py"))]
#[test_case(Rule::UnderIndentation, Path::new("D.py"))] #[test_case(Rule::UnderIndentation, Path::new("D.py"))]
@ -59,8 +59,8 @@ mod tests {
#[test_case(Rule::EmptyDocstringSection, Path::new("sections.py"))] #[test_case(Rule::EmptyDocstringSection, Path::new("sections.py"))]
#[test_case(Rule::NonImperativeMood, Path::new("D401.py"))] #[test_case(Rule::NonImperativeMood, Path::new("D401.py"))]
#[test_case(Rule::NoBlankLineAfterSection, Path::new("D410.py"))] #[test_case(Rule::NoBlankLineAfterSection, Path::new("D410.py"))]
#[test_case(Rule::OneBlankLineAfterClass, Path::new("D.py"))] #[test_case(Rule::IncorrectBlankLineAfterClass, Path::new("D.py"))]
#[test_case(Rule::OneBlankLineBeforeClass, Path::new("D.py"))] #[test_case(Rule::IncorrectBlankLineBeforeClass, Path::new("D.py"))]
#[test_case(Rule::UndocumentedPublicClass, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicClass, Path::new("D.py"))]
#[test_case(Rule::UndocumentedPublicFunction, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicFunction, Path::new("D.py"))]
#[test_case(Rule::UndocumentedPublicInit, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicInit, Path::new("D.py"))]
@ -83,13 +83,13 @@ mod tests {
#[test_case(Rule::UndocumentedPublicNestedClass, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicNestedClass, Path::new("D.py"))]
#[test_case(Rule::UndocumentedPublicPackage, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicPackage, Path::new("D.py"))]
#[test_case(Rule::UndocumentedPublicPackage, Path::new("D104/__init__.py"))] #[test_case(Rule::UndocumentedPublicPackage, Path::new("D104/__init__.py"))]
#[test_case(Rule::SectionNameEndsInColon, Path::new("D.py"))] #[test_case(Rule::MissingSectionNameColon, Path::new("D.py"))]
#[test_case(Rule::SectionNotOverIndented, Path::new("sections.py"))] #[test_case(Rule::OverindentedSection, Path::new("sections.py"))]
#[test_case(Rule::SectionNotOverIndented, Path::new("D214_module.py"))] #[test_case(Rule::OverindentedSection, Path::new("D214_module.py"))]
#[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("D215.py"))] #[test_case(Rule::OverindentedSectionUnderline, Path::new("D215.py"))]
#[test_case(Rule::SectionUnderlineAfterName, Path::new("sections.py"))] #[test_case(Rule::MissingSectionUnderlineAfterName, Path::new("sections.py"))]
#[test_case(Rule::SectionUnderlineMatchesSectionLength, Path::new("sections.py"))] #[test_case(Rule::MismatchedSectionUnderlineLength, Path::new("sections.py"))]
#[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("sections.py"))] #[test_case(Rule::OverindentedSectionUnderline, Path::new("sections.py"))]
#[test_case(Rule::OverloadWithDocstring, Path::new("D.py"))] #[test_case(Rule::OverloadWithDocstring, Path::new("D.py"))]
#[test_case(Rule::EscapeSequenceInDocstring, Path::new("D.py"))] #[test_case(Rule::EscapeSequenceInDocstring, Path::new("D.py"))]
#[test_case(Rule::EscapeSequenceInDocstring, Path::new("D301.py"))] #[test_case(Rule::EscapeSequenceInDocstring, Path::new("D301.py"))]
@ -171,7 +171,7 @@ mod tests {
Path::new("pydocstyle/D209_D400.py"), Path::new("pydocstyle/D209_D400.py"),
&settings::LinterSettings::for_rules([ &settings::LinterSettings::for_rules([
Rule::NewLineAfterLastParagraph, Rule::NewLineAfterLastParagraph,
Rule::EndsInPeriod, Rule::MissingTrailingPeriod,
]), ]),
)?; )?;
assert_messages!(diagnostics); assert_messages!(diagnostics);

View File

@ -41,16 +41,16 @@ use crate::docstrings::Docstring;
/// ///
/// [PEP 257]: https://peps.python.org/pep-0257/ /// [PEP 257]: https://peps.python.org/pep-0257/
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct BlankLineAfterSummary { pub(crate) struct MissingBlankLineAfterSummary {
num_lines: usize, num_lines: usize,
} }
impl Violation for BlankLineAfterSummary { impl Violation for MissingBlankLineAfterSummary {
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let BlankLineAfterSummary { num_lines } = self; let MissingBlankLineAfterSummary { num_lines } = self;
if *num_lines == 0 { if *num_lines == 0 {
"1 blank line required between summary line and description".to_string() "1 blank line required between summary line and description".to_string()
} else { } else {
@ -85,7 +85,7 @@ pub(crate) fn blank_after_summary(checker: &mut Checker, docstring: &Docstring)
} }
if lines_count > 1 && blanks_count != 1 { if lines_count > 1 && blanks_count != 1 {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
BlankLineAfterSummary { MissingBlankLineAfterSummary {
num_lines: blanks_count, num_lines: blanks_count,
}, },
docstring.range(), docstring.range(),

View File

@ -43,9 +43,9 @@ use crate::registry::Rule;
/// ///
/// [D211]: https://docs.astral.sh/ruff/rules/blank-line-before-class /// [D211]: https://docs.astral.sh/ruff/rules/blank-line-before-class
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct OneBlankLineBeforeClass; pub(crate) struct IncorrectBlankLineBeforeClass;
impl AlwaysFixableViolation for OneBlankLineBeforeClass { impl AlwaysFixableViolation for IncorrectBlankLineBeforeClass {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
"1 blank line required before class docstring".to_string() "1 blank line required before class docstring".to_string()
@ -95,9 +95,9 @@ impl AlwaysFixableViolation for OneBlankLineBeforeClass {
/// ///
/// [PEP 257]: https://peps.python.org/pep-0257/ /// [PEP 257]: https://peps.python.org/pep-0257/
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct OneBlankLineAfterClass; pub(crate) struct IncorrectBlankLineAfterClass;
impl AlwaysFixableViolation for OneBlankLineAfterClass { impl AlwaysFixableViolation for IncorrectBlankLineAfterClass {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
"1 blank line required after class docstring".to_string() "1 blank line required after class docstring".to_string()
@ -140,7 +140,7 @@ impl AlwaysFixableViolation for OneBlankLineAfterClass {
/// ## Options /// ## Options
/// - `lint.pydocstyle.convention` /// - `lint.pydocstyle.convention`
/// ///
/// [D203]: https://docs.astral.sh/ruff/rules/one-blank-line-before-class /// [D203]: https://docs.astral.sh/ruff/rules/incorrect-blank-line-before-class
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct BlankLineBeforeClass; pub(crate) struct BlankLineBeforeClass;
@ -170,7 +170,8 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
return; return;
} }
if checker.enabled(Rule::OneBlankLineBeforeClass) || checker.enabled(Rule::BlankLineBeforeClass) if checker.enabled(Rule::IncorrectBlankLineBeforeClass)
|| checker.enabled(Rule::BlankLineBeforeClass)
{ {
let mut lines = UniversalNewlineIterator::with_offset( let mut lines = UniversalNewlineIterator::with_offset(
checker.locator().slice(between_range), checker.locator().slice(between_range),
@ -201,9 +202,10 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
checker.diagnostics.push(diagnostic); checker.diagnostics.push(diagnostic);
} }
} }
if checker.enabled(Rule::OneBlankLineBeforeClass) { if checker.enabled(Rule::IncorrectBlankLineBeforeClass) {
if blank_lines_before != 1 { if blank_lines_before != 1 {
let mut diagnostic = Diagnostic::new(OneBlankLineBeforeClass, docstring.range()); let mut diagnostic =
Diagnostic::new(IncorrectBlankLineBeforeClass, docstring.range());
// Insert one blank line before the class. // Insert one blank line before the class.
diagnostic.set_fix(Fix::safe_edit(Edit::replacement( diagnostic.set_fix(Fix::safe_edit(Edit::replacement(
checker.stylist().line_ending().to_string(), checker.stylist().line_ending().to_string(),
@ -215,7 +217,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
} }
} }
if checker.enabled(Rule::OneBlankLineAfterClass) { if checker.enabled(Rule::IncorrectBlankLineAfterClass) {
let class_after_docstring_range = TextRange::new(docstring.end(), class.end()); let class_after_docstring_range = TextRange::new(docstring.end(), class.end());
let class_after_docstring = checker.locator().slice(class_after_docstring_range); let class_after_docstring = checker.locator().slice(class_after_docstring_range);
let mut lines = UniversalNewlineIterator::with_offset( let mut lines = UniversalNewlineIterator::with_offset(
@ -242,7 +244,8 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
if let Some(next_statement) = trailing.strip_prefix(';') { if let Some(next_statement) = trailing.strip_prefix(';') {
let indentation = indentation_at_offset(docstring.start(), checker.source()) let indentation = indentation_at_offset(docstring.start(), checker.source())
.expect("Own line docstring must have indentation"); .expect("Own line docstring must have indentation");
let mut diagnostic = Diagnostic::new(OneBlankLineAfterClass, docstring.range()); let mut diagnostic =
Diagnostic::new(IncorrectBlankLineAfterClass, docstring.range());
let line_ending = checker.stylist().line_ending().as_str(); let line_ending = checker.stylist().line_ending().as_str();
// We have to trim the whitespace twice, once before the semicolon above and // We have to trim the whitespace twice, once before the semicolon above and
// once after the semicolon here, or we get invalid indents: // once after the semicolon here, or we get invalid indents:
@ -277,7 +280,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
} }
if blank_lines_after != 1 { if blank_lines_after != 1 {
let mut diagnostic = Diagnostic::new(OneBlankLineAfterClass, docstring.range()); let mut diagnostic = Diagnostic::new(IncorrectBlankLineAfterClass, docstring.range());
// Insert a blank line before the class (replacing any existing lines). // Insert a blank line before the class (replacing any existing lines).
diagnostic.set_fix(Fix::safe_edit(Edit::replacement( diagnostic.set_fix(Fix::safe_edit(Edit::replacement(
checker.stylist().line_ending().to_string(), checker.stylist().line_ending().to_string(),

View File

@ -38,14 +38,14 @@ use crate::registry::Rule;
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct NoBlankLineBeforeFunction { pub(crate) struct BlankLineBeforeFunction {
num_lines: usize, num_lines: usize,
} }
impl AlwaysFixableViolation for NoBlankLineBeforeFunction { impl AlwaysFixableViolation for BlankLineBeforeFunction {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let NoBlankLineBeforeFunction { num_lines } = self; let BlankLineBeforeFunction { num_lines } = self;
format!("No blank lines allowed before function docstring (found {num_lines})") format!("No blank lines allowed before function docstring (found {num_lines})")
} }
@ -82,14 +82,14 @@ impl AlwaysFixableViolation for NoBlankLineBeforeFunction {
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct NoBlankLineAfterFunction { pub(crate) struct BlankLineAfterFunction {
num_lines: usize, num_lines: usize,
} }
impl AlwaysFixableViolation for NoBlankLineAfterFunction { impl AlwaysFixableViolation for BlankLineAfterFunction {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let NoBlankLineAfterFunction { num_lines } = self; let BlankLineAfterFunction { num_lines } = self;
format!("No blank lines allowed after function docstring (found {num_lines})") format!("No blank lines allowed after function docstring (found {num_lines})")
} }
@ -107,7 +107,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc
return; return;
}; };
if checker.enabled(Rule::NoBlankLineBeforeFunction) { if checker.enabled(Rule::BlankLineBeforeFunction) {
let before = checker let before = checker
.locator() .locator()
.slice(TextRange::new(function.start(), docstring.start())); .slice(TextRange::new(function.start(), docstring.start()));
@ -127,7 +127,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc
if blank_lines_before != 0 { if blank_lines_before != 0 {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
NoBlankLineBeforeFunction { BlankLineBeforeFunction {
num_lines: blank_lines_before, num_lines: blank_lines_before,
}, },
docstring.range(), docstring.range(),
@ -141,7 +141,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc
} }
} }
if checker.enabled(Rule::NoBlankLineAfterFunction) { if checker.enabled(Rule::BlankLineAfterFunction) {
let after = checker let after = checker
.locator() .locator()
.slice(TextRange::new(docstring.end(), function.end())); .slice(TextRange::new(docstring.end(), function.end()));
@ -181,7 +181,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc
if blank_lines_after != 0 { if blank_lines_after != 0 {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
NoBlankLineAfterFunction { BlankLineAfterFunction {
num_lines: blank_lines_after, num_lines: blank_lines_after,
}, },
docstring.range(), docstring.range(),

View File

@ -45,9 +45,9 @@ use crate::rules::pydocstyle::helpers::logical_line;
/// ///
/// [PEP 257]: https://peps.python.org/pep-0257/ /// [PEP 257]: https://peps.python.org/pep-0257/
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct EndsInPeriod; pub(crate) struct MissingTrailingPeriod;
impl Violation for EndsInPeriod { impl Violation for MissingTrailingPeriod {
/// `None` in the case a fix is never available or otherwise Some /// `None` in the case a fix is never available or otherwise Some
/// [`FixAvailability`] describing the available fix. /// [`FixAvailability`] describing the available fix.
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
@ -106,7 +106,7 @@ pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) {
} }
if !trimmed.ends_with('.') { if !trimmed.ends_with('.') {
let mut diagnostic = Diagnostic::new(EndsInPeriod, docstring.range()); let mut diagnostic = Diagnostic::new(MissingTrailingPeriod, docstring.range());
// Best-effort fix: avoid adding a period after other punctuation marks. // Best-effort fix: avoid adding a period after other punctuation marks.
if !trimmed.ends_with([':', ';', '?', '!']) { if !trimmed.ends_with([':', ';', '?', '!']) {
diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion( diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion(

View File

@ -44,9 +44,9 @@ use crate::rules::pydocstyle::helpers::logical_line;
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct EndsInPunctuation; pub(crate) struct MissingTerminalPunctuation;
impl Violation for EndsInPunctuation { impl Violation for MissingTerminalPunctuation {
/// `None` in the case a fix is never available or otherwise Some /// `None` in the case a fix is never available or otherwise Some
/// [`FixAvailability`] describing the available fix. /// [`FixAvailability`] describing the available fix.
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
@ -105,7 +105,7 @@ pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring
} }
if !trimmed.ends_with(['.', '!', '?']) { if !trimmed.ends_with(['.', '!', '?']) {
let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range()); let mut diagnostic = Diagnostic::new(MissingTerminalPunctuation, docstring.range());
// Best-effort fix: avoid adding a period after other punctuation marks. // Best-effort fix: avoid adding a period after other punctuation marks.
if !trimmed.ends_with([':', ';']) { if !trimmed.ends_with([':', ';']) {
diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion( diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion(

View File

@ -52,9 +52,9 @@ use crate::registry::Rule;
/// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces /// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces
/// [formatter]: https://docs.astral.sh/ruff/formatter /// [formatter]: https://docs.astral.sh/ruff/formatter
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct IndentWithSpaces; pub(crate) struct DocstringTabIndentation;
impl Violation for IndentWithSpaces { impl Violation for DocstringTabIndentation {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
"Docstring should be indented with spaces, not tabs".to_string() "Docstring should be indented with spaces, not tabs".to_string()
@ -264,11 +264,11 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
current = lines.next(); current = lines.next();
} }
if checker.enabled(Rule::IndentWithSpaces) { if checker.enabled(Rule::DocstringTabIndentation) {
if has_seen_tab { if has_seen_tab {
checker checker
.diagnostics .diagnostics
.push(Diagnostic::new(IndentWithSpaces, docstring.range())); .push(Diagnostic::new(DocstringTabIndentation, docstring.range()));
} }
} }

View File

@ -41,9 +41,9 @@ use crate::docstrings::Docstring;
/// ///
/// [PEP 257]: https://peps.python.org/pep-0257/ /// [PEP 257]: https://peps.python.org/pep-0257/
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct NoSignature; pub(crate) struct SignatureInDocstring;
impl Violation for NoSignature { impl Violation for SignatureInDocstring {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
"First line should not be the function's signature".to_string() "First line should not be the function's signature".to_string()
@ -88,6 +88,6 @@ pub(crate) fn no_signature(checker: &mut Checker, docstring: &Docstring) {
{ {
checker checker
.diagnostics .diagnostics
.push(Diagnostic::new(NoSignature, docstring.range())); .push(Diagnostic::new(SignatureInDocstring, docstring.range()));
} }
} }

View File

@ -33,9 +33,9 @@ use crate::docstrings::Docstring;
/// ///
/// [PEP 257]: https://peps.python.org/pep-0257/ /// [PEP 257]: https://peps.python.org/pep-0257/
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct FitsOnOneLine; pub(crate) struct UnnecessaryMultilineDocstring;
impl Violation for FitsOnOneLine { impl Violation for UnnecessaryMultilineDocstring {
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
#[derive_message_formats] #[derive_message_formats]
@ -63,7 +63,7 @@ pub(crate) fn one_liner(checker: &mut Checker, docstring: &Docstring) {
} }
if non_empty_line_count == 1 && line_count > 1 { if non_empty_line_count == 1 && line_count > 1 {
let mut diagnostic = Diagnostic::new(FitsOnOneLine, docstring.range()); let mut diagnostic = Diagnostic::new(UnnecessaryMultilineDocstring, docstring.range());
if let (Some(leading), Some(trailing)) = ( if let (Some(leading), Some(trailing)) = (
leading_quote(docstring.contents), leading_quote(docstring.contents),
trailing_quote(docstring.contents), trailing_quote(docstring.contents),

View File

@ -90,19 +90,19 @@ use crate::rules::pydocstyle::settings::Convention;
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct SectionNotOverIndented { pub(crate) struct OverindentedSection {
name: String, name: String,
} }
impl AlwaysFixableViolation for SectionNotOverIndented { impl AlwaysFixableViolation for OverindentedSection {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let SectionNotOverIndented { name } = self; let OverindentedSection { name } = self;
format!("Section is over-indented (\"{name}\")") format!("Section is over-indented (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let SectionNotOverIndented { name } = self; let OverindentedSection { name } = self;
format!("Remove over-indentation from \"{name}\"") format!("Remove over-indentation from \"{name}\"")
} }
} }
@ -193,19 +193,19 @@ impl AlwaysFixableViolation for SectionNotOverIndented {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct SectionUnderlineNotOverIndented { pub(crate) struct OverindentedSectionUnderline {
name: String, name: String,
} }
impl AlwaysFixableViolation for SectionUnderlineNotOverIndented { impl AlwaysFixableViolation for OverindentedSectionUnderline {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let SectionUnderlineNotOverIndented { name } = self; let OverindentedSectionUnderline { name } = self;
format!("Section underline is over-indented (\"{name}\")") format!("Section underline is over-indented (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let SectionUnderlineNotOverIndented { name } = self; let OverindentedSectionUnderline { name } = self;
format!("Remove over-indentation from \"{name}\" underline") format!("Remove over-indentation from \"{name}\" underline")
} }
} }
@ -276,19 +276,19 @@ impl AlwaysFixableViolation for SectionUnderlineNotOverIndented {
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct CapitalizeSectionName { pub(crate) struct NonCapitalizedSectionName {
name: String, name: String,
} }
impl AlwaysFixableViolation for CapitalizeSectionName { impl AlwaysFixableViolation for NonCapitalizedSectionName {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let CapitalizeSectionName { name } = self; let NonCapitalizedSectionName { name } = self;
format!("Section name should be properly capitalized (\"{name}\")") format!("Section name should be properly capitalized (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let CapitalizeSectionName { name } = self; let NonCapitalizedSectionName { name } = self;
format!("Capitalize \"{name}\"") format!("Capitalize \"{name}\"")
} }
} }
@ -374,19 +374,19 @@ impl AlwaysFixableViolation for CapitalizeSectionName {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct NewLineAfterSectionName { pub(crate) struct MissingNewLineAfterSectionName {
name: String, name: String,
} }
impl AlwaysFixableViolation for NewLineAfterSectionName { impl AlwaysFixableViolation for MissingNewLineAfterSectionName {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let NewLineAfterSectionName { name } = self; let MissingNewLineAfterSectionName { name } = self;
format!("Section name should end with a newline (\"{name}\")") format!("Section name should end with a newline (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let NewLineAfterSectionName { name } = self; let MissingNewLineAfterSectionName { name } = self;
format!("Add newline after \"{name}\"") format!("Add newline after \"{name}\"")
} }
} }
@ -477,19 +477,19 @@ impl AlwaysFixableViolation for NewLineAfterSectionName {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct DashedUnderlineAfterSection { pub(crate) struct MissingDashedUnderlineAfterSection {
name: String, name: String,
} }
impl AlwaysFixableViolation for DashedUnderlineAfterSection { impl AlwaysFixableViolation for MissingDashedUnderlineAfterSection {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let DashedUnderlineAfterSection { name } = self; let MissingDashedUnderlineAfterSection { name } = self;
format!("Missing dashed underline after section (\"{name}\")") format!("Missing dashed underline after section (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let DashedUnderlineAfterSection { name } = self; let MissingDashedUnderlineAfterSection { name } = self;
format!("Add dashed line under \"{name}\"") format!("Add dashed line under \"{name}\"")
} }
} }
@ -583,19 +583,19 @@ impl AlwaysFixableViolation for DashedUnderlineAfterSection {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct SectionUnderlineAfterName { pub(crate) struct MissingSectionUnderlineAfterName {
name: String, name: String,
} }
impl AlwaysFixableViolation for SectionUnderlineAfterName { impl AlwaysFixableViolation for MissingSectionUnderlineAfterName {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let SectionUnderlineAfterName { name } = self; let MissingSectionUnderlineAfterName { name } = self;
format!("Section underline should be in the line following the section's name (\"{name}\")") format!("Section underline should be in the line following the section's name (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let SectionUnderlineAfterName { name } = self; let MissingSectionUnderlineAfterName { name } = self;
format!("Add underline to \"{name}\"") format!("Add underline to \"{name}\"")
} }
} }
@ -687,19 +687,19 @@ impl AlwaysFixableViolation for SectionUnderlineAfterName {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct SectionUnderlineMatchesSectionLength { pub(crate) struct MismatchedSectionUnderlineLength {
name: String, name: String,
} }
impl AlwaysFixableViolation for SectionUnderlineMatchesSectionLength { impl AlwaysFixableViolation for MismatchedSectionUnderlineLength {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let SectionUnderlineMatchesSectionLength { name } = self; let MismatchedSectionUnderlineLength { name } = self;
format!("Section underline should match the length of its name (\"{name}\")") format!("Section underline should match the length of its name (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let SectionUnderlineMatchesSectionLength { name } = self; let MismatchedSectionUnderlineLength { name } = self;
format!("Adjust underline length to match \"{name}\"") format!("Adjust underline length to match \"{name}\"")
} }
} }
@ -972,19 +972,19 @@ impl AlwaysFixableViolation for NoBlankLineBeforeSection {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct BlankLineAfterLastSection { pub(crate) struct MissingBlankLineAfterLastSection {
name: String, name: String,
} }
impl AlwaysFixableViolation for BlankLineAfterLastSection { impl AlwaysFixableViolation for MissingBlankLineAfterLastSection {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let BlankLineAfterLastSection { name } = self; let MissingBlankLineAfterLastSection { name } = self;
format!("Missing blank line after last section (\"{name}\")") format!("Missing blank line after last section (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let BlankLineAfterLastSection { name } = self; let MissingBlankLineAfterLastSection { name } = self;
format!("Add blank line after \"{name}\"") format!("Add blank line after \"{name}\"")
} }
} }
@ -1138,19 +1138,19 @@ impl Violation for EmptyDocstringSection {
/// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [PEP 287 reStructuredText Docstring Format](https://peps.python.org/pep-0287/)
/// - [Google Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// - [Google Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct SectionNameEndsInColon { pub(crate) struct MissingSectionNameColon {
name: String, name: String,
} }
impl AlwaysFixableViolation for SectionNameEndsInColon { impl AlwaysFixableViolation for MissingSectionNameColon {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let SectionNameEndsInColon { name } = self; let MissingSectionNameColon { name } = self;
format!("Section name should end with a colon (\"{name}\")") format!("Section name should end with a colon (\"{name}\")")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {
let SectionNameEndsInColon { name } = self; let MissingSectionNameColon { name } = self;
format!("Add colon to \"{name}\"") format!("Add colon to \"{name}\"")
} }
} }
@ -1360,9 +1360,9 @@ fn blanks_and_section_underline(
if let Some(non_blank_line) = following_lines.next() { if let Some(non_blank_line) = following_lines.next() {
if let Some(dashed_line) = find_underline(&non_blank_line, '-') { if let Some(dashed_line) = find_underline(&non_blank_line, '-') {
if num_blank_lines_after_header > 0 { if num_blank_lines_after_header > 0 {
if checker.enabled(Rule::SectionUnderlineAfterName) { if checker.enabled(Rule::MissingSectionUnderlineAfterName) {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
SectionUnderlineAfterName { MissingSectionUnderlineAfterName {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
dashed_line, dashed_line,
@ -1379,9 +1379,9 @@ fn blanks_and_section_underline(
} }
if dashed_line.len().to_usize() != context.section_name().len() { if dashed_line.len().to_usize() != context.section_name().len() {
if checker.enabled(Rule::SectionUnderlineMatchesSectionLength) { if checker.enabled(Rule::MismatchedSectionUnderlineLength) {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
SectionUnderlineMatchesSectionLength { MismatchedSectionUnderlineLength {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
dashed_line, dashed_line,
@ -1397,11 +1397,11 @@ fn blanks_and_section_underline(
} }
} }
if checker.enabled(Rule::SectionUnderlineNotOverIndented) { if checker.enabled(Rule::OverindentedSectionUnderline) {
let leading_space = leading_space(&non_blank_line); let leading_space = leading_space(&non_blank_line);
if leading_space.len() > docstring.indentation.len() { if leading_space.len() > docstring.indentation.len() {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
SectionUnderlineNotOverIndented { OverindentedSectionUnderline {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
dashed_line, dashed_line,
@ -1511,10 +1511,10 @@ fn blanks_and_section_underline(
} }
} }
} else { } else {
if style.is_numpy() && checker.enabled(Rule::DashedUnderlineAfterSection) { if style.is_numpy() && checker.enabled(Rule::MissingDashedUnderlineAfterSection) {
if let Some(equal_line) = find_underline(&non_blank_line, '=') { if let Some(equal_line) = find_underline(&non_blank_line, '=') {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
DashedUnderlineAfterSection { MissingDashedUnderlineAfterSection {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
equal_line, equal_line,
@ -1530,7 +1530,7 @@ fn blanks_and_section_underline(
checker.diagnostics.push(diagnostic); checker.diagnostics.push(diagnostic);
} else { } else {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
DashedUnderlineAfterSection { MissingDashedUnderlineAfterSection {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
context.section_name_range(), context.section_name_range(),
@ -1609,9 +1609,9 @@ fn blanks_and_section_underline(
} }
} else { } else {
// Nothing but blank lines after the section header. // Nothing but blank lines after the section header.
if style.is_numpy() && checker.enabled(Rule::DashedUnderlineAfterSection) { if style.is_numpy() && checker.enabled(Rule::MissingDashedUnderlineAfterSection) {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
DashedUnderlineAfterSection { MissingDashedUnderlineAfterSection {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
context.section_name_range(), context.section_name_range(),
@ -1649,12 +1649,12 @@ fn common_section(
next: Option<&SectionContext>, next: Option<&SectionContext>,
style: SectionStyle, style: SectionStyle,
) { ) {
if checker.enabled(Rule::CapitalizeSectionName) { if checker.enabled(Rule::NonCapitalizedSectionName) {
let capitalized_section_name = context.kind().as_str(); let capitalized_section_name = context.kind().as_str();
if context.section_name() != capitalized_section_name { if context.section_name() != capitalized_section_name {
let section_range = context.section_name_range(); let section_range = context.section_name_range();
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
CapitalizeSectionName { NonCapitalizedSectionName {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
section_range, section_range,
@ -1669,12 +1669,12 @@ fn common_section(
} }
} }
if checker.enabled(Rule::SectionNotOverIndented) { if checker.enabled(Rule::OverindentedSection) {
let leading_space = leading_space(context.summary_line()); let leading_space = leading_space(context.summary_line());
if leading_space.len() > docstring.indentation.len() { if leading_space.len() > docstring.indentation.len() {
let section_range = context.section_name_range(); let section_range = context.section_name_range();
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
SectionNotOverIndented { OverindentedSection {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
section_range, section_range,
@ -1720,7 +1720,7 @@ fn common_section(
} else { } else {
// The first blank line is the line containing the closing triple quotes, so we need at // The first blank line is the line containing the closing triple quotes, so we need at
// least two. // least two.
if checker.enabled(Rule::BlankLineAfterLastSection) { if checker.enabled(Rule::MissingBlankLineAfterLastSection) {
let num_blank_lines = context let num_blank_lines = context
.following_lines() .following_lines()
.rev() .rev()
@ -1746,7 +1746,7 @@ fn common_section(
let section_range = context.section_name_range(); let section_range = context.section_name_range();
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
BlankLineAfterLastSection { MissingBlankLineAfterLastSection {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
section_range, section_range,
@ -1950,12 +1950,12 @@ fn numpy_section(
) { ) {
common_section(checker, docstring, context, next, SectionStyle::Numpy); common_section(checker, docstring, context, next, SectionStyle::Numpy);
if checker.enabled(Rule::NewLineAfterSectionName) { if checker.enabled(Rule::MissingNewLineAfterSectionName) {
let suffix = context.summary_after_section_name(); let suffix = context.summary_after_section_name();
if !suffix.is_empty() { if !suffix.is_empty() {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
NewLineAfterSectionName { MissingNewLineAfterSectionName {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
context.section_name_range(), context.section_name_range(),
@ -1985,11 +1985,11 @@ fn google_section(
) { ) {
common_section(checker, docstring, context, next, SectionStyle::Google); common_section(checker, docstring, context, next, SectionStyle::Google);
if checker.enabled(Rule::SectionNameEndsInColon) { if checker.enabled(Rule::MissingSectionNameColon) {
let suffix = context.summary_after_section_name(); let suffix = context.summary_after_section_name();
if suffix != ":" { if suffix != ":" {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
SectionNameEndsInColon { MissingSectionNameColon {
name: context.section_name().to_string(), name: context.section_name().to_string(),
}, },
context.section_name_range(), context.section_name_range(),

View File

@ -28,47 +28,47 @@ impl Convention {
pub const fn rules_to_be_ignored(self) -> &'static [Rule] { pub const fn rules_to_be_ignored(self) -> &'static [Rule] {
match self { match self {
Convention::Google => &[ Convention::Google => &[
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
Rule::OneBlankLineAfterClass, Rule::IncorrectBlankLineAfterClass,
Rule::MultiLineSummarySecondLine, Rule::MultiLineSummarySecondLine,
Rule::SectionUnderlineNotOverIndented, Rule::OverindentedSectionUnderline,
Rule::EndsInPeriod, Rule::MissingTrailingPeriod,
Rule::NonImperativeMood, Rule::NonImperativeMood,
Rule::DocstringStartsWithThis, Rule::DocstringStartsWithThis,
Rule::NewLineAfterSectionName, Rule::MissingNewLineAfterSectionName,
Rule::DashedUnderlineAfterSection, Rule::MissingDashedUnderlineAfterSection,
Rule::SectionUnderlineAfterName, Rule::MissingSectionUnderlineAfterName,
Rule::SectionUnderlineMatchesSectionLength, Rule::MismatchedSectionUnderlineLength,
Rule::BlankLineAfterLastSection, Rule::MissingBlankLineAfterLastSection,
], ],
Convention::Numpy => &[ Convention::Numpy => &[
Rule::UndocumentedPublicInit, Rule::UndocumentedPublicInit,
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummaryFirstLine,
Rule::MultiLineSummarySecondLine, Rule::MultiLineSummarySecondLine,
Rule::NoSignature, Rule::SignatureInDocstring,
Rule::BlankLineAfterLastSection, Rule::MissingBlankLineAfterLastSection,
Rule::EndsInPunctuation, Rule::MissingTerminalPunctuation,
Rule::SectionNameEndsInColon, Rule::MissingSectionNameColon,
Rule::UndocumentedParam, Rule::UndocumentedParam,
], ],
Convention::Pep257 => &[ Convention::Pep257 => &[
Rule::OneBlankLineBeforeClass, Rule::IncorrectBlankLineBeforeClass,
Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummaryFirstLine,
Rule::MultiLineSummarySecondLine, Rule::MultiLineSummarySecondLine,
Rule::SectionNotOverIndented, Rule::OverindentedSection,
Rule::SectionUnderlineNotOverIndented, Rule::OverindentedSectionUnderline,
Rule::DocstringStartsWithThis, Rule::DocstringStartsWithThis,
Rule::CapitalizeSectionName, Rule::NonCapitalizedSectionName,
Rule::NewLineAfterSectionName, Rule::MissingNewLineAfterSectionName,
Rule::DashedUnderlineAfterSection, Rule::MissingDashedUnderlineAfterSection,
Rule::SectionUnderlineAfterName, Rule::MissingSectionUnderlineAfterName,
Rule::SectionUnderlineMatchesSectionLength, Rule::MismatchedSectionUnderlineLength,
Rule::NoBlankLineAfterSection, Rule::NoBlankLineAfterSection,
Rule::NoBlankLineBeforeSection, Rule::NoBlankLineBeforeSection,
Rule::BlankLineAfterLastSection, Rule::MissingBlankLineAfterLastSection,
Rule::EndsInPunctuation, Rule::MissingTerminalPunctuation,
Rule::SectionNameEndsInColon, Rule::MissingSectionNameColon,
Rule::UndocumentedParam, Rule::UndocumentedParam,
], ],
} }

View File

@ -503,47 +503,47 @@ then selectively enable or disable any additional rules on top of it:
``` ```
The PEP 257 convention includes all `D` errors apart from: The PEP 257 convention includes all `D` errors apart from:
[`D203`](rules/one-blank-line-before-class.md), [`D203`](rules/incorrect-blank-line-before-class.md),
[`D212`](rules/multi-line-summary-first-line.md), [`D212`](rules/multi-line-summary-first-line.md),
[`D213`](rules/multi-line-summary-second-line.md), [`D213`](rules/multi-line-summary-second-line.md),
[`D214`](rules/section-not-over-indented.md), [`D214`](rules/overindented-section.md),
[`D215`](rules/section-underline-not-over-indented.md), [`D215`](rules/overindented-section-underline.md),
[`D404`](rules/docstring-starts-with-this.md), [`D404`](rules/docstring-starts-with-this.md),
[`D405`](rules/capitalize-section-name.md), [`D405`](rules/non-capitalized-section-name.md),
[`D406`](rules/new-line-after-section-name.md), [`D406`](rules/missing-new-line-after-section-name.md),
[`D407`](rules/dashed-underline-after-section.md), [`D407`](rules/missing-dashed-underline-after-section.md),
[`D408`](rules/section-underline-after-name.md), [`D408`](rules/missing-section-underline-after-name.md),
[`D409`](rules/section-underline-matches-section-length.md), [`D409`](rules/mismatched-section-underline-length.md),
[`D410`](rules/no-blank-line-after-section.md), [`D410`](rules/no-blank-line-after-section.md),
[`D411`](rules/no-blank-line-before-section.md), [`D411`](rules/no-blank-line-before-section.md),
[`D413`](rules/no-blank-line-after-section.md), [`D413`](rules/no-blank-line-after-section.md),
[`D415`](rules/ends-in-punctuation.md), [`D415`](rules/missing-terminal-punctuation.md),
[`D416`](rules/section-name-ends-in-colon.md), and [`D416`](rules/missing-section-name-colon.md), and
[`D417`](rules/undocumented-param.md). [`D417`](rules/undocumented-param.md).
The NumPy convention includes all `D` errors apart from: The NumPy convention includes all `D` errors apart from:
[`D107`](rules/undocumented-public-init.md), [`D107`](rules/undocumented-public-init.md),
[`D203`](rules/one-blank-line-before-class.md), [`D203`](rules/incorrect-blank-line-before-class.md),
[`D212`](rules/multi-line-summary-first-line.md), [`D212`](rules/multi-line-summary-first-line.md),
[`D213`](rules/multi-line-summary-second-line.md), [`D213`](rules/multi-line-summary-second-line.md),
[`D402`](rules/no-signature.md), [`D402`](rules/signature-in-docstring.md),
[`D413`](rules/no-blank-line-after-section.md), [`D413`](rules/no-blank-line-after-section.md),
[`D415`](rules/ends-in-punctuation.md), [`D415`](rules/missing-terminal-punctuation.md),
[`D416`](rules/section-name-ends-in-colon.md), and [`D416`](rules/missing-section-name-colon.md), and
[`D417`](rules/undocumented-param.md). [`D417`](rules/undocumented-param.md).
The Google convention includes all `D` errors apart from: The Google convention includes all `D` errors apart from:
[`D203`](rules/one-blank-line-before-class.md), [`D203`](rules/incorrect-blank-line-before-class.md),
[`D204`](rules/one-blank-line-after-class.md), [`D204`](rules/incorrect-blank-line-after-class.md),
[`D213`](rules/multi-line-summary-second-line.md), [`D213`](rules/multi-line-summary-second-line.md),
[`D215`](rules/section-underline-not-over-indented.md), [`D215`](rules/overindented-section-underline.md),
[`D400`](rules/ends-in-period.md), [`D400`](rules/missing-trailing-period.md),
[`D401`](rules/non-imperative-mood.md), [`D401`](rules/non-imperative-mood.md),
[`D404`](rules/docstring-starts-with-this.md), [`D404`](rules/docstring-starts-with-this.md),
[`D406`](rules/new-line-after-section-name.md), [`D406`](rules/missing-new-line-after-section-name.md),
[`D407`](rules/dashed-underline-after-section.md), [`D407`](rules/missing-dashed-underline-after-section.md),
[`D408`](rules/section-underline-after-name.md), [`D408`](rules/missing-section-underline-after-name.md),
[`D409`](rules/section-underline-matches-section-length.md), and [`D409`](rules/mismatched-section-underline-length.md), and
[`D413`](rules/no-blank-line-after-section.md). [`D413`](rules/no-blank-line-after-section.md).
By default, no [`convention`](settings.md#lint_pydocstyle_convention) is set, and so the enabled rules By default, no [`convention`](settings.md#lint_pydocstyle_convention) is set, and so the enabled rules

View File

@ -322,7 +322,7 @@ When using Ruff as a formatter, we recommend avoiding the following lint rules:
- [`indentation-with-invalid-multiple`](rules/indentation-with-invalid-multiple.md) (`E111`) - [`indentation-with-invalid-multiple`](rules/indentation-with-invalid-multiple.md) (`E111`)
- [`indentation-with-invalid-multiple-comment`](rules/indentation-with-invalid-multiple-comment.md) (`E114`) - [`indentation-with-invalid-multiple-comment`](rules/indentation-with-invalid-multiple-comment.md) (`E114`)
- [`over-indented`](rules/over-indented.md) (`E117`) - [`over-indented`](rules/over-indented.md) (`E117`)
- [`indent-with-spaces`](rules/indent-with-spaces.md) (`D206`) - [`docstring-tab-indentation`](rules/docstring-tab-indentation.md) (`D206`)
- [`triple-single-quotes`](rules/triple-single-quotes.md) (`D300`) - [`triple-single-quotes`](rules/triple-single-quotes.md) (`D300`)
- [`bad-quotes-inline-string`](rules/bad-quotes-inline-string.md) (`Q000`) - [`bad-quotes-inline-string`](rules/bad-quotes-inline-string.md) (`Q000`)
- [`bad-quotes-multiline-string`](rules/bad-quotes-multiline-string.md) (`Q001`) - [`bad-quotes-multiline-string`](rules/bad-quotes-multiline-string.md) (`Q001`)

View File

@ -31,13 +31,16 @@ KNOWN_FORMATTING_VIOLATIONS = [
"bad-quotes-multiline-string", "bad-quotes-multiline-string",
"blank-line-after-decorator", "blank-line-after-decorator",
"blank-line-before-class", "blank-line-before-class",
"blank-line-before-function",
"blank-line-between-methods", "blank-line-between-methods",
"blank-lines-after-function-or-class", "blank-lines-after-function-or-class",
"blank-lines-before-nested-definition", "blank-lines-before-nested-definition",
"blank-lines-top-level", "blank-lines-top-level",
"docstring-tab-indentation",
"explicit-string-concatenation", "explicit-string-concatenation",
"f-string-missing-placeholders", "f-string-missing-placeholders",
"indent-with-spaces", "incorrect-blank-line-after-class",
"incorrect-blank-line-before-class",
"indentation-with-invalid-multiple", "indentation-with-invalid-multiple",
"line-too-long", "line-too-long",
"missing-trailing-comma", "missing-trailing-comma",
@ -58,14 +61,11 @@ KNOWN_FORMATTING_VIOLATIONS = [
"multiple-spaces-before-operator", "multiple-spaces-before-operator",
"multiple-statements-on-one-line-colon", "multiple-statements-on-one-line-colon",
"multiple-statements-on-one-line-semicolon", "multiple-statements-on-one-line-semicolon",
"no-blank-line-before-function",
"no-indented-block-comment", "no-indented-block-comment",
"no-return-argument-annotation-in-stub", "no-return-argument-annotation-in-stub",
"no-space-after-block-comment", "no-space-after-block-comment",
"no-space-after-inline-comment", "no-space-after-inline-comment",
"non-empty-stub-body", "non-empty-stub-body",
"one-blank-line-after-class",
"one-blank-line-before-class",
"over-indentation", "over-indentation",
"over-indented", "over-indented",
"pass-statement-stub-body", "pass-statement-stub-body",