Skip to content

Commit

Permalink
Rename a bunch of pydocstyle rules
Browse files Browse the repository at this point in the history
  • Loading branch information
not-my-profile authored and charliermarsh committed Feb 11, 2023
1 parent 31d0093 commit 42924c0
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 110 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ For more, see [pydocstyle](https://pypi.org/project/pydocstyle/) on PyPI.
| D401 | non-imperative-mood | First line of docstring should be in imperative mood: "{first_line}" | |
| D402 | no-signature | First line should not be the function's signature | |
| D403 | first-line-capitalized | First word of the first line should be properly capitalized | |
| D404 | no-this-prefix | First word of the docstring should not be "This" | |
| D404 | docstring-starts-with-this | First word of the docstring should not be "This" | |
| D405 | capitalize-section-name | Section name should be properly capitalized ("{name}") | 🛠 |
| D406 | new-line-after-section-name | Section name should end with a newline ("{name}") | 🛠 |
| D407 | dashed-underline-after-section | Missing dashed underline after section ("{name}") | 🛠 |
Expand All @@ -828,12 +828,12 @@ For more, see [pydocstyle](https://pypi.org/project/pydocstyle/) on PyPI.
| D411 | blank-line-before-section | Missing blank line before section ("{name}") | 🛠 |
| D412 | no-blank-lines-between-header-and-content | No blank lines allowed between a section header and its content ("{name}") | 🛠 |
| D413 | blank-line-after-last-section | Missing blank line after last section ("{name}") | 🛠 |
| D414 | non-empty-section | Section has no content ("{name}") | |
| D414 | empty-docstring-section | Section has no content ("{name}") | |
| D415 | ends-in-punctuation | First line should end with a period, question mark, or exclamation point | 🛠 |
| D416 | section-name-ends-in-colon | Section name should end with a colon ("{name}") | 🛠 |
| D417 | document-all-arguments | Missing argument description in the docstring: `{name}` | |
| D418 | skip-docstring | Function decorated with `@overload` shouldn't contain a docstring | |
| D419 | non-empty | Docstring is empty | |
| D417 | undocumented-param | Missing argument description in the docstring: `{name}` | |
| D418 | overload-with-docstring | Function decorated with `@overload` shouldn't contain a docstring | |
| D419 | empty-docstring | Docstring is empty | |

### pyupgrade (UP)

Expand Down
18 changes: 9 additions & 9 deletions crates/ruff/src/checkers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5081,7 +5081,7 @@ impl<'a> Checker<'a> {
|| self.settings.rules.enabled(&Rule::NonImperativeMood)
|| self.settings.rules.enabled(&Rule::NoSignature)
|| self.settings.rules.enabled(&Rule::FirstLineCapitalized)
|| self.settings.rules.enabled(&Rule::NoThisPrefix)
|| self.settings.rules.enabled(&Rule::DocstringStartsWithThis)
|| self.settings.rules.enabled(&Rule::CapitalizeSectionName)
|| self.settings.rules.enabled(&Rule::NewLineAfterSectionName)
|| self
Expand All @@ -5106,12 +5106,12 @@ impl<'a> Checker<'a> {
.settings
.rules
.enabled(&Rule::BlankLineAfterLastSection)
|| self.settings.rules.enabled(&Rule::NonEmptySection)
|| self.settings.rules.enabled(&Rule::EmptyDocstringSection)
|| self.settings.rules.enabled(&Rule::EndsInPunctuation)
|| self.settings.rules.enabled(&Rule::SectionNameEndsInColon)
|| self.settings.rules.enabled(&Rule::DocumentAllArguments)
|| self.settings.rules.enabled(&Rule::SkipDocstring)
|| self.settings.rules.enabled(&Rule::NonEmpty);
|| self.settings.rules.enabled(&Rule::UndocumentedParam)
|| self.settings.rules.enabled(&Rule::OverloadWithDocstring)
|| self.settings.rules.enabled(&Rule::EmptyDocstring);

let mut overloaded_name: Option<String> = None;
self.definitions.reverse();
Expand Down Expand Up @@ -5242,13 +5242,13 @@ impl<'a> Checker<'a> {
if self.settings.rules.enabled(&Rule::FirstLineCapitalized) {
pydocstyle::rules::capitalized(self, &docstring);
}
if self.settings.rules.enabled(&Rule::NoThisPrefix) {
if self.settings.rules.enabled(&Rule::DocstringStartsWithThis) {
pydocstyle::rules::starts_with_this(self, &docstring);
}
if self.settings.rules.enabled(&Rule::EndsInPunctuation) {
pydocstyle::rules::ends_with_punctuation(self, &docstring);
}
if self.settings.rules.enabled(&Rule::SkipDocstring) {
if self.settings.rules.enabled(&Rule::OverloadWithDocstring) {
pydocstyle::rules::if_needed(self, &docstring);
}
if self
Expand Down Expand Up @@ -5284,9 +5284,9 @@ impl<'a> Checker<'a> {
.settings
.rules
.enabled(&Rule::BlankLineAfterLastSection)
|| self.settings.rules.enabled(&Rule::NonEmptySection)
|| self.settings.rules.enabled(&Rule::EmptyDocstringSection)
|| self.settings.rules.enabled(&Rule::SectionNameEndsInColon)
|| self.settings.rules.enabled(&Rule::DocumentAllArguments)
|| self.settings.rules.enabled(&Rule::UndocumentedParam)
{
pydocstyle::rules::sections(
self,
Expand Down
10 changes: 5 additions & 5 deletions crates/ruff/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ ruff_macros::define_rule_mapping!(
D401 => rules::pydocstyle::rules::NonImperativeMood,
D402 => rules::pydocstyle::rules::NoSignature,
D403 => rules::pydocstyle::rules::FirstLineCapitalized,
D404 => rules::pydocstyle::rules::NoThisPrefix,
D404 => rules::pydocstyle::rules::DocstringStartsWithThis,
D405 => rules::pydocstyle::rules::CapitalizeSectionName,
D406 => rules::pydocstyle::rules::NewLineAfterSectionName,
D407 => rules::pydocstyle::rules::DashedUnderlineAfterSection,
Expand All @@ -354,12 +354,12 @@ ruff_macros::define_rule_mapping!(
D411 => rules::pydocstyle::rules::BlankLineBeforeSection,
D412 => rules::pydocstyle::rules::NoBlankLinesBetweenHeaderAndContent,
D413 => rules::pydocstyle::rules::BlankLineAfterLastSection,
D414 => rules::pydocstyle::rules::NonEmptySection,
D414 => rules::pydocstyle::rules::EmptyDocstringSection,
D415 => rules::pydocstyle::rules::EndsInPunctuation,
D416 => rules::pydocstyle::rules::SectionNameEndsInColon,
D417 => rules::pydocstyle::rules::DocumentAllArguments,
D418 => rules::pydocstyle::rules::SkipDocstring,
D419 => rules::pydocstyle::rules::NonEmpty,
D417 => rules::pydocstyle::rules::UndocumentedParam,
D418 => rules::pydocstyle::rules::OverloadWithDocstring,
D419 => rules::pydocstyle::rules::EmptyDocstring,
// pep8-naming
N801 => rules::pep8_naming::rules::InvalidClassName,
N802 => rules::pep8_naming::rules::InvalidFunctionName,
Expand Down
20 changes: 10 additions & 10 deletions crates/ruff/src/rules/pydocstyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ mod tests {
#[test_case(Rule::BlankLineBeforeSection, Path::new("sections.py"); "D411")]
#[test_case(Rule::CapitalizeSectionName, Path::new("sections.py"); "D405")]
#[test_case(Rule::DashedUnderlineAfterSection, Path::new("sections.py"); "D407")]
#[test_case(Rule::DocumentAllArguments, Path::new("canonical_google_examples.py"); "D417_2")]
#[test_case(Rule::DocumentAllArguments, Path::new("canonical_numpy_examples.py"); "D417_1")]
#[test_case(Rule::DocumentAllArguments, Path::new("sections.py"); "D417_0")]
#[test_case(Rule::UndocumentedParam, Path::new("canonical_google_examples.py"); "D417_2")]
#[test_case(Rule::UndocumentedParam, Path::new("canonical_numpy_examples.py"); "D417_1")]
#[test_case(Rule::UndocumentedParam, Path::new("sections.py"); "D417_0")]
#[test_case(Rule::EndsInPeriod, Path::new("D.py"); "D400_0")]
#[test_case(Rule::EndsInPeriod, Path::new("D400.py"); "D400_1")]
#[test_case(Rule::EndsInPunctuation, Path::new("D.py"); "D415")]
Expand All @@ -43,10 +43,10 @@ mod tests {
#[test_case(Rule::NoOverIndentation, Path::new("D.py"); "D208")]
#[test_case(Rule::NoSignature, Path::new("D.py"); "D402")]
#[test_case(Rule::NoSurroundingWhitespace, Path::new("D.py"); "D210")]
#[test_case(Rule::NoThisPrefix, Path::new("D.py"); "D404")]
#[test_case(Rule::DocstringStartsWithThis, Path::new("D.py"); "D404")]
#[test_case(Rule::NoUnderIndentation, Path::new("D.py"); "D207")]
#[test_case(Rule::NonEmpty, Path::new("D.py"); "D419")]
#[test_case(Rule::NonEmptySection, Path::new("sections.py"); "D414")]
#[test_case(Rule::EmptyDocstring, Path::new("D.py"); "D419")]
#[test_case(Rule::EmptyDocstringSection, Path::new("sections.py"); "D414")]
#[test_case(Rule::NonImperativeMood, Path::new("D401.py"); "D401")]
#[test_case(Rule::OneBlankLineAfterClass, Path::new("D.py"); "D204")]
#[test_case(Rule::OneBlankLineBeforeClass, Path::new("D.py"); "D203")]
Expand All @@ -64,7 +64,7 @@ mod tests {
#[test_case(Rule::SectionUnderlineAfterName, Path::new("sections.py"); "D408")]
#[test_case(Rule::SectionUnderlineMatchesSectionLength, Path::new("sections.py"); "D409")]
#[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("sections.py"); "D215")]
#[test_case(Rule::SkipDocstring, Path::new("D.py"); "D418")]
#[test_case(Rule::OverloadWithDocstring, Path::new("D.py"); "D418")]
#[test_case(Rule::EscapeSequenceInDocstring, Path::new("D.py"); "D301")]
#[test_case(Rule::TripleSingleQuotes, Path::new("D.py"); "D300")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
Expand All @@ -85,7 +85,7 @@ mod tests {
// When inferring the convention, we'll see a few false negatives.
// See: https://github.com/PyCQA/pydocstyle/issues/459.
pydocstyle: Settings { convention: None },
..settings::Settings::for_rule(Rule::DocumentAllArguments)
..settings::Settings::for_rule(Rule::UndocumentedParam)
},
)?;
assert_yaml_snapshot!(diagnostics);
Expand All @@ -101,7 +101,7 @@ mod tests {
pydocstyle: Settings {
convention: Some(Convention::Google),
},
..settings::Settings::for_rule(Rule::DocumentAllArguments)
..settings::Settings::for_rule(Rule::UndocumentedParam)
},
)?;
assert_yaml_snapshot!(diagnostics);
Expand All @@ -117,7 +117,7 @@ mod tests {
pydocstyle: Settings {
convention: Some(Convention::Numpy),
},
..settings::Settings::for_rule(Rule::DocumentAllArguments)
..settings::Settings::for_rule(Rule::UndocumentedParam)
},
)?;
assert_yaml_snapshot!(diagnostics);
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/rules/pydocstyle/rules/if_needed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::violation::Violation;
use crate::visibility::is_overload;

define_violation!(
pub struct SkipDocstring;
pub struct OverloadWithDocstring;
);
impl Violation for SkipDocstring {
impl Violation for OverloadWithDocstring {
#[derive_message_formats]
fn message(&self) -> String {
format!("Function decorated with `@overload` shouldn't contain a docstring")
Expand All @@ -31,7 +31,7 @@ pub fn if_needed(checker: &mut Checker, docstring: &Docstring) {
return;
}
checker.diagnostics.push(Diagnostic::new(
SkipDocstring,
OverloadWithDocstring,
identifier_range(stmt, checker.locator),
));
}
14 changes: 7 additions & 7 deletions crates/ruff/src/rules/pydocstyle/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use blank_before_after_function::{
pub use capitalized::{capitalized, FirstLineCapitalized};
pub use ends_with_period::{ends_with_period, EndsInPeriod};
pub use ends_with_punctuation::{ends_with_punctuation, EndsInPunctuation};
pub use if_needed::{if_needed, SkipDocstring};
pub use if_needed::{if_needed, OverloadWithDocstring};
pub use indent::{indent, IndentWithSpaces, NoOverIndentation, NoUnderIndentation};
pub use multi_line_summary_start::{
multi_line_summary_start, MultiLineSummaryFirstLine, MultiLineSummarySecondLine,
Expand All @@ -19,20 +19,20 @@ pub use newline_after_last_paragraph::{newline_after_last_paragraph, NewLineAfte
pub use no_signature::{no_signature, NoSignature};
pub use no_surrounding_whitespace::{no_surrounding_whitespace, NoSurroundingWhitespace};
pub use non_imperative_mood::{non_imperative_mood, NonImperativeMood};
pub use not_empty::{not_empty, NonEmpty};
pub use not_empty::{not_empty, EmptyDocstring};
pub use not_missing::{
not_missing, MagicMethod, PublicClass, PublicFunction, PublicInit, PublicMethod, PublicModule,
PublicNestedClass, PublicPackage,
};
pub use one_liner::{one_liner, FitsOnOneLine};
pub use sections::{
sections, BlankLineAfterLastSection, BlankLineAfterSection, BlankLineBeforeSection,
CapitalizeSectionName, DashedUnderlineAfterSection, DocumentAllArguments,
NewLineAfterSectionName, NoBlankLinesBetweenHeaderAndContent, NonEmptySection,
SectionNameEndsInColon, SectionNotOverIndented, SectionUnderlineAfterName,
SectionUnderlineMatchesSectionLength, SectionUnderlineNotOverIndented,
CapitalizeSectionName, DashedUnderlineAfterSection, EmptyDocstringSection,
NewLineAfterSectionName, NoBlankLinesBetweenHeaderAndContent, SectionNameEndsInColon,
SectionNotOverIndented, SectionUnderlineAfterName, SectionUnderlineMatchesSectionLength,
SectionUnderlineNotOverIndented, UndocumentedParam,
};
pub use starts_with_this::{starts_with_this, NoThisPrefix};
pub use starts_with_this::{starts_with_this, DocstringStartsWithThis};
pub use triple_quotes::{triple_quotes, TripleSingleQuotes};

mod backslashes;
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff/src/rules/pydocstyle/rules/not_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::registry::{Diagnostic, Rule};
use crate::violation::Violation;

define_violation!(
pub struct NonEmpty;
pub struct EmptyDocstring;
);
impl Violation for NonEmpty {
impl Violation for EmptyDocstring {
#[derive_message_formats]
fn message(&self) -> String {
format!("Docstring is empty")
Expand All @@ -22,9 +22,9 @@ pub fn not_empty(checker: &mut Checker, docstring: &Docstring) -> bool {
return true;
}

if checker.settings.rules.enabled(&Rule::NonEmpty) {
if checker.settings.rules.enabled(&Rule::EmptyDocstring) {
checker.diagnostics.push(Diagnostic::new(
NonEmpty,
EmptyDocstring,
Range::from_located(docstring.expr),
));
}
Expand Down
30 changes: 15 additions & 15 deletions crates/ruff/src/rules/pydocstyle/rules/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ impl AlwaysAutofixableViolation for BlankLineAfterLastSection {
}

define_violation!(
pub struct NonEmptySection {
pub struct EmptyDocstringSection {
pub name: String,
}
);
impl Violation for NonEmptySection {
impl Violation for EmptyDocstringSection {
#[derive_message_formats]
fn message(&self) -> String {
let NonEmptySection { name } = self;
let EmptyDocstringSection { name } = self;
format!("Section has no content (\"{name}\")")
}
}
Expand All @@ -231,14 +231,14 @@ impl AlwaysAutofixableViolation for SectionNameEndsInColon {
}

define_violation!(
pub struct DocumentAllArguments {
pub struct UndocumentedParam {
pub names: Vec<String>,
}
);
impl Violation for DocumentAllArguments {
impl Violation for UndocumentedParam {
#[derive_message_formats]
fn message(&self) -> String {
let DocumentAllArguments { names } = self;
let UndocumentedParam { names } = self;
if names.len() == 1 {
let name = &names[0];
format!("Missing argument description in the docstring: `{name}`")
Expand Down Expand Up @@ -349,9 +349,9 @@ fn blanks_and_section_underline(
}
checker.diagnostics.push(diagnostic);
}
if checker.settings.rules.enabled(&Rule::NonEmptySection) {
if checker.settings.rules.enabled(&Rule::EmptyDocstringSection) {
checker.diagnostics.push(Diagnostic::new(
NonEmptySection {
EmptyDocstringSection {
name: context.section_name.to_string(),
},
Range::from_located(docstring.expr),
Expand Down Expand Up @@ -495,9 +495,9 @@ fn blanks_and_section_underline(
.take_while(|line| line.trim().is_empty())
.count();
if blank_lines_after_dashes == rest_of_lines.len() {
if checker.settings.rules.enabled(&Rule::NonEmptySection) {
if checker.settings.rules.enabled(&Rule::EmptyDocstringSection) {
checker.diagnostics.push(Diagnostic::new(
NonEmptySection {
EmptyDocstringSection {
name: context.section_name.to_string(),
},
Range::from_located(docstring.expr),
Expand Down Expand Up @@ -540,9 +540,9 @@ fn blanks_and_section_underline(
}
}
} else {
if checker.settings.rules.enabled(&Rule::NonEmptySection) {
if checker.settings.rules.enabled(&Rule::EmptyDocstringSection) {
checker.diagnostics.push(Diagnostic::new(
NonEmptySection {
EmptyDocstringSection {
name: context.section_name.to_string(),
},
Range::from_located(docstring.expr),
Expand Down Expand Up @@ -836,7 +836,7 @@ fn missing_args(checker: &mut Checker, docstring: &Docstring, docstrings_args: &
if !missing_arg_names.is_empty() {
let names = missing_arg_names.into_iter().sorted().collect();
checker.diagnostics.push(Diagnostic::new(
DocumentAllArguments { names },
UndocumentedParam { names },
Range::from_located(parent),
));
}
Expand Down Expand Up @@ -975,7 +975,7 @@ fn numpy_section(checker: &mut Checker, docstring: &Docstring, context: &Section
}
}

if checker.settings.rules.enabled(&Rule::DocumentAllArguments) {
if checker.settings.rules.enabled(&Rule::UndocumentedParam) {
let capitalized_section_name = titlecase::titlecase(context.section_name);
if capitalized_section_name == "Parameters" {
parameters_section(checker, docstring, context);
Expand Down Expand Up @@ -1028,7 +1028,7 @@ fn google_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
}
}

if checker.settings.rules.enabled(&Rule::DocumentAllArguments) {
if checker.settings.rules.enabled(&Rule::UndocumentedParam) {
let capitalized_section_name = titlecase::titlecase(context.section_name);
if capitalized_section_name == "Args" || capitalized_section_name == "Arguments" {
args_section(checker, docstring, context);
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/rules/pydocstyle/rules/starts_with_this.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::rules::pydocstyle::helpers::normalize_word;
use crate::violation::Violation;

define_violation!(
pub struct NoThisPrefix;
pub struct DocstringStartsWithThis;
);
impl Violation for NoThisPrefix {
impl Violation for DocstringStartsWithThis {
#[derive_message_formats]
fn message(&self) -> String {
format!(r#"First word of the docstring should not be "This""#)
Expand All @@ -33,7 +33,7 @@ pub fn starts_with_this(checker: &mut Checker, docstring: &Docstring) {
return;
}
checker.diagnostics.push(Diagnostic::new(
NoThisPrefix,
DocstringStartsWithThis,
Range::from_located(docstring.expr),
));
}
Loading

0 comments on commit 42924c0

Please sign in to comment.