Skip to content

Commit

Permalink
Docstring formatting: Preserve tab indentation when using `indent-sty…
Browse files Browse the repository at this point in the history
…le=tabs`
  • Loading branch information
MichaReiser committed Feb 9, 2024
1 parent 7893be7 commit 83b40d6
Show file tree
Hide file tree
Showing 5 changed files with 537 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ ij_formatter_enabled = false

["range_formatting/*.py"]
generated_code = true
ij_formatter_enabled = false

[docstring_tab_indentation.py]
generated_code = true
ij_formatter_enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"indent_style": "tab",
"indent_width": 4
},
{
"indent_style": "tab",
"indent_width": 8
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Tests the behavior of the formatter when it comes to tabs inside docstrings
# when using `indent_style="tab`

# The example below uses tabs exclusively. The formatter should preserve the tab indentation
# of `arg1`.
def tab_argument(arg1: str) -> None:
"""
Arguments:
arg1: super duper arg with 2 tabs in front
"""

# The `arg1` is intended with spaces. The formatter should not change the spaces to a tab
# because it must assume that the spaces are used for alignment and not indentation.
def space_argument(arg1: str) -> None:
"""
Arguments:
arg1: super duper arg with a tab and a space in front
"""

def under_indented(arg1: str) -> None:
"""
Arguments:
arg1: super duper arg with a tab and a space in front
arg2: Not properly indented
"""

def under_indented_tabs(arg1: str) -> None:
"""
Arguments:
arg1: super duper arg with a tab and a space in front
arg2: Not properly indented
"""


# The docstring itself is indented with spaces but the argument is indented by a tab.
# Keep the tab indentation of the argument, convert th docstring indent to tabs.
def space_indented_docstring_containing_tabs(arg1: str) -> None:
"""
Arguments:
arg1: super duper arg
"""


# The docstring uses tabs, spaces, tabs indentation.
# Fallback to use space indentation
def mixed_indentation(arg1: str) -> None:
"""
Arguments:
arg1: super duper arg with a tab and a space in front
"""


# The example shows an ascii art. The formatter should not change the spaces
# to tabs because it breaks the ASCII art when inspecting the docstring with `inspect.cleandoc(ascii_art.__doc__)`
# when using an indent width other than 8.
def ascii_art():
r"""
Look at this beautiful tree.
a
/ \
b c
/ \
d e
"""


Loading

0 comments on commit 83b40d6

Please sign in to comment.