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 | 🛠 |
| 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 | |

View file

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

View file

@ -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);
}

View file

@ -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,

View file

@ -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(

View file

@ -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),
));
}

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_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;

View file

@ -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),
));
}

View file

@ -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

View file

@ -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