diff --git a/crates/ruff/src/commands/format.rs b/crates/ruff/src/commands/format.rs index d346a323f9..2d49f0d5e0 100644 --- a/crates/ruff/src/commands/format.rs +++ b/crates/ruff/src/commands/format.rs @@ -799,7 +799,7 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) { // ``` Rule::MissingTrailingComma, // The formatter always removes blank lines before the docstring. - Rule::OneBlankLineBeforeClass, + Rule::IncorrectBlankLineBeforeClass, ] { if setting.linter.rules.enabled(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. - if setting.linter.rules.enabled(Rule::IndentWithSpaces) + if setting.linter.rules.enabled(Rule::DocstringTabIndentation) && 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\"`."); diff --git a/crates/ruff/tests/format.rs b/crates/ruff/tests/format.rs index 72dbcfbf8c..ff0ded80c7 100644 --- a/crates/ruff/tests/format.rs +++ b/crates/ruff/tests/format.rs @@ -1112,7 +1112,7 @@ def say_hy(name: str): 1 file reformatted ----- 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: 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. "); diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 759df792b3..bae45dd22f 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -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). ----- 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`. "); } diff --git a/crates/ruff_linter/resources/test/fixtures/pydocstyle/D202.py b/crates/ruff_linter/resources/test/fixtures/pydocstyle/D202.py index ea59bbc4e6..da85cb159c 100644 --- a/crates/ruff_linter/resources/test/fixtures/pydocstyle/D202.py +++ b/crates/ruff_linter/resources/test/fixtures/pydocstyle/D202.py @@ -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 def outer(): diff --git a/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs b/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs index b9e8be637d..bf3aac864b 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs @@ -34,40 +34,40 @@ pub(crate) fn definitions(checker: &mut Checker) { let enforce_stubs_and_runtime = checker.enabled(Rule::IterMethodReturnIterable); let enforce_dunder_method = checker.enabled(Rule::BadDunderMethodName); let enforce_docstrings = checker.any_enabled(&[ - Rule::BlankLineAfterLastSection, - Rule::BlankLineAfterSummary, + Rule::MissingBlankLineAfterLastSection, + Rule::MissingBlankLineAfterSummary, Rule::BlankLineBeforeClass, Rule::BlankLinesBetweenHeaderAndContent, - Rule::CapitalizeSectionName, - Rule::DashedUnderlineAfterSection, + Rule::NonCapitalizedSectionName, + Rule::MissingDashedUnderlineAfterSection, Rule::DocstringStartsWithThis, Rule::EmptyDocstring, Rule::EmptyDocstringSection, - Rule::EndsInPeriod, - Rule::EndsInPunctuation, + Rule::MissingTrailingPeriod, + Rule::MissingTerminalPunctuation, Rule::EscapeSequenceInDocstring, Rule::FirstWordUncapitalized, - Rule::FitsOnOneLine, - Rule::IndentWithSpaces, + Rule::UnnecessaryMultilineDocstring, + Rule::DocstringTabIndentation, Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummarySecondLine, Rule::NewLineAfterLastParagraph, - Rule::NewLineAfterSectionName, - Rule::NoBlankLineAfterFunction, + Rule::MissingNewLineAfterSectionName, + Rule::BlankLineAfterFunction, Rule::NoBlankLineAfterSection, - Rule::NoBlankLineBeforeFunction, + Rule::BlankLineBeforeFunction, Rule::NoBlankLineBeforeSection, - Rule::NoSignature, + Rule::SignatureInDocstring, Rule::NonImperativeMood, - Rule::OneBlankLineAfterClass, - Rule::OneBlankLineBeforeClass, + Rule::IncorrectBlankLineAfterClass, + Rule::IncorrectBlankLineBeforeClass, Rule::OverIndentation, Rule::OverloadWithDocstring, - Rule::SectionNameEndsInColon, - Rule::SectionNotOverIndented, - Rule::SectionUnderlineAfterName, - Rule::SectionUnderlineMatchesSectionLength, - Rule::SectionUnderlineNotOverIndented, + Rule::MissingSectionNameColon, + Rule::OverindentedSection, + Rule::MissingSectionUnderlineAfterName, + Rule::MismatchedSectionUnderlineLength, + Rule::OverindentedSectionUnderline, Rule::SurroundingWhitespace, Rule::TripleSingleQuotes, Rule::UnderIndentation, @@ -220,27 +220,24 @@ pub(crate) fn definitions(checker: &mut Checker) { if !pydocstyle::rules::not_empty(checker, &docstring) { continue; } - if checker.enabled(Rule::FitsOnOneLine) { + if checker.enabled(Rule::UnnecessaryMultilineDocstring) { pydocstyle::rules::one_liner(checker, &docstring); } - if checker.any_enabled(&[ - Rule::NoBlankLineAfterFunction, - Rule::NoBlankLineBeforeFunction, - ]) { + if checker.any_enabled(&[Rule::BlankLineAfterFunction, Rule::BlankLineBeforeFunction]) { pydocstyle::rules::blank_before_after_function(checker, &docstring); } if checker.any_enabled(&[ Rule::BlankLineBeforeClass, - Rule::OneBlankLineAfterClass, - Rule::OneBlankLineBeforeClass, + Rule::IncorrectBlankLineAfterClass, + Rule::IncorrectBlankLineBeforeClass, ]) { 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); } if checker.any_enabled(&[ - Rule::IndentWithSpaces, + Rule::DocstringTabIndentation, Rule::OverIndentation, Rule::UnderIndentation, ]) { @@ -264,7 +261,7 @@ pub(crate) fn definitions(checker: &mut Checker) { if checker.enabled(Rule::EscapeSequenceInDocstring) { pydocstyle::rules::backslashes(checker, &docstring); } - if checker.enabled(Rule::EndsInPeriod) { + if checker.enabled(Rule::MissingTrailingPeriod) { pydocstyle::rules::ends_with_period(checker, &docstring); } if checker.enabled(Rule::NonImperativeMood) { @@ -274,7 +271,7 @@ pub(crate) fn definitions(checker: &mut Checker) { &checker.settings.pydocstyle, ); } - if checker.enabled(Rule::NoSignature) { + if checker.enabled(Rule::SignatureInDocstring) { pydocstyle::rules::no_signature(checker, &docstring); } if checker.enabled(Rule::FirstWordUncapitalized) { @@ -283,7 +280,7 @@ pub(crate) fn definitions(checker: &mut Checker) { if checker.enabled(Rule::DocstringStartsWithThis) { pydocstyle::rules::starts_with_this(checker, &docstring); } - if checker.enabled(Rule::EndsInPunctuation) { + if checker.enabled(Rule::MissingTerminalPunctuation) { pydocstyle::rules::ends_with_punctuation(checker, &docstring); } if checker.enabled(Rule::OverloadWithDocstring) { @@ -291,20 +288,20 @@ pub(crate) fn definitions(checker: &mut Checker) { } let enforce_sections = checker.any_enabled(&[ - Rule::BlankLineAfterLastSection, + Rule::MissingBlankLineAfterLastSection, Rule::BlankLinesBetweenHeaderAndContent, - Rule::CapitalizeSectionName, - Rule::DashedUnderlineAfterSection, + Rule::NonCapitalizedSectionName, + Rule::MissingDashedUnderlineAfterSection, Rule::EmptyDocstringSection, Rule::MultiLineSummaryFirstLine, - Rule::NewLineAfterSectionName, + Rule::MissingNewLineAfterSectionName, Rule::NoBlankLineAfterSection, Rule::NoBlankLineBeforeSection, - Rule::SectionNameEndsInColon, - Rule::SectionNotOverIndented, - Rule::SectionUnderlineAfterName, - Rule::SectionUnderlineMatchesSectionLength, - Rule::SectionUnderlineNotOverIndented, + Rule::MissingSectionNameColon, + Rule::OverindentedSection, + Rule::MissingSectionUnderlineAfterName, + Rule::MismatchedSectionUnderlineLength, + Rule::OverindentedSectionUnderline, Rule::UndocumentedParam, ]); if enforce_sections || enforce_pydoclint { diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 97c28815cd..d4bff4099a 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -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, "106") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicNestedClass), (Pydocstyle, "107") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedPublicInit), - (Pydocstyle, "200") => (RuleGroup::Stable, rules::pydocstyle::rules::FitsOnOneLine), - (Pydocstyle, "201") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineBeforeFunction), - (Pydocstyle, "202") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineAfterFunction), - (Pydocstyle, "203") => (RuleGroup::Stable, rules::pydocstyle::rules::OneBlankLineBeforeClass), - (Pydocstyle, "204") => (RuleGroup::Stable, rules::pydocstyle::rules::OneBlankLineAfterClass), - (Pydocstyle, "205") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineAfterSummary), - (Pydocstyle, "206") => (RuleGroup::Stable, rules::pydocstyle::rules::IndentWithSpaces), + (Pydocstyle, "200") => (RuleGroup::Stable, rules::pydocstyle::rules::UnnecessaryMultilineDocstring), + (Pydocstyle, "201") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineBeforeFunction), + (Pydocstyle, "202") => (RuleGroup::Stable, rules::pydocstyle::rules::BlankLineAfterFunction), + (Pydocstyle, "203") => (RuleGroup::Stable, rules::pydocstyle::rules::IncorrectBlankLineBeforeClass), + (Pydocstyle, "204") => (RuleGroup::Stable, rules::pydocstyle::rules::IncorrectBlankLineAfterClass), + (Pydocstyle, "205") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingBlankLineAfterSummary), + (Pydocstyle, "206") => (RuleGroup::Stable, rules::pydocstyle::rules::DocstringTabIndentation), (Pydocstyle, "207") => (RuleGroup::Stable, rules::pydocstyle::rules::UnderIndentation), (Pydocstyle, "208") => (RuleGroup::Stable, rules::pydocstyle::rules::OverIndentation), (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, "212") => (RuleGroup::Stable, rules::pydocstyle::rules::MultiLineSummaryFirstLine), (Pydocstyle, "213") => (RuleGroup::Stable, rules::pydocstyle::rules::MultiLineSummarySecondLine), - (Pydocstyle, "214") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionNotOverIndented), - (Pydocstyle, "215") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionUnderlineNotOverIndented), + (Pydocstyle, "214") => (RuleGroup::Stable, rules::pydocstyle::rules::OverindentedSection), + (Pydocstyle, "215") => (RuleGroup::Stable, rules::pydocstyle::rules::OverindentedSectionUnderline), (Pydocstyle, "300") => (RuleGroup::Stable, rules::pydocstyle::rules::TripleSingleQuotes), (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, "402") => (RuleGroup::Stable, rules::pydocstyle::rules::NoSignature), + (Pydocstyle, "402") => (RuleGroup::Stable, rules::pydocstyle::rules::SignatureInDocstring), (Pydocstyle, "403") => (RuleGroup::Stable, rules::pydocstyle::rules::FirstWordUncapitalized), (Pydocstyle, "404") => (RuleGroup::Stable, rules::pydocstyle::rules::DocstringStartsWithThis), - (Pydocstyle, "405") => (RuleGroup::Stable, rules::pydocstyle::rules::CapitalizeSectionName), - (Pydocstyle, "406") => (RuleGroup::Stable, rules::pydocstyle::rules::NewLineAfterSectionName), - (Pydocstyle, "407") => (RuleGroup::Stable, rules::pydocstyle::rules::DashedUnderlineAfterSection), - (Pydocstyle, "408") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionUnderlineAfterName), - (Pydocstyle, "409") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionUnderlineMatchesSectionLength), + (Pydocstyle, "405") => (RuleGroup::Stable, rules::pydocstyle::rules::NonCapitalizedSectionName), + (Pydocstyle, "406") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingNewLineAfterSectionName), + (Pydocstyle, "407") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingDashedUnderlineAfterSection), + (Pydocstyle, "408") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingSectionUnderlineAfterName), + (Pydocstyle, "409") => (RuleGroup::Stable, rules::pydocstyle::rules::MismatchedSectionUnderlineLength), (Pydocstyle, "410") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineAfterSection), (Pydocstyle, "411") => (RuleGroup::Stable, rules::pydocstyle::rules::NoBlankLineBeforeSection), (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, "415") => (RuleGroup::Stable, rules::pydocstyle::rules::EndsInPunctuation), - (Pydocstyle, "416") => (RuleGroup::Stable, rules::pydocstyle::rules::SectionNameEndsInColon), + (Pydocstyle, "415") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingTerminalPunctuation), + (Pydocstyle, "416") => (RuleGroup::Stable, rules::pydocstyle::rules::MissingSectionNameColon), (Pydocstyle, "417") => (RuleGroup::Stable, rules::pydocstyle::rules::UndocumentedParam), (Pydocstyle, "418") => (RuleGroup::Stable, rules::pydocstyle::rules::OverloadWithDocstring), (Pydocstyle, "419") => (RuleGroup::Stable, rules::pydocstyle::rules::EmptyDocstring), diff --git a/crates/ruff_linter/src/fix/mod.rs b/crates/ruff_linter/src/fix/mod.rs index 6a46c7a02e..51f9775c6c 100644 --- a/crates/ruff_linter/src/fix/mod.rs +++ b/crates/ruff_linter/src/fix/mod.rs @@ -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())) // Break ties in the event of overlapping rules, for some specific combinations. .then_with(|| match (&rule1, &rule2) { - // Apply `EndsInPeriod` fixes before `NewLineAfterLastParagraph` fixes. - (Rule::EndsInPeriod, Rule::NewLineAfterLastParagraph) => std::cmp::Ordering::Less, - (Rule::NewLineAfterLastParagraph, Rule::EndsInPeriod) => std::cmp::Ordering::Greater, + // Apply `MissingTrailingPeriod` fixes before `NewLineAfterLastParagraph` fixes. + (Rule::MissingTrailingPeriod, Rule::NewLineAfterLastParagraph) => std::cmp::Ordering::Less, + (Rule::NewLineAfterLastParagraph, Rule::MissingTrailingPeriod) => { + std::cmp::Ordering::Greater + } // Apply `IfElseBlockInsteadOfDictGet` fixes before `IfElseBlockInsteadOfIfExp` fixes. (Rule::IfElseBlockInsteadOfDictGet, Rule::IfElseBlockInsteadOfIfExp) => { std::cmp::Ordering::Less diff --git a/crates/ruff_linter/src/registry.rs b/crates/ruff_linter/src/registry.rs index d20bc6a482..2ec1c86fd0 100644 --- a/crates/ruff_linter/src/registry.rs +++ b/crates/ruff_linter/src/registry.rs @@ -357,9 +357,9 @@ impl Rule { pub const INCOMPATIBLE_CODES: &[(Rule, Rule, &str); 2] = &[ ( Rule::BlankLineBeforeClass, - Rule::OneBlankLineBeforeClass, - "`one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are \ - incompatible. Ignoring `one-blank-line-before-class`.", + Rule::IncorrectBlankLineBeforeClass, + "`incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are \ + incompatible. Ignoring `incorrect-blank-line-before-class`.", ), ( Rule::MultiLineSummaryFirstLine, diff --git a/crates/ruff_linter/src/rules/pydocstyle/mod.rs b/crates/ruff_linter/src/rules/pydocstyle/mod.rs index 700633ff69..6e2be1ab7f 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/mod.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/mod.rs @@ -17,41 +17,41 @@ mod tests { 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::BlankLineAfterLastSection, Path::new("D413.py"))] - #[test_case(Rule::BlankLineAfterSummary, Path::new("D.py"))] + #[test_case(Rule::MissingBlankLineAfterLastSection, Path::new("D413.py"))] + #[test_case(Rule::MissingBlankLineAfterSummary, Path::new("D.py"))] #[test_case(Rule::NoBlankLineBeforeSection, Path::new("sections.py"))] - #[test_case(Rule::CapitalizeSectionName, Path::new("sections.py"))] - #[test_case(Rule::DashedUnderlineAfterSection, Path::new("sections.py"))] + #[test_case(Rule::NonCapitalizedSectionName, 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_numpy_examples.py"))] #[test_case(Rule::UndocumentedParam, Path::new("sections.py"))] - #[test_case(Rule::EndsInPeriod, Path::new("D.py"))] - #[test_case(Rule::EndsInPeriod, Path::new("D400.py"))] - #[test_case(Rule::EndsInPeriod, Path::new("D400_415.py"))] - #[test_case(Rule::EndsInPunctuation, Path::new("D.py"))] - #[test_case(Rule::EndsInPunctuation, Path::new("D400_415.py"))] + #[test_case(Rule::MissingTrailingPeriod, Path::new("D.py"))] + #[test_case(Rule::MissingTrailingPeriod, Path::new("D400.py"))] + #[test_case(Rule::MissingTrailingPeriod, Path::new("D400_415.py"))] + #[test_case(Rule::MissingTerminalPunctuation, Path::new("D.py"))] + #[test_case(Rule::MissingTerminalPunctuation, Path::new("D400_415.py"))] #[test_case(Rule::FirstWordUncapitalized, Path::new("D.py"))] #[test_case(Rule::FirstWordUncapitalized, Path::new("D403.py"))] - #[test_case(Rule::FitsOnOneLine, Path::new("D.py"))] - #[test_case(Rule::IndentWithSpaces, Path::new("D.py"))] + #[test_case(Rule::UnnecessaryMultilineDocstring, Path::new("D.py"))] + #[test_case(Rule::DocstringTabIndentation, Path::new("D.py"))] #[test_case(Rule::UndocumentedMagicMethod, Path::new("D.py"))] #[test_case(Rule::MultiLineSummaryFirstLine, Path::new("D.py"))] #[test_case(Rule::MultiLineSummarySecondLine, Path::new("D.py"))] #[test_case(Rule::NewLineAfterLastParagraph, Path::new("D.py"))] - #[test_case(Rule::NewLineAfterSectionName, Path::new("sections.py"))] - #[test_case(Rule::NoBlankLineAfterFunction, Path::new("D.py"))] - #[test_case(Rule::FitsOnOneLine, Path::new("D200.py"))] - #[test_case(Rule::NoBlankLineAfterFunction, Path::new("D202.py"))] + #[test_case(Rule::MissingNewLineAfterSectionName, Path::new("sections.py"))] + #[test_case(Rule::BlankLineAfterFunction, Path::new("D.py"))] + #[test_case(Rule::UnnecessaryMultilineDocstring, Path::new("D200.py"))] + #[test_case(Rule::BlankLineAfterFunction, Path::new("D202.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("sphinx.py"))] #[test_case(Rule::OverIndentation, Path::new("D.py"))] #[test_case(Rule::OverIndentation, Path::new("D208.py"))] - #[test_case(Rule::NoSignature, Path::new("D.py"))] - #[test_case(Rule::NoSignature, Path::new("D402.py"))] + #[test_case(Rule::SignatureInDocstring, Path::new("D.py"))] + #[test_case(Rule::SignatureInDocstring, Path::new("D402.py"))] #[test_case(Rule::SurroundingWhitespace, Path::new("D.py"))] #[test_case(Rule::DocstringStartsWithThis, 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::NonImperativeMood, Path::new("D401.py"))] #[test_case(Rule::NoBlankLineAfterSection, Path::new("D410.py"))] - #[test_case(Rule::OneBlankLineAfterClass, Path::new("D.py"))] - #[test_case(Rule::OneBlankLineBeforeClass, Path::new("D.py"))] + #[test_case(Rule::IncorrectBlankLineAfterClass, Path::new("D.py"))] + #[test_case(Rule::IncorrectBlankLineBeforeClass, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicClass, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicFunction, 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::UndocumentedPublicPackage, Path::new("D.py"))] #[test_case(Rule::UndocumentedPublicPackage, Path::new("D104/__init__.py"))] - #[test_case(Rule::SectionNameEndsInColon, Path::new("D.py"))] - #[test_case(Rule::SectionNotOverIndented, Path::new("sections.py"))] - #[test_case(Rule::SectionNotOverIndented, Path::new("D214_module.py"))] - #[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("D215.py"))] - #[test_case(Rule::SectionUnderlineAfterName, Path::new("sections.py"))] - #[test_case(Rule::SectionUnderlineMatchesSectionLength, Path::new("sections.py"))] - #[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("sections.py"))] + #[test_case(Rule::MissingSectionNameColon, Path::new("D.py"))] + #[test_case(Rule::OverindentedSection, Path::new("sections.py"))] + #[test_case(Rule::OverindentedSection, Path::new("D214_module.py"))] + #[test_case(Rule::OverindentedSectionUnderline, Path::new("D215.py"))] + #[test_case(Rule::MissingSectionUnderlineAfterName, Path::new("sections.py"))] + #[test_case(Rule::MismatchedSectionUnderlineLength, Path::new("sections.py"))] + #[test_case(Rule::OverindentedSectionUnderline, Path::new("sections.py"))] #[test_case(Rule::OverloadWithDocstring, Path::new("D.py"))] #[test_case(Rule::EscapeSequenceInDocstring, Path::new("D.py"))] #[test_case(Rule::EscapeSequenceInDocstring, Path::new("D301.py"))] @@ -171,7 +171,7 @@ mod tests { Path::new("pydocstyle/D209_D400.py"), &settings::LinterSettings::for_rules([ Rule::NewLineAfterLastParagraph, - Rule::EndsInPeriod, + Rule::MissingTrailingPeriod, ]), )?; assert_messages!(diagnostics); diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs index c6e773725c..5fc4936780 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -41,16 +41,16 @@ use crate::docstrings::Docstring; /// /// [PEP 257]: https://peps.python.org/pep-0257/ #[derive(ViolationMetadata)] -pub(crate) struct BlankLineAfterSummary { +pub(crate) struct MissingBlankLineAfterSummary { num_lines: usize, } -impl Violation for BlankLineAfterSummary { +impl Violation for MissingBlankLineAfterSummary { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; #[derive_message_formats] fn message(&self) -> String { - let BlankLineAfterSummary { num_lines } = self; + let MissingBlankLineAfterSummary { num_lines } = self; if *num_lines == 0 { "1 blank line required between summary line and description".to_string() } else { @@ -85,7 +85,7 @@ pub(crate) fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) } if lines_count > 1 && blanks_count != 1 { let mut diagnostic = Diagnostic::new( - BlankLineAfterSummary { + MissingBlankLineAfterSummary { num_lines: blanks_count, }, docstring.range(), diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs index 745427bb7e..c640183ef7 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs @@ -43,9 +43,9 @@ use crate::registry::Rule; /// /// [D211]: https://docs.astral.sh/ruff/rules/blank-line-before-class #[derive(ViolationMetadata)] -pub(crate) struct OneBlankLineBeforeClass; +pub(crate) struct IncorrectBlankLineBeforeClass; -impl AlwaysFixableViolation for OneBlankLineBeforeClass { +impl AlwaysFixableViolation for IncorrectBlankLineBeforeClass { #[derive_message_formats] fn message(&self) -> 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/ #[derive(ViolationMetadata)] -pub(crate) struct OneBlankLineAfterClass; +pub(crate) struct IncorrectBlankLineAfterClass; -impl AlwaysFixableViolation for OneBlankLineAfterClass { +impl AlwaysFixableViolation for IncorrectBlankLineAfterClass { #[derive_message_formats] fn message(&self) -> String { "1 blank line required after class docstring".to_string() @@ -140,7 +140,7 @@ impl AlwaysFixableViolation for OneBlankLineAfterClass { /// ## Options /// - `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)] pub(crate) struct BlankLineBeforeClass; @@ -170,7 +170,8 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr 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( 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); } } - if checker.enabled(Rule::OneBlankLineBeforeClass) { + if checker.enabled(Rule::IncorrectBlankLineBeforeClass) { 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. diagnostic.set_fix(Fix::safe_edit(Edit::replacement( 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 = checker.locator().slice(class_after_docstring_range); 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(';') { let indentation = indentation_at_offset(docstring.start(), checker.source()) .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(); // We have to trim the whitespace twice, once before the semicolon above and // 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 { - 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). diagnostic.set_fix(Fix::safe_edit(Edit::replacement( checker.stylist().line_ending().to_string(), diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs index 00313474db..b7ff84031b 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs @@ -38,14 +38,14 @@ use crate::registry::Rule; /// - [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) #[derive(ViolationMetadata)] -pub(crate) struct NoBlankLineBeforeFunction { +pub(crate) struct BlankLineBeforeFunction { num_lines: usize, } -impl AlwaysFixableViolation for NoBlankLineBeforeFunction { +impl AlwaysFixableViolation for BlankLineBeforeFunction { #[derive_message_formats] 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})") } @@ -82,14 +82,14 @@ impl AlwaysFixableViolation for NoBlankLineBeforeFunction { /// - [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) #[derive(ViolationMetadata)] -pub(crate) struct NoBlankLineAfterFunction { +pub(crate) struct BlankLineAfterFunction { num_lines: usize, } -impl AlwaysFixableViolation for NoBlankLineAfterFunction { +impl AlwaysFixableViolation for BlankLineAfterFunction { #[derive_message_formats] 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})") } @@ -107,7 +107,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc return; }; - if checker.enabled(Rule::NoBlankLineBeforeFunction) { + if checker.enabled(Rule::BlankLineBeforeFunction) { let before = checker .locator() .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 { let mut diagnostic = Diagnostic::new( - NoBlankLineBeforeFunction { + BlankLineBeforeFunction { num_lines: blank_lines_before, }, 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 .locator() .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 { let mut diagnostic = Diagnostic::new( - NoBlankLineAfterFunction { + BlankLineAfterFunction { num_lines: blank_lines_after, }, docstring.range(), diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs index c50602e3a2..2b89579e1b 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs @@ -45,9 +45,9 @@ use crate::rules::pydocstyle::helpers::logical_line; /// /// [PEP 257]: https://peps.python.org/pep-0257/ #[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 /// [`FixAvailability`] describing the available fix. 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('.') { - 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. if !trimmed.ends_with([':', ';', '?', '!']) { diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion( diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs index b32cbe898c..17fdf9dfce 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -44,9 +44,9 @@ use crate::rules::pydocstyle::helpers::logical_line; /// - [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) #[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 /// [`FixAvailability`] describing the available fix. 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(['.', '!', '?']) { - 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. if !trimmed.ends_with([':', ';']) { diagnostic.set_fix(Fix::unsafe_edit(Edit::insertion( diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs index fe287104ad..ae59026687 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs @@ -52,9 +52,9 @@ use crate::registry::Rule; /// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces /// [formatter]: https://docs.astral.sh/ruff/formatter #[derive(ViolationMetadata)] -pub(crate) struct IndentWithSpaces; +pub(crate) struct DocstringTabIndentation; -impl Violation for IndentWithSpaces { +impl Violation for DocstringTabIndentation { #[derive_message_formats] fn message(&self) -> 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(); } - if checker.enabled(Rule::IndentWithSpaces) { + if checker.enabled(Rule::DocstringTabIndentation) { if has_seen_tab { checker .diagnostics - .push(Diagnostic::new(IndentWithSpaces, docstring.range())); + .push(Diagnostic::new(DocstringTabIndentation, docstring.range())); } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs index 6daeeb5045..2ae17806c5 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs @@ -41,9 +41,9 @@ use crate::docstrings::Docstring; /// /// [PEP 257]: https://peps.python.org/pep-0257/ #[derive(ViolationMetadata)] -pub(crate) struct NoSignature; +pub(crate) struct SignatureInDocstring; -impl Violation for NoSignature { +impl Violation for SignatureInDocstring { #[derive_message_formats] fn message(&self) -> 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 .diagnostics - .push(Diagnostic::new(NoSignature, docstring.range())); + .push(Diagnostic::new(SignatureInDocstring, docstring.range())); } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs index d4b422138e..bcfc4b9dea 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs @@ -33,9 +33,9 @@ use crate::docstrings::Docstring; /// /// [PEP 257]: https://peps.python.org/pep-0257/ #[derive(ViolationMetadata)] -pub(crate) struct FitsOnOneLine; +pub(crate) struct UnnecessaryMultilineDocstring; -impl Violation for FitsOnOneLine { +impl Violation for UnnecessaryMultilineDocstring { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; #[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 { - let mut diagnostic = Diagnostic::new(FitsOnOneLine, docstring.range()); + let mut diagnostic = Diagnostic::new(UnnecessaryMultilineDocstring, docstring.range()); if let (Some(leading), Some(trailing)) = ( leading_quote(docstring.contents), trailing_quote(docstring.contents), diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs index 7f5c120867..de2e41f619 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs @@ -90,19 +90,19 @@ use crate::rules::pydocstyle::settings::Convention; /// - [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) #[derive(ViolationMetadata)] -pub(crate) struct SectionNotOverIndented { +pub(crate) struct OverindentedSection { name: String, } -impl AlwaysFixableViolation for SectionNotOverIndented { +impl AlwaysFixableViolation for OverindentedSection { #[derive_message_formats] fn message(&self) -> String { - let SectionNotOverIndented { name } = self; + let OverindentedSection { name } = self; format!("Section is over-indented (\"{name}\")") } fn fix_title(&self) -> String { - let SectionNotOverIndented { name } = self; + let OverindentedSection { name } = self; 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/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) #[derive(ViolationMetadata)] -pub(crate) struct SectionUnderlineNotOverIndented { +pub(crate) struct OverindentedSectionUnderline { name: String, } -impl AlwaysFixableViolation for SectionUnderlineNotOverIndented { +impl AlwaysFixableViolation for OverindentedSectionUnderline { #[derive_message_formats] fn message(&self) -> String { - let SectionUnderlineNotOverIndented { name } = self; + let OverindentedSectionUnderline { name } = self; format!("Section underline is over-indented (\"{name}\")") } fn fix_title(&self) -> String { - let SectionUnderlineNotOverIndented { name } = self; + let OverindentedSectionUnderline { name } = self; 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) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) #[derive(ViolationMetadata)] -pub(crate) struct CapitalizeSectionName { +pub(crate) struct NonCapitalizedSectionName { name: String, } -impl AlwaysFixableViolation for CapitalizeSectionName { +impl AlwaysFixableViolation for NonCapitalizedSectionName { #[derive_message_formats] fn message(&self) -> String { - let CapitalizeSectionName { name } = self; + let NonCapitalizedSectionName { name } = self; format!("Section name should be properly capitalized (\"{name}\")") } fn fix_title(&self) -> String { - let CapitalizeSectionName { name } = self; + let NonCapitalizedSectionName { name } = self; format!("Capitalize \"{name}\"") } } @@ -374,19 +374,19 @@ impl AlwaysFixableViolation for CapitalizeSectionName { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) #[derive(ViolationMetadata)] -pub(crate) struct NewLineAfterSectionName { +pub(crate) struct MissingNewLineAfterSectionName { name: String, } -impl AlwaysFixableViolation for NewLineAfterSectionName { +impl AlwaysFixableViolation for MissingNewLineAfterSectionName { #[derive_message_formats] fn message(&self) -> String { - let NewLineAfterSectionName { name } = self; + let MissingNewLineAfterSectionName { name } = self; format!("Section name should end with a newline (\"{name}\")") } fn fix_title(&self) -> String { - let NewLineAfterSectionName { name } = self; + let MissingNewLineAfterSectionName { name } = self; format!("Add newline after \"{name}\"") } } @@ -477,19 +477,19 @@ impl AlwaysFixableViolation for NewLineAfterSectionName { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) #[derive(ViolationMetadata)] -pub(crate) struct DashedUnderlineAfterSection { +pub(crate) struct MissingDashedUnderlineAfterSection { name: String, } -impl AlwaysFixableViolation for DashedUnderlineAfterSection { +impl AlwaysFixableViolation for MissingDashedUnderlineAfterSection { #[derive_message_formats] fn message(&self) -> String { - let DashedUnderlineAfterSection { name } = self; + let MissingDashedUnderlineAfterSection { name } = self; format!("Missing dashed underline after section (\"{name}\")") } fn fix_title(&self) -> String { - let DashedUnderlineAfterSection { name } = self; + let MissingDashedUnderlineAfterSection { name } = self; 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/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) #[derive(ViolationMetadata)] -pub(crate) struct SectionUnderlineAfterName { +pub(crate) struct MissingSectionUnderlineAfterName { name: String, } -impl AlwaysFixableViolation for SectionUnderlineAfterName { +impl AlwaysFixableViolation for MissingSectionUnderlineAfterName { #[derive_message_formats] 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}\")") } fn fix_title(&self) -> String { - let SectionUnderlineAfterName { name } = self; + let MissingSectionUnderlineAfterName { name } = self; format!("Add underline to \"{name}\"") } } @@ -687,19 +687,19 @@ impl AlwaysFixableViolation for SectionUnderlineAfterName { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) #[derive(ViolationMetadata)] -pub(crate) struct SectionUnderlineMatchesSectionLength { +pub(crate) struct MismatchedSectionUnderlineLength { name: String, } -impl AlwaysFixableViolation for SectionUnderlineMatchesSectionLength { +impl AlwaysFixableViolation for MismatchedSectionUnderlineLength { #[derive_message_formats] fn message(&self) -> String { - let SectionUnderlineMatchesSectionLength { name } = self; + let MismatchedSectionUnderlineLength { name } = self; format!("Section underline should match the length of its name (\"{name}\")") } fn fix_title(&self) -> String { - let SectionUnderlineMatchesSectionLength { name } = self; + let MismatchedSectionUnderlineLength { name } = self; 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/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) #[derive(ViolationMetadata)] -pub(crate) struct BlankLineAfterLastSection { +pub(crate) struct MissingBlankLineAfterLastSection { name: String, } -impl AlwaysFixableViolation for BlankLineAfterLastSection { +impl AlwaysFixableViolation for MissingBlankLineAfterLastSection { #[derive_message_formats] fn message(&self) -> String { - let BlankLineAfterLastSection { name } = self; + let MissingBlankLineAfterLastSection { name } = self; format!("Missing blank line after last section (\"{name}\")") } fn fix_title(&self) -> String { - let BlankLineAfterLastSection { name } = self; + let MissingBlankLineAfterLastSection { name } = self; 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/) /// - [Google Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) #[derive(ViolationMetadata)] -pub(crate) struct SectionNameEndsInColon { +pub(crate) struct MissingSectionNameColon { name: String, } -impl AlwaysFixableViolation for SectionNameEndsInColon { +impl AlwaysFixableViolation for MissingSectionNameColon { #[derive_message_formats] fn message(&self) -> String { - let SectionNameEndsInColon { name } = self; + let MissingSectionNameColon { name } = self; format!("Section name should end with a colon (\"{name}\")") } fn fix_title(&self) -> String { - let SectionNameEndsInColon { name } = self; + let MissingSectionNameColon { name } = self; 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(dashed_line) = find_underline(&non_blank_line, '-') { if num_blank_lines_after_header > 0 { - if checker.enabled(Rule::SectionUnderlineAfterName) { + if checker.enabled(Rule::MissingSectionUnderlineAfterName) { let mut diagnostic = Diagnostic::new( - SectionUnderlineAfterName { + MissingSectionUnderlineAfterName { name: context.section_name().to_string(), }, dashed_line, @@ -1379,9 +1379,9 @@ fn blanks_and_section_underline( } 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( - SectionUnderlineMatchesSectionLength { + MismatchedSectionUnderlineLength { name: context.section_name().to_string(), }, 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); if leading_space.len() > docstring.indentation.len() { let mut diagnostic = Diagnostic::new( - SectionUnderlineNotOverIndented { + OverindentedSectionUnderline { name: context.section_name().to_string(), }, dashed_line, @@ -1511,10 +1511,10 @@ fn blanks_and_section_underline( } } } 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, '=') { let mut diagnostic = Diagnostic::new( - DashedUnderlineAfterSection { + MissingDashedUnderlineAfterSection { name: context.section_name().to_string(), }, equal_line, @@ -1530,7 +1530,7 @@ fn blanks_and_section_underline( checker.diagnostics.push(diagnostic); } else { let mut diagnostic = Diagnostic::new( - DashedUnderlineAfterSection { + MissingDashedUnderlineAfterSection { name: context.section_name().to_string(), }, context.section_name_range(), @@ -1609,9 +1609,9 @@ fn blanks_and_section_underline( } } else { // 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( - DashedUnderlineAfterSection { + MissingDashedUnderlineAfterSection { name: context.section_name().to_string(), }, context.section_name_range(), @@ -1649,12 +1649,12 @@ fn common_section( next: Option<&SectionContext>, style: SectionStyle, ) { - if checker.enabled(Rule::CapitalizeSectionName) { + if checker.enabled(Rule::NonCapitalizedSectionName) { let capitalized_section_name = context.kind().as_str(); if context.section_name() != capitalized_section_name { let section_range = context.section_name_range(); let mut diagnostic = Diagnostic::new( - CapitalizeSectionName { + NonCapitalizedSectionName { name: context.section_name().to_string(), }, 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()); if leading_space.len() > docstring.indentation.len() { let section_range = context.section_name_range(); let mut diagnostic = Diagnostic::new( - SectionNotOverIndented { + OverindentedSection { name: context.section_name().to_string(), }, section_range, @@ -1720,7 +1720,7 @@ fn common_section( } else { // The first blank line is the line containing the closing triple quotes, so we need at // least two. - if checker.enabled(Rule::BlankLineAfterLastSection) { + if checker.enabled(Rule::MissingBlankLineAfterLastSection) { let num_blank_lines = context .following_lines() .rev() @@ -1746,7 +1746,7 @@ fn common_section( let section_range = context.section_name_range(); let mut diagnostic = Diagnostic::new( - BlankLineAfterLastSection { + MissingBlankLineAfterLastSection { name: context.section_name().to_string(), }, section_range, @@ -1950,12 +1950,12 @@ fn numpy_section( ) { 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(); if !suffix.is_empty() { let mut diagnostic = Diagnostic::new( - NewLineAfterSectionName { + MissingNewLineAfterSectionName { name: context.section_name().to_string(), }, context.section_name_range(), @@ -1985,11 +1985,11 @@ fn google_section( ) { 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(); if suffix != ":" { let mut diagnostic = Diagnostic::new( - SectionNameEndsInColon { + MissingSectionNameColon { name: context.section_name().to_string(), }, context.section_name_range(), diff --git a/crates/ruff_linter/src/rules/pydocstyle/settings.rs b/crates/ruff_linter/src/rules/pydocstyle/settings.rs index c8b05ba3c5..933c5b2364 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/settings.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/settings.rs @@ -28,47 +28,47 @@ impl Convention { pub const fn rules_to_be_ignored(self) -> &'static [Rule] { match self { Convention::Google => &[ - Rule::OneBlankLineBeforeClass, - Rule::OneBlankLineAfterClass, + Rule::IncorrectBlankLineBeforeClass, + Rule::IncorrectBlankLineAfterClass, Rule::MultiLineSummarySecondLine, - Rule::SectionUnderlineNotOverIndented, - Rule::EndsInPeriod, + Rule::OverindentedSectionUnderline, + Rule::MissingTrailingPeriod, Rule::NonImperativeMood, Rule::DocstringStartsWithThis, - Rule::NewLineAfterSectionName, - Rule::DashedUnderlineAfterSection, - Rule::SectionUnderlineAfterName, - Rule::SectionUnderlineMatchesSectionLength, - Rule::BlankLineAfterLastSection, + Rule::MissingNewLineAfterSectionName, + Rule::MissingDashedUnderlineAfterSection, + Rule::MissingSectionUnderlineAfterName, + Rule::MismatchedSectionUnderlineLength, + Rule::MissingBlankLineAfterLastSection, ], Convention::Numpy => &[ Rule::UndocumentedPublicInit, - Rule::OneBlankLineBeforeClass, + Rule::IncorrectBlankLineBeforeClass, Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummarySecondLine, - Rule::NoSignature, - Rule::BlankLineAfterLastSection, - Rule::EndsInPunctuation, - Rule::SectionNameEndsInColon, + Rule::SignatureInDocstring, + Rule::MissingBlankLineAfterLastSection, + Rule::MissingTerminalPunctuation, + Rule::MissingSectionNameColon, Rule::UndocumentedParam, ], Convention::Pep257 => &[ - Rule::OneBlankLineBeforeClass, + Rule::IncorrectBlankLineBeforeClass, Rule::MultiLineSummaryFirstLine, Rule::MultiLineSummarySecondLine, - Rule::SectionNotOverIndented, - Rule::SectionUnderlineNotOverIndented, + Rule::OverindentedSection, + Rule::OverindentedSectionUnderline, Rule::DocstringStartsWithThis, - Rule::CapitalizeSectionName, - Rule::NewLineAfterSectionName, - Rule::DashedUnderlineAfterSection, - Rule::SectionUnderlineAfterName, - Rule::SectionUnderlineMatchesSectionLength, + Rule::NonCapitalizedSectionName, + Rule::MissingNewLineAfterSectionName, + Rule::MissingDashedUnderlineAfterSection, + Rule::MissingSectionUnderlineAfterName, + Rule::MismatchedSectionUnderlineLength, Rule::NoBlankLineAfterSection, Rule::NoBlankLineBeforeSection, - Rule::BlankLineAfterLastSection, - Rule::EndsInPunctuation, - Rule::SectionNameEndsInColon, + Rule::MissingBlankLineAfterLastSection, + Rule::MissingTerminalPunctuation, + Rule::MissingSectionNameColon, Rule::UndocumentedParam, ], } diff --git a/docs/faq.md b/docs/faq.md index 42b24904d4..2c1227b811 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -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: -[`D203`](rules/one-blank-line-before-class.md), +[`D203`](rules/incorrect-blank-line-before-class.md), [`D212`](rules/multi-line-summary-first-line.md), [`D213`](rules/multi-line-summary-second-line.md), -[`D214`](rules/section-not-over-indented.md), -[`D215`](rules/section-underline-not-over-indented.md), +[`D214`](rules/overindented-section.md), +[`D215`](rules/overindented-section-underline.md), [`D404`](rules/docstring-starts-with-this.md), -[`D405`](rules/capitalize-section-name.md), -[`D406`](rules/new-line-after-section-name.md), -[`D407`](rules/dashed-underline-after-section.md), -[`D408`](rules/section-underline-after-name.md), -[`D409`](rules/section-underline-matches-section-length.md), +[`D405`](rules/non-capitalized-section-name.md), +[`D406`](rules/missing-new-line-after-section-name.md), +[`D407`](rules/missing-dashed-underline-after-section.md), +[`D408`](rules/missing-section-underline-after-name.md), +[`D409`](rules/mismatched-section-underline-length.md), [`D410`](rules/no-blank-line-after-section.md), [`D411`](rules/no-blank-line-before-section.md), [`D413`](rules/no-blank-line-after-section.md), -[`D415`](rules/ends-in-punctuation.md), -[`D416`](rules/section-name-ends-in-colon.md), and +[`D415`](rules/missing-terminal-punctuation.md), +[`D416`](rules/missing-section-name-colon.md), and [`D417`](rules/undocumented-param.md). The NumPy convention includes all `D` errors apart from: [`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), [`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), -[`D415`](rules/ends-in-punctuation.md), -[`D416`](rules/section-name-ends-in-colon.md), and +[`D415`](rules/missing-terminal-punctuation.md), +[`D416`](rules/missing-section-name-colon.md), and [`D417`](rules/undocumented-param.md). The Google convention includes all `D` errors apart from: -[`D203`](rules/one-blank-line-before-class.md), -[`D204`](rules/one-blank-line-after-class.md), +[`D203`](rules/incorrect-blank-line-before-class.md), +[`D204`](rules/incorrect-blank-line-after-class.md), [`D213`](rules/multi-line-summary-second-line.md), -[`D215`](rules/section-underline-not-over-indented.md), -[`D400`](rules/ends-in-period.md), +[`D215`](rules/overindented-section-underline.md), +[`D400`](rules/missing-trailing-period.md), [`D401`](rules/non-imperative-mood.md), [`D404`](rules/docstring-starts-with-this.md), -[`D406`](rules/new-line-after-section-name.md), -[`D407`](rules/dashed-underline-after-section.md), -[`D408`](rules/section-underline-after-name.md), -[`D409`](rules/section-underline-matches-section-length.md), and +[`D406`](rules/missing-new-line-after-section-name.md), +[`D407`](rules/missing-dashed-underline-after-section.md), +[`D408`](rules/missing-section-underline-after-name.md), +[`D409`](rules/mismatched-section-underline-length.md), and [`D413`](rules/no-blank-line-after-section.md). By default, no [`convention`](settings.md#lint_pydocstyle_convention) is set, and so the enabled rules diff --git a/docs/formatter.md b/docs/formatter.md index bf5d13231d..6dcc976706 100644 --- a/docs/formatter.md +++ b/docs/formatter.md @@ -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-comment`](rules/indentation-with-invalid-multiple-comment.md) (`E114`) - [`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`) - [`bad-quotes-inline-string`](rules/bad-quotes-inline-string.md) (`Q000`) - [`bad-quotes-multiline-string`](rules/bad-quotes-multiline-string.md) (`Q001`) diff --git a/scripts/check_docs_formatted.py b/scripts/check_docs_formatted.py index c262722056..7a8135e002 100755 --- a/scripts/check_docs_formatted.py +++ b/scripts/check_docs_formatted.py @@ -31,13 +31,16 @@ KNOWN_FORMATTING_VIOLATIONS = [ "bad-quotes-multiline-string", "blank-line-after-decorator", "blank-line-before-class", + "blank-line-before-function", "blank-line-between-methods", "blank-lines-after-function-or-class", "blank-lines-before-nested-definition", "blank-lines-top-level", + "docstring-tab-indentation", "explicit-string-concatenation", "f-string-missing-placeholders", - "indent-with-spaces", + "incorrect-blank-line-after-class", + "incorrect-blank-line-before-class", "indentation-with-invalid-multiple", "line-too-long", "missing-trailing-comma", @@ -58,14 +61,11 @@ KNOWN_FORMATTING_VIOLATIONS = [ "multiple-spaces-before-operator", "multiple-statements-on-one-line-colon", "multiple-statements-on-one-line-semicolon", - "no-blank-line-before-function", "no-indented-block-comment", "no-return-argument-annotation-in-stub", "no-space-after-block-comment", "no-space-after-inline-comment", "non-empty-stub-body", - "one-blank-line-after-class", - "one-blank-line-before-class", "over-indentation", "over-indented", "pass-statement-stub-body",