mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Rename rules currently not conforming to naming convention (#15102)
Some checks failed
CI / Determine changes (push) Has been cancelled
CI / cargo fmt (push) Has been cancelled
CI / cargo build (release) (push) Has been cancelled
CI / python package (push) Has been cancelled
CI / pre-commit (push) Has been cancelled
CI / mkdocs (push) Has been cancelled
CI / cargo clippy (push) Has been cancelled
CI / cargo test (linux) (push) Has been cancelled
CI / cargo test (linux, release) (push) Has been cancelled
CI / cargo test (windows) (push) Has been cancelled
CI / cargo test (wasm) (push) Has been cancelled
CI / cargo build (msrv) (push) Has been cancelled
CI / cargo fuzz build (push) Has been cancelled
CI / fuzz parser (push) Has been cancelled
CI / test scripts (push) Has been cancelled
CI / ecosystem (push) Has been cancelled
CI / cargo shear (push) Has been cancelled
CI / formatter instabilities and black similarity (push) Has been cancelled
CI / test ruff-lsp (push) Has been cancelled
CI / benchmarks (push) Has been cancelled
Some checks failed
CI / Determine changes (push) Has been cancelled
CI / cargo fmt (push) Has been cancelled
CI / cargo build (release) (push) Has been cancelled
CI / python package (push) Has been cancelled
CI / pre-commit (push) Has been cancelled
CI / mkdocs (push) Has been cancelled
CI / cargo clippy (push) Has been cancelled
CI / cargo test (linux) (push) Has been cancelled
CI / cargo test (linux, release) (push) Has been cancelled
CI / cargo test (windows) (push) Has been cancelled
CI / cargo test (wasm) (push) Has been cancelled
CI / cargo build (msrv) (push) Has been cancelled
CI / cargo fuzz build (push) Has been cancelled
CI / fuzz parser (push) Has been cancelled
CI / test scripts (push) Has been cancelled
CI / ecosystem (push) Has been cancelled
CI / cargo shear (push) Has been cancelled
CI / formatter instabilities and black similarity (push) Has been cancelled
CI / test ruff-lsp (push) Has been cancelled
CI / benchmarks (push) Has been cancelled
## 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:
parent
97965ff114
commit
5bc9d6d3aa
22 changed files with 251 additions and 249 deletions
|
@ -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():
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
],
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue