@@ -37,3 +37,32 @@ def _treat_string(self, tokeninfo: tokenize.TokenInfo) -> str:
3737 elif len (split_string ) == 2 and split_string [- 1 ] == good_end :
3838 new_string = "\n " .join (split_string [:- 1 ]) + tokeninfo .string [0 ] * 3
3939 return new_string
40+
41+
42+ class FinalPeriodFormatter (StringFormatter ):
43+ """Add a period to the end of single line docstrings and summaries."""
44+
45+ name = "final-period"
46+
47+ def _treat_string (self , tokeninfo : tokenize .TokenInfo ) -> str :
48+ """Add a period to the end of single-line docstrings and summaries."""
49+ # Handle single line docstrings
50+ if not tokeninfo .string .count ("\n " ):
51+ if tokeninfo .string [- 4 ] != "." :
52+ return tokeninfo .string [:- 3 ] + "." + tokeninfo .string [- 3 :]
53+ # Handle multi-line docstrings
54+ else :
55+ first_linebreak = tokeninfo .string .index ("\n " )
56+ # If first linebreak is followed by another we're dealing with a summary
57+ if tokeninfo .string [tokeninfo .string .index ("\n " ) + 1 ] == "\n " :
58+ if tokeninfo .string [first_linebreak - 1 ] != "." :
59+ return (
60+ tokeninfo .string [:first_linebreak ]
61+ + "."
62+ + tokeninfo .string [first_linebreak :]
63+ )
64+ # pylint: disable=fixme
65+ # TODO: Handle multi-line docstrings that do not have a summary
66+ # This is obviously dependent on whether 'pydocstringformatter' will
67+ # start enforcing summaries :)
68+ return tokeninfo .string
0 commit comments