diff --git a/README.md b/README.md index c0f9897cfc..189f9253ae 100644 --- a/README.md +++ b/README.md @@ -812,8 +812,8 @@ For more, see [pydocstyle](https://pypi.org/project/pydocstyle/) on PyPI. | D213 | multi-line-summary-second-line | Multi-line docstring summary should start at the second line | 🛠 | | D214 | section-not-over-indented | Section is over-indented ("{name}") | 🛠 | | D215 | section-underline-not-over-indented | Section underline is over-indented ("{name}") | 🛠 | -| D300 | uses-triple-quotes | Use """triple double quotes""" | | -| D301 | uses-r-prefix-for-backslashed-content | Use r""" if any backslashes in a docstring | | +| D300 | triple-single-quotes | Use """triple double quotes""" | | +| D301 | escape-sequence-in-docstring | Use r""" if any backslashes in a docstring | | | D400 | ends-in-period | First line should end with a period | 🛠 | | 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 | | diff --git a/crates/ruff/resources/test/disallowed_rule_names.txt b/crates/ruff/resources/test/disallowed_rule_names.txt index d27ce0ab8a..196329acf1 100644 --- a/crates/ruff/resources/test/disallowed_rule_names.txt +++ b/crates/ruff/resources/test/disallowed_rule_names.txt @@ -1,2 +1,3 @@ do-not-* +uses-* *-used diff --git a/crates/ruff/src/checkers/ast.rs b/crates/ruff/src/checkers/ast.rs index be7a269fe4..12cf59ded0 100644 --- a/crates/ruff/src/checkers/ast.rs +++ b/crates/ruff/src/checkers/ast.rs @@ -5055,11 +5055,11 @@ impl<'a> Checker<'a> { .settings .rules .enabled(&Rule::SectionUnderlineNotOverIndented) - || self.settings.rules.enabled(&Rule::UsesTripleQuotes) + || self.settings.rules.enabled(&Rule::TripleSingleQuotes) || self .settings .rules - .enabled(&Rule::UsesRPrefixForBackslashedContent) + .enabled(&Rule::EscapeSequenceInDocstring) || self.settings.rules.enabled(&Rule::EndsInPeriod) || self.settings.rules.enabled(&Rule::NonImperativeMood) || self.settings.rules.enabled(&Rule::NoSignature) @@ -5203,13 +5203,13 @@ impl<'a> Checker<'a> { { pydocstyle::rules::multi_line_summary_start(self, &docstring); } - if self.settings.rules.enabled(&Rule::UsesTripleQuotes) { + if self.settings.rules.enabled(&Rule::TripleSingleQuotes) { pydocstyle::rules::triple_quotes(self, &docstring); } if self .settings .rules - .enabled(&Rule::UsesRPrefixForBackslashedContent) + .enabled(&Rule::EscapeSequenceInDocstring) { pydocstyle::rules::backslashes(self, &docstring); } diff --git a/crates/ruff/src/registry.rs b/crates/ruff/src/registry.rs index 8145e5b64a..8d007fd835 100644 --- a/crates/ruff/src/registry.rs +++ b/crates/ruff/src/registry.rs @@ -337,8 +337,8 @@ ruff_macros::define_rule_mapping!( D213 => rules::pydocstyle::rules::MultiLineSummarySecondLine, D214 => rules::pydocstyle::rules::SectionNotOverIndented, D215 => rules::pydocstyle::rules::SectionUnderlineNotOverIndented, - D300 => rules::pydocstyle::rules::UsesTripleQuotes, - D301 => rules::pydocstyle::rules::UsesRPrefixForBackslashedContent, + D300 => rules::pydocstyle::rules::TripleSingleQuotes, + D301 => rules::pydocstyle::rules::EscapeSequenceInDocstring, D400 => rules::pydocstyle::rules::EndsInPeriod, D401 => rules::pydocstyle::rules::NonImperativeMood, D402 => rules::pydocstyle::rules::NoSignature, diff --git a/crates/ruff/src/rules/pydocstyle/mod.rs b/crates/ruff/src/rules/pydocstyle/mod.rs index 2269f1c800..58765b55e8 100644 --- a/crates/ruff/src/rules/pydocstyle/mod.rs +++ b/crates/ruff/src/rules/pydocstyle/mod.rs @@ -65,8 +65,8 @@ mod tests { #[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::UsesRPrefixForBackslashedContent, Path::new("D.py"); "D301")] - #[test_case(Rule::UsesTripleQuotes, Path::new("D.py"); "D300")] + #[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<()> { let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( diff --git a/crates/ruff/src/rules/pydocstyle/rules/backslashes.rs b/crates/ruff/src/rules/pydocstyle/rules/backslashes.rs index 8b90da4e2e..5196919f81 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/backslashes.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/backslashes.rs @@ -9,9 +9,9 @@ use crate::registry::Diagnostic; use crate::violation::Violation; define_violation!( - pub struct UsesRPrefixForBackslashedContent; + pub struct EscapeSequenceInDocstring; ); -impl Violation for UsesRPrefixForBackslashedContent { +impl Violation for EscapeSequenceInDocstring { #[derive_message_formats] fn message(&self) -> String { format!(r#"Use r""" if any backslashes in a docstring"#) @@ -31,7 +31,7 @@ pub fn backslashes(checker: &mut Checker, docstring: &Docstring) { if BACKSLASH_REGEX.is_match(contents) { checker.diagnostics.push(Diagnostic::new( - UsesRPrefixForBackslashedContent, + EscapeSequenceInDocstring, Range::from_located(docstring.expr), )); } diff --git a/crates/ruff/src/rules/pydocstyle/rules/mod.rs b/crates/ruff/src/rules/pydocstyle/rules/mod.rs index 35d6b154c7..75f9e169d2 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/mod.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/mod.rs @@ -1,4 +1,4 @@ -pub use backslashes::{backslashes, UsesRPrefixForBackslashedContent}; +pub use backslashes::{backslashes, EscapeSequenceInDocstring}; pub use blank_after_summary::{blank_after_summary, BlankLineAfterSummary}; pub use blank_before_after_class::{ blank_before_after_class, NoBlankLineBeforeClass, OneBlankLineAfterClass, @@ -33,7 +33,7 @@ pub use sections::{ SectionUnderlineMatchesSectionLength, SectionUnderlineNotOverIndented, }; pub use starts_with_this::{starts_with_this, NoThisPrefix}; -pub use triple_quotes::{triple_quotes, UsesTripleQuotes}; +pub use triple_quotes::{triple_quotes, TripleSingleQuotes}; mod backslashes; mod blank_after_summary; diff --git a/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs b/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs index 4ed50d1249..aeebc2ad96 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/triple_quotes.rs @@ -7,9 +7,9 @@ use crate::registry::Diagnostic; use crate::violation::Violation; define_violation!( - pub struct UsesTripleQuotes; + pub struct TripleSingleQuotes; ); -impl Violation for UsesTripleQuotes { +impl Violation for TripleSingleQuotes { #[derive_message_formats] fn message(&self) -> String { format!(r#"Use """triple double quotes""""#) @@ -41,7 +41,7 @@ pub fn triple_quotes(checker: &mut Checker, docstring: &Docstring) { }; if !starts_with_triple { checker.diagnostics.push(Diagnostic::new( - UsesTripleQuotes, + TripleSingleQuotes, Range::from_located(docstring.expr), )); } diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap index 48565cfb87..6146e91259 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap @@ -1,9 +1,9 @@ --- -source: src/rules/pydocstyle/mod.rs +source: crates/ruff/src/rules/pydocstyle/mod.rs expression: diagnostics --- - kind: - UsesTripleQuotes: ~ + TripleSingleQuotes: ~ location: row: 307 column: 4 @@ -13,7 +13,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - UsesTripleQuotes: ~ + TripleSingleQuotes: ~ location: row: 312 column: 4 @@ -23,7 +23,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - UsesTripleQuotes: ~ + TripleSingleQuotes: ~ location: row: 317 column: 4 @@ -33,7 +33,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - UsesTripleQuotes: ~ + TripleSingleQuotes: ~ location: row: 322 column: 4 @@ -43,7 +43,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - UsesTripleQuotes: ~ + TripleSingleQuotes: ~ location: row: 328 column: 4 diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap index bb8760d3b5..7ef5940f07 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap @@ -1,9 +1,9 @@ --- -source: src/rules/pydocstyle/mod.rs +source: crates/ruff/src/rules/pydocstyle/mod.rs expression: diagnostics --- - kind: - UsesRPrefixForBackslashedContent: ~ + EscapeSequenceInDocstring: ~ location: row: 328 column: 4 @@ -13,7 +13,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - UsesRPrefixForBackslashedContent: ~ + EscapeSequenceInDocstring: ~ location: row: 333 column: 4 @@ -23,7 +23,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - UsesRPrefixForBackslashedContent: ~ + EscapeSequenceInDocstring: ~ location: row: 338 column: 4