Skip to content

Commit 112a80b

Browse files
committed
fix: wip: add function to check if docstring is at end of file
1 parent 7798699 commit 112a80b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/docformatter/classify.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,18 @@ def is_string_variable(
471471
return True
472472

473473
return False
474+
475+
476+
def is_docstring_at_end_of_file(tokens: list[tokenize.TokenInfo], index: int) -> bool:
477+
"""Determine if the docstring is at the end of the file."""
478+
for i in range(index + 1, len(tokens)):
479+
tok = tokens[i]
480+
if tok.type not in (
481+
tokenize.NL,
482+
tokenize.NEWLINE,
483+
tokenize.DEDENT,
484+
tokenize.ENDMARKER,
485+
):
486+
return False
487+
488+
return True

src/docformatter/format.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ def _get_newlines_by_type(
379379
int
380380
The number of newlines to insert after the docstring.
381381
"""
382-
if _classify.is_module_docstring(tokens, index):
382+
if _classify.is_docstring_at_end_of_file(tokens, index):
383+
# print("End of file")
384+
return 0
385+
elif _classify.is_module_docstring(tokens, index):
383386
# print("Module")
384387
return _get_module_docstring_newlines(black)
385388
elif _classify.is_class_docstring(tokens, index):

0 commit comments

Comments
 (0)