Disallow rule names starting with uses-*

This commit is contained in:
Martin Fischer 2023-02-10 06:39:52 +01:00 committed by Charlie Marsh
parent 1cbe48522e
commit 1a97de0b01
10 changed files with 29 additions and 28 deletions

View file

@ -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 | 🛠 | | 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}") | 🛠 | | D214 | section-not-over-indented | Section is over-indented ("{name}") | 🛠 |
| D215 | section-underline-not-over-indented | Section underline is over-indented ("{name}") | 🛠 | | D215 | section-underline-not-over-indented | Section underline is over-indented ("{name}") | 🛠 |
| D300 | uses-triple-quotes | Use """triple double quotes""" | | | D300 | triple-single-quotes | Use """triple double quotes""" | |
| D301 | uses-r-prefix-for-backslashed-content | Use r""" if any backslashes in a docstring | | | D301 | escape-sequence-in-docstring | Use r""" if any backslashes in a docstring | |
| D400 | ends-in-period | First line should end with a period | 🛠 | | 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}" | | | 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 | | | D402 | no-signature | First line should not be the function's signature | |

View file

@ -1,2 +1,3 @@
do-not-* do-not-*
uses-*
*-used *-used

View file

@ -5055,11 +5055,11 @@ impl<'a> Checker<'a> {
.settings .settings
.rules .rules
.enabled(&Rule::SectionUnderlineNotOverIndented) .enabled(&Rule::SectionUnderlineNotOverIndented)
|| self.settings.rules.enabled(&Rule::UsesTripleQuotes) || self.settings.rules.enabled(&Rule::TripleSingleQuotes)
|| self || self
.settings .settings
.rules .rules
.enabled(&Rule::UsesRPrefixForBackslashedContent) .enabled(&Rule::EscapeSequenceInDocstring)
|| self.settings.rules.enabled(&Rule::EndsInPeriod) || self.settings.rules.enabled(&Rule::EndsInPeriod)
|| self.settings.rules.enabled(&Rule::NonImperativeMood) || self.settings.rules.enabled(&Rule::NonImperativeMood)
|| self.settings.rules.enabled(&Rule::NoSignature) || self.settings.rules.enabled(&Rule::NoSignature)
@ -5203,13 +5203,13 @@ impl<'a> Checker<'a> {
{ {
pydocstyle::rules::multi_line_summary_start(self, &docstring); 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); pydocstyle::rules::triple_quotes(self, &docstring);
} }
if self if self
.settings .settings
.rules .rules
.enabled(&Rule::UsesRPrefixForBackslashedContent) .enabled(&Rule::EscapeSequenceInDocstring)
{ {
pydocstyle::rules::backslashes(self, &docstring); pydocstyle::rules::backslashes(self, &docstring);
} }

View file

@ -337,8 +337,8 @@ ruff_macros::define_rule_mapping!(
D213 => rules::pydocstyle::rules::MultiLineSummarySecondLine, D213 => rules::pydocstyle::rules::MultiLineSummarySecondLine,
D214 => rules::pydocstyle::rules::SectionNotOverIndented, D214 => rules::pydocstyle::rules::SectionNotOverIndented,
D215 => rules::pydocstyle::rules::SectionUnderlineNotOverIndented, D215 => rules::pydocstyle::rules::SectionUnderlineNotOverIndented,
D300 => rules::pydocstyle::rules::UsesTripleQuotes, D300 => rules::pydocstyle::rules::TripleSingleQuotes,
D301 => rules::pydocstyle::rules::UsesRPrefixForBackslashedContent, D301 => rules::pydocstyle::rules::EscapeSequenceInDocstring,
D400 => rules::pydocstyle::rules::EndsInPeriod, D400 => rules::pydocstyle::rules::EndsInPeriod,
D401 => rules::pydocstyle::rules::NonImperativeMood, D401 => rules::pydocstyle::rules::NonImperativeMood,
D402 => rules::pydocstyle::rules::NoSignature, D402 => rules::pydocstyle::rules::NoSignature,

View file

@ -65,8 +65,8 @@ mod tests {
#[test_case(Rule::SectionUnderlineMatchesSectionLength, Path::new("sections.py"); "D409")] #[test_case(Rule::SectionUnderlineMatchesSectionLength, Path::new("sections.py"); "D409")]
#[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("sections.py"); "D215")] #[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("sections.py"); "D215")]
#[test_case(Rule::SkipDocstring, Path::new("D.py"); "D418")] #[test_case(Rule::SkipDocstring, Path::new("D.py"); "D418")]
#[test_case(Rule::UsesRPrefixForBackslashedContent, Path::new("D.py"); "D301")] #[test_case(Rule::EscapeSequenceInDocstring, Path::new("D.py"); "D301")]
#[test_case(Rule::UsesTripleQuotes, Path::new("D.py"); "D300")] #[test_case(Rule::TripleSingleQuotes, Path::new("D.py"); "D300")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> { fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
let diagnostics = test_path( let diagnostics = test_path(

View file

@ -9,9 +9,9 @@ use crate::registry::Diagnostic;
use crate::violation::Violation; use crate::violation::Violation;
define_violation!( define_violation!(
pub struct UsesRPrefixForBackslashedContent; pub struct EscapeSequenceInDocstring;
); );
impl Violation for UsesRPrefixForBackslashedContent { impl Violation for EscapeSequenceInDocstring {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
format!(r#"Use r""" if any backslashes in a docstring"#) 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) { if BACKSLASH_REGEX.is_match(contents) {
checker.diagnostics.push(Diagnostic::new( checker.diagnostics.push(Diagnostic::new(
UsesRPrefixForBackslashedContent, EscapeSequenceInDocstring,
Range::from_located(docstring.expr), Range::from_located(docstring.expr),
)); ));
} }

View file

@ -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_after_summary::{blank_after_summary, BlankLineAfterSummary};
pub use blank_before_after_class::{ pub use blank_before_after_class::{
blank_before_after_class, NoBlankLineBeforeClass, OneBlankLineAfterClass, blank_before_after_class, NoBlankLineBeforeClass, OneBlankLineAfterClass,
@ -33,7 +33,7 @@ pub use sections::{
SectionUnderlineMatchesSectionLength, SectionUnderlineNotOverIndented, SectionUnderlineMatchesSectionLength, SectionUnderlineNotOverIndented,
}; };
pub use starts_with_this::{starts_with_this, NoThisPrefix}; 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 backslashes;
mod blank_after_summary; mod blank_after_summary;

View file

@ -7,9 +7,9 @@ use crate::registry::Diagnostic;
use crate::violation::Violation; use crate::violation::Violation;
define_violation!( define_violation!(
pub struct UsesTripleQuotes; pub struct TripleSingleQuotes;
); );
impl Violation for UsesTripleQuotes { impl Violation for TripleSingleQuotes {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
format!(r#"Use """triple double quotes""""#) format!(r#"Use """triple double quotes""""#)
@ -41,7 +41,7 @@ pub fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
}; };
if !starts_with_triple { if !starts_with_triple {
checker.diagnostics.push(Diagnostic::new( checker.diagnostics.push(Diagnostic::new(
UsesTripleQuotes, TripleSingleQuotes,
Range::from_located(docstring.expr), Range::from_located(docstring.expr),
)); ));
} }

View file

@ -1,9 +1,9 @@
--- ---
source: src/rules/pydocstyle/mod.rs source: crates/ruff/src/rules/pydocstyle/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
UsesTripleQuotes: ~ TripleSingleQuotes: ~
location: location:
row: 307 row: 307
column: 4 column: 4
@ -13,7 +13,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
UsesTripleQuotes: ~ TripleSingleQuotes: ~
location: location:
row: 312 row: 312
column: 4 column: 4
@ -23,7 +23,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
UsesTripleQuotes: ~ TripleSingleQuotes: ~
location: location:
row: 317 row: 317
column: 4 column: 4
@ -33,7 +33,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
UsesTripleQuotes: ~ TripleSingleQuotes: ~
location: location:
row: 322 row: 322
column: 4 column: 4
@ -43,7 +43,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
UsesTripleQuotes: ~ TripleSingleQuotes: ~
location: location:
row: 328 row: 328
column: 4 column: 4

View file

@ -1,9 +1,9 @@
--- ---
source: src/rules/pydocstyle/mod.rs source: crates/ruff/src/rules/pydocstyle/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
UsesRPrefixForBackslashedContent: ~ EscapeSequenceInDocstring: ~
location: location:
row: 328 row: 328
column: 4 column: 4
@ -13,7 +13,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
UsesRPrefixForBackslashedContent: ~ EscapeSequenceInDocstring: ~
location: location:
row: 333 row: 333
column: 4 column: 4
@ -23,7 +23,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
UsesRPrefixForBackslashedContent: ~ EscapeSequenceInDocstring: ~
location: location:
row: 338 row: 338
column: 4 column: 4