Skip to content

Commit 98cdd94

Browse files
DanielNoordjspaezp
andcommitted
Create the AddBFormatter example formatter
Co-authored-by: J. Sebastian Paez <[email protected]>
1 parent 93b15ca commit 98cdd94

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pydocstringformatter/_testutils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydocstringformatter import run_docstring_formatter
1111
from pydocstringformatter._formatting import Formatter
1212
from pydocstringformatter._testutils.example_formatters import (
13+
AddBFormatter,
1314
MakeAFormatter,
1415
MakeBFormatter,
1516
)
@@ -83,4 +84,4 @@ def __exit__(
8384
return None
8485

8586

86-
__all__ = ["FormatterAsserter", "MakeAFormatter", "MakeBFormatter"]
87+
__all__ = ["FormatterAsserter", "MakeAFormatter", "MakeBFormatter", "AddBFormatter"]

pydocstringformatter/_testutils/example_formatters.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo:
2727
token_dict = tokeninfo._asdict()
2828
token_dict["string"] = token_dict["string"].replace("A", "B")
2929
return type(tokeninfo)(**token_dict)
30+
31+
32+
class AddBFormatter(Formatter):
33+
"""A formatter that adds Bs."""
34+
35+
name = "add-b-formatter"
36+
style = ["default"]
37+
38+
def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo:
39+
"""Add a B to the end of the string."""
40+
token_dict = tokeninfo._asdict()
41+
token_dict["string"] += "B"
42+
return type(tokeninfo)(**token_dict)

0 commit comments

Comments
 (0)