From ab825eb28dcb217194e1a743f85afa5bcd638464 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 17 Nov 2022 15:01:58 -0500 Subject: [PATCH] Fix D202 to remove line after docstring (#797) --- resources/test/fixtures/D.py | 34 ++++++++++++++++++ src/pydocstyle/plugins.rs | 7 ++-- .../ruff__linter__tests__D201_D.py.snap | 36 +++++++++++++++++++ .../ruff__linter__tests__D202_D.py.snap | 36 +++++++++++++++++++ .../ruff__linter__tests__D213_D.py.snap | 24 +++++++++++++ 5 files changed, 135 insertions(+), 2 deletions(-) diff --git a/resources/test/fixtures/D.py b/resources/test/fixtures/D.py index 1cbd8ec4c9..f5e4e748b8 100644 --- a/resources/test/fixtures/D.py +++ b/resources/test/fixtures/D.py @@ -532,3 +532,37 @@ class Blah: # noqa: D203,D213 expect(os.path.normcase(__file__ if __file__[-1] != 'c' else __file__[:-1]), 'D100: Missing docstring in public module') + + +@expect('D201: No blank lines allowed before function docstring (found 1)') +@expect('D213: Multi-line docstring summary should start at the second line') +def multiline_leading_space(): + + """Leading space. + + More content. + """ + + +@expect('D202: No blank lines allowed after function docstring (found 1)') +@expect('D213: Multi-line docstring summary should start at the second line') +def multiline_trailing_space(): + """Leading space. + + More content. + """ + + pass + + +@expect('D201: No blank lines allowed before function docstring (found 1)') +@expect('D202: No blank lines allowed after function docstring (found 1)') +@expect('D213: Multi-line docstring summary should start at the second line') +def multiline_trailing_and_leading_space(): + + """Trailing and leading space. + + More content. + """ + + pass diff --git a/src/pydocstyle/plugins.rs b/src/pydocstyle/plugins.rs index 13d328f6fe..d66bb4e212 100644 --- a/src/pydocstyle/plugins.rs +++ b/src/pydocstyle/plugins.rs @@ -223,8 +223,11 @@ pub fn blank_before_after_function(checker: &mut Checker, definition: &Definitio if checker.patch() { // Delete the blank line after the docstring. check.amend(Fix::deletion( - Location::new(docstring.location.row() + 1, 0), - Location::new(docstring.location.row() + 1 + blank_lines_after, 0), + Location::new(docstring.end_location.unwrap().row() + 1, 0), + Location::new( + docstring.end_location.unwrap().row() + 1 + blank_lines_after, + 0, + ), )); } checker.add_check(check); diff --git a/src/snapshots/ruff__linter__tests__D201_D.py.snap b/src/snapshots/ruff__linter__tests__D201_D.py.snap index e0de2671a0..e238c21736 100644 --- a/src/snapshots/ruff__linter__tests__D201_D.py.snap +++ b/src/snapshots/ruff__linter__tests__D201_D.py.snap @@ -38,4 +38,40 @@ expression: checks row: 146 column: 0 applied: false +- kind: + NoBlankLineBeforeFunction: 1 + location: + row: 541 + column: 4 + end_location: + row: 544 + column: 7 + fix: + patch: + content: "" + location: + row: 540 + column: 0 + end_location: + row: 541 + column: 0 + applied: false +- kind: + NoBlankLineBeforeFunction: 1 + location: + row: 563 + column: 4 + end_location: + row: 566 + column: 7 + fix: + patch: + content: "" + location: + row: 562 + column: 0 + end_location: + row: 563 + column: 0 + applied: false diff --git a/src/snapshots/ruff__linter__tests__D202_D.py.snap b/src/snapshots/ruff__linter__tests__D202_D.py.snap index ed7f5fbb5c..1c7a625254 100644 --- a/src/snapshots/ruff__linter__tests__D202_D.py.snap +++ b/src/snapshots/ruff__linter__tests__D202_D.py.snap @@ -38,4 +38,40 @@ expression: checks row: 148 column: 0 applied: false +- kind: + NoBlankLineAfterFunction: 1 + location: + row: 550 + column: 4 + end_location: + row: 553 + column: 7 + fix: + patch: + content: "" + location: + row: 554 + column: 0 + end_location: + row: 555 + column: 0 + applied: false +- kind: + NoBlankLineAfterFunction: 1 + location: + row: 563 + column: 4 + end_location: + row: 566 + column: 7 + fix: + patch: + content: "" + location: + row: 567 + column: 0 + end_location: + row: 568 + column: 0 + applied: false diff --git a/src/snapshots/ruff__linter__tests__D213_D.py.snap b/src/snapshots/ruff__linter__tests__D213_D.py.snap index 716895ecba..9cf5d75bdc 100644 --- a/src/snapshots/ruff__linter__tests__D213_D.py.snap +++ b/src/snapshots/ruff__linter__tests__D213_D.py.snap @@ -130,4 +130,28 @@ expression: checks row: 527 column: 7 fix: ~ +- kind: MultiLineSummarySecondLine + location: + row: 541 + column: 4 + end_location: + row: 544 + column: 7 + fix: ~ +- kind: MultiLineSummarySecondLine + location: + row: 550 + column: 4 + end_location: + row: 553 + column: 7 + fix: ~ +- kind: MultiLineSummarySecondLine + location: + row: 563 + column: 4 + end_location: + row: 566 + column: 7 + fix: ~