mirror of https://github.com/astral-sh/ruff
Skip docstring checks for empty docstrings (#402)
This commit is contained in:
parent
2ff964107c
commit
5b6fb8cefa
|
|
@ -1890,6 +1890,9 @@ impl<'a> Checker<'a> {
|
|||
|
||||
fn check_docstrings(&mut self) {
|
||||
while let Some(docstring) = self.docstrings.pop() {
|
||||
if !docstrings::not_empty(self, &docstring) {
|
||||
continue;
|
||||
}
|
||||
if self.settings.enabled.contains(&CheckCode::D200) {
|
||||
docstrings::one_liner(self, &docstring);
|
||||
}
|
||||
|
|
@ -1919,9 +1922,6 @@ impl<'a> Checker<'a> {
|
|||
if self.settings.enabled.contains(&CheckCode::D415) {
|
||||
docstrings::ends_with_punctuation(self, &docstring);
|
||||
}
|
||||
if self.settings.enabled.contains(&CheckCode::D419) {
|
||||
docstrings::not_empty(self, &docstring);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -308,14 +308,18 @@ pub fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) {
|
|||
}
|
||||
|
||||
/// D419
|
||||
pub fn not_empty(checker: &mut Checker, docstring: &Docstring) {
|
||||
pub fn not_empty(checker: &mut Checker, docstring: &Docstring) -> bool {
|
||||
if let ExprKind::Constant {
|
||||
value: Constant::Str(string),
|
||||
..
|
||||
} = &docstring.expr.node
|
||||
{
|
||||
if string.trim().is_empty() {
|
||||
checker.add_check(Check::new(CheckKind::NonEmpty, range_for(docstring)));
|
||||
if checker.settings.enabled.contains(&CheckCode::D419) {
|
||||
checker.add_check(Check::new(CheckKind::NonEmpty, range_for(docstring)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
source: src/linter.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: OneLinerDocstring
|
||||
- kind: FitsOnOneLine
|
||||
location:
|
||||
row: 124
|
||||
column: 5
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
source: src/linter.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: BlankLineAfterSummary
|
||||
- kind: NoBlankLineAfterSummary
|
||||
location:
|
||||
row: 195
|
||||
column: 5
|
||||
|
|
@ -10,7 +10,7 @@ expression: checks
|
|||
row: 198
|
||||
column: 8
|
||||
fix: ~
|
||||
- kind: BlankLineAfterSummary
|
||||
- kind: NoBlankLineAfterSummary
|
||||
location:
|
||||
row: 205
|
||||
column: 5
|
||||
|
|
|
|||
|
|
@ -2,15 +2,7 @@
|
|||
source: src/linter.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: TripleQuotes
|
||||
location:
|
||||
row: 75
|
||||
column: 9
|
||||
end_location:
|
||||
row: 75
|
||||
column: 11
|
||||
fix: ~
|
||||
- kind: TripleQuotes
|
||||
- kind: UsesTripleQuotes
|
||||
location:
|
||||
row: 302
|
||||
column: 6
|
||||
|
|
@ -18,7 +10,7 @@ expression: checks
|
|||
row: 302
|
||||
column: 20
|
||||
fix: ~
|
||||
- kind: TripleQuotes
|
||||
- kind: UsesTripleQuotes
|
||||
location:
|
||||
row: 307
|
||||
column: 6
|
||||
|
|
@ -26,7 +18,7 @@ expression: checks
|
|||
row: 307
|
||||
column: 20
|
||||
fix: ~
|
||||
- kind: TripleQuotes
|
||||
- kind: UsesTripleQuotes
|
||||
location:
|
||||
row: 312
|
||||
column: 6
|
||||
|
|
@ -34,7 +26,7 @@ expression: checks
|
|||
row: 312
|
||||
column: 16
|
||||
fix: ~
|
||||
- kind: TripleQuotes
|
||||
- kind: UsesTripleQuotes
|
||||
location:
|
||||
row: 317
|
||||
column: 6
|
||||
|
|
@ -42,7 +34,7 @@ expression: checks
|
|||
row: 317
|
||||
column: 16
|
||||
fix: ~
|
||||
- kind: TripleQuotes
|
||||
- kind: UsesTripleQuotes
|
||||
location:
|
||||
row: 323
|
||||
column: 6
|
||||
|
|
|
|||
|
|
@ -2,15 +2,7 @@
|
|||
source: src/linter.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
location:
|
||||
row: 69
|
||||
column: 5
|
||||
end_location:
|
||||
row: 69
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 124
|
||||
column: 5
|
||||
|
|
@ -18,7 +10,7 @@ expression: checks
|
|||
row: 126
|
||||
column: 8
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 283
|
||||
column: 5
|
||||
|
|
@ -26,7 +18,7 @@ expression: checks
|
|||
row: 283
|
||||
column: 34
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 288
|
||||
column: 5
|
||||
|
|
@ -34,7 +26,7 @@ expression: checks
|
|||
row: 288
|
||||
column: 38
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 350
|
||||
column: 5
|
||||
|
|
@ -42,7 +34,7 @@ expression: checks
|
|||
row: 350
|
||||
column: 18
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 401
|
||||
column: 25
|
||||
|
|
@ -50,7 +42,7 @@ expression: checks
|
|||
row: 401
|
||||
column: 40
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 405
|
||||
column: 5
|
||||
|
|
@ -58,7 +50,7 @@ expression: checks
|
|||
row: 405
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 411
|
||||
column: 5
|
||||
|
|
@ -66,7 +58,7 @@ expression: checks
|
|||
row: 411
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 417
|
||||
column: 35
|
||||
|
|
@ -74,7 +66,7 @@ expression: checks
|
|||
row: 417
|
||||
column: 50
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 424
|
||||
column: 49
|
||||
|
|
@ -82,7 +74,7 @@ expression: checks
|
|||
row: 424
|
||||
column: 64
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 465
|
||||
column: 5
|
||||
|
|
@ -90,7 +82,7 @@ expression: checks
|
|||
row: 465
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 470
|
||||
column: 5
|
||||
|
|
@ -98,7 +90,7 @@ expression: checks
|
|||
row: 470
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 475
|
||||
column: 5
|
||||
|
|
@ -106,7 +98,7 @@ expression: checks
|
|||
row: 475
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 482
|
||||
column: 5
|
||||
|
|
@ -114,7 +106,7 @@ expression: checks
|
|||
row: 482
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 504
|
||||
column: 5
|
||||
|
|
@ -122,7 +114,7 @@ expression: checks
|
|||
row: 504
|
||||
column: 35
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 509
|
||||
column: 5
|
||||
|
|
@ -130,7 +122,7 @@ expression: checks
|
|||
row: 509
|
||||
column: 34
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPeriod
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 515
|
||||
column: 5
|
||||
|
|
|
|||
|
|
@ -2,15 +2,7 @@
|
|||
source: src/linter.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
location:
|
||||
row: 69
|
||||
column: 5
|
||||
end_location:
|
||||
row: 69
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 124
|
||||
column: 5
|
||||
|
|
@ -18,7 +10,7 @@ expression: checks
|
|||
row: 126
|
||||
column: 8
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 283
|
||||
column: 5
|
||||
|
|
@ -26,7 +18,7 @@ expression: checks
|
|||
row: 283
|
||||
column: 34
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 288
|
||||
column: 5
|
||||
|
|
@ -34,7 +26,7 @@ expression: checks
|
|||
row: 288
|
||||
column: 38
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 350
|
||||
column: 5
|
||||
|
|
@ -42,7 +34,7 @@ expression: checks
|
|||
row: 350
|
||||
column: 18
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 401
|
||||
column: 25
|
||||
|
|
@ -50,7 +42,7 @@ expression: checks
|
|||
row: 401
|
||||
column: 40
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 405
|
||||
column: 5
|
||||
|
|
@ -58,7 +50,7 @@ expression: checks
|
|||
row: 405
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 411
|
||||
column: 5
|
||||
|
|
@ -66,7 +58,7 @@ expression: checks
|
|||
row: 411
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 417
|
||||
column: 35
|
||||
|
|
@ -74,7 +66,7 @@ expression: checks
|
|||
row: 417
|
||||
column: 50
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 424
|
||||
column: 49
|
||||
|
|
@ -82,7 +74,7 @@ expression: checks
|
|||
row: 424
|
||||
column: 64
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 465
|
||||
column: 5
|
||||
|
|
@ -90,7 +82,7 @@ expression: checks
|
|||
row: 465
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 470
|
||||
column: 5
|
||||
|
|
@ -98,7 +90,7 @@ expression: checks
|
|||
row: 470
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 475
|
||||
column: 5
|
||||
|
|
@ -106,7 +98,7 @@ expression: checks
|
|||
row: 475
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 482
|
||||
column: 5
|
||||
|
|
@ -114,7 +106,7 @@ expression: checks
|
|||
row: 482
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 504
|
||||
column: 5
|
||||
|
|
@ -122,7 +114,7 @@ expression: checks
|
|||
row: 504
|
||||
column: 35
|
||||
fix: ~
|
||||
- kind: DocstringEndsInNonPunctuation
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 515
|
||||
column: 5
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
source: src/linter.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: EmptyDocstring
|
||||
- kind: NonEmpty
|
||||
location:
|
||||
row: 19
|
||||
column: 9
|
||||
|
|
@ -10,7 +10,7 @@ expression: checks
|
|||
row: 19
|
||||
column: 15
|
||||
fix: ~
|
||||
- kind: EmptyDocstring
|
||||
- kind: NonEmpty
|
||||
location:
|
||||
row: 69
|
||||
column: 5
|
||||
|
|
@ -18,7 +18,7 @@ expression: checks
|
|||
row: 69
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind: EmptyDocstring
|
||||
- kind: NonEmpty
|
||||
location:
|
||||
row: 75
|
||||
column: 9
|
||||
|
|
|
|||
Loading…
Reference in New Issue