Skip docstring checks for empty docstrings (#402)

This commit is contained in:
Charlie Marsh 2022-10-11 12:54:30 -04:00 committed by GitHub
parent 2ff964107c
commit 5b6fb8cefa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 71 deletions

View File

@ -1890,6 +1890,9 @@ impl<'a> Checker<'a> {
fn check_docstrings(&mut self) { fn check_docstrings(&mut self) {
while let Some(docstring) = self.docstrings.pop() { while let Some(docstring) = self.docstrings.pop() {
if !docstrings::not_empty(self, &docstring) {
continue;
}
if self.settings.enabled.contains(&CheckCode::D200) { if self.settings.enabled.contains(&CheckCode::D200) {
docstrings::one_liner(self, &docstring); docstrings::one_liner(self, &docstring);
} }
@ -1919,9 +1922,6 @@ impl<'a> Checker<'a> {
if self.settings.enabled.contains(&CheckCode::D415) { if self.settings.enabled.contains(&CheckCode::D415) {
docstrings::ends_with_punctuation(self, &docstring); docstrings::ends_with_punctuation(self, &docstring);
} }
if self.settings.enabled.contains(&CheckCode::D419) {
docstrings::not_empty(self, &docstring);
}
} }
} }

View File

@ -308,14 +308,18 @@ pub fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) {
} }
/// D419 /// D419
pub fn not_empty(checker: &mut Checker, docstring: &Docstring) { pub fn not_empty(checker: &mut Checker, docstring: &Docstring) -> bool {
if let ExprKind::Constant { if let ExprKind::Constant {
value: Constant::Str(string), value: Constant::Str(string),
.. ..
} = &docstring.expr.node } = &docstring.expr.node
{ {
if string.trim().is_empty() { 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
} }

View File

@ -2,7 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: OneLinerDocstring - kind: FitsOnOneLine
location: location:
row: 124 row: 124
column: 5 column: 5

View File

@ -2,7 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: BlankLineAfterSummary - kind: NoBlankLineAfterSummary
location: location:
row: 195 row: 195
column: 5 column: 5
@ -10,7 +10,7 @@ expression: checks
row: 198 row: 198
column: 8 column: 8
fix: ~ fix: ~
- kind: BlankLineAfterSummary - kind: NoBlankLineAfterSummary
location: location:
row: 205 row: 205
column: 5 column: 5

View File

@ -2,15 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: TripleQuotes - kind: UsesTripleQuotes
location:
row: 75
column: 9
end_location:
row: 75
column: 11
fix: ~
- kind: TripleQuotes
location: location:
row: 302 row: 302
column: 6 column: 6
@ -18,7 +10,7 @@ expression: checks
row: 302 row: 302
column: 20 column: 20
fix: ~ fix: ~
- kind: TripleQuotes - kind: UsesTripleQuotes
location: location:
row: 307 row: 307
column: 6 column: 6
@ -26,7 +18,7 @@ expression: checks
row: 307 row: 307
column: 20 column: 20
fix: ~ fix: ~
- kind: TripleQuotes - kind: UsesTripleQuotes
location: location:
row: 312 row: 312
column: 6 column: 6
@ -34,7 +26,7 @@ expression: checks
row: 312 row: 312
column: 16 column: 16
fix: ~ fix: ~
- kind: TripleQuotes - kind: UsesTripleQuotes
location: location:
row: 317 row: 317
column: 6 column: 6
@ -42,7 +34,7 @@ expression: checks
row: 317 row: 317
column: 16 column: 16
fix: ~ fix: ~
- kind: TripleQuotes - kind: UsesTripleQuotes
location: location:
row: 323 row: 323
column: 6 column: 6

View File

@ -2,15 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location:
row: 69
column: 5
end_location:
row: 69
column: 12
fix: ~
- kind: DocstringEndsInNonPeriod
location: location:
row: 124 row: 124
column: 5 column: 5
@ -18,7 +10,7 @@ expression: checks
row: 126 row: 126
column: 8 column: 8
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 283 row: 283
column: 5 column: 5
@ -26,7 +18,7 @@ expression: checks
row: 283 row: 283
column: 34 column: 34
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 288 row: 288
column: 5 column: 5
@ -34,7 +26,7 @@ expression: checks
row: 288 row: 288
column: 38 column: 38
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 350 row: 350
column: 5 column: 5
@ -42,7 +34,7 @@ expression: checks
row: 350 row: 350
column: 18 column: 18
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 401 row: 401
column: 25 column: 25
@ -50,7 +42,7 @@ expression: checks
row: 401 row: 401
column: 40 column: 40
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 405 row: 405
column: 5 column: 5
@ -58,7 +50,7 @@ expression: checks
row: 405 row: 405
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 411 row: 411
column: 5 column: 5
@ -66,7 +58,7 @@ expression: checks
row: 411 row: 411
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 417 row: 417
column: 35 column: 35
@ -74,7 +66,7 @@ expression: checks
row: 417 row: 417
column: 50 column: 50
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 424 row: 424
column: 49 column: 49
@ -82,7 +74,7 @@ expression: checks
row: 424 row: 424
column: 64 column: 64
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 465 row: 465
column: 5 column: 5
@ -90,7 +82,7 @@ expression: checks
row: 465 row: 465
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 470 row: 470
column: 5 column: 5
@ -98,7 +90,7 @@ expression: checks
row: 470 row: 470
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 475 row: 475
column: 5 column: 5
@ -106,7 +98,7 @@ expression: checks
row: 475 row: 475
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 482 row: 482
column: 5 column: 5
@ -114,7 +106,7 @@ expression: checks
row: 482 row: 482
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 504 row: 504
column: 5 column: 5
@ -122,7 +114,7 @@ expression: checks
row: 504 row: 504
column: 35 column: 35
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 509 row: 509
column: 5 column: 5
@ -130,7 +122,7 @@ expression: checks
row: 509 row: 509
column: 34 column: 34
fix: ~ fix: ~
- kind: DocstringEndsInNonPeriod - kind: EndsInPeriod
location: location:
row: 515 row: 515
column: 5 column: 5

View File

@ -2,15 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location:
row: 69
column: 5
end_location:
row: 69
column: 12
fix: ~
- kind: DocstringEndsInNonPunctuation
location: location:
row: 124 row: 124
column: 5 column: 5
@ -18,7 +10,7 @@ expression: checks
row: 126 row: 126
column: 8 column: 8
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 283 row: 283
column: 5 column: 5
@ -26,7 +18,7 @@ expression: checks
row: 283 row: 283
column: 34 column: 34
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 288 row: 288
column: 5 column: 5
@ -34,7 +26,7 @@ expression: checks
row: 288 row: 288
column: 38 column: 38
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 350 row: 350
column: 5 column: 5
@ -42,7 +34,7 @@ expression: checks
row: 350 row: 350
column: 18 column: 18
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 401 row: 401
column: 25 column: 25
@ -50,7 +42,7 @@ expression: checks
row: 401 row: 401
column: 40 column: 40
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 405 row: 405
column: 5 column: 5
@ -58,7 +50,7 @@ expression: checks
row: 405 row: 405
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 411 row: 411
column: 5 column: 5
@ -66,7 +58,7 @@ expression: checks
row: 411 row: 411
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 417 row: 417
column: 35 column: 35
@ -74,7 +66,7 @@ expression: checks
row: 417 row: 417
column: 50 column: 50
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 424 row: 424
column: 49 column: 49
@ -82,7 +74,7 @@ expression: checks
row: 424 row: 424
column: 64 column: 64
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 465 row: 465
column: 5 column: 5
@ -90,7 +82,7 @@ expression: checks
row: 465 row: 465
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 470 row: 470
column: 5 column: 5
@ -98,7 +90,7 @@ expression: checks
row: 470 row: 470
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 475 row: 475
column: 5 column: 5
@ -106,7 +98,7 @@ expression: checks
row: 475 row: 475
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 482 row: 482
column: 5 column: 5
@ -114,7 +106,7 @@ expression: checks
row: 482 row: 482
column: 25 column: 25
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 504 row: 504
column: 5 column: 5
@ -122,7 +114,7 @@ expression: checks
row: 504 row: 504
column: 35 column: 35
fix: ~ fix: ~
- kind: DocstringEndsInNonPunctuation - kind: EndsInPunctuation
location: location:
row: 515 row: 515
column: 5 column: 5

View File

@ -2,7 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: EmptyDocstring - kind: NonEmpty
location: location:
row: 19 row: 19
column: 9 column: 9
@ -10,7 +10,7 @@ expression: checks
row: 19 row: 19
column: 15 column: 15
fix: ~ fix: ~
- kind: EmptyDocstring - kind: NonEmpty
location: location:
row: 69 row: 69
column: 5 column: 5
@ -18,7 +18,7 @@ expression: checks
row: 69 row: 69
column: 12 column: 12
fix: ~ fix: ~
- kind: EmptyDocstring - kind: NonEmpty
location: location:
row: 75 row: 75
column: 9 column: 9