Skip to content

Commit

Permalink
Update docs_formatter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
he11owthere authored Nov 29, 2023
1 parent ff10e0e commit 0f98a43
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions ivy_lint/formatters/docs_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ def format_docstring(self, doc):
codeblock_start_lines = set() # This will store indices of lines which start a code block
lines_to_modify = set() # This will store the indices of indented lines not containing "..."
is_codeblock_cont = False
lb = 0
rb = 0

for idx, line in enumerate(lines):
stripped_line = line.strip()

if is_codeblock and is_codeblock_cont and not stripped_line.startswith(('>>>', '...')):
lines_to_modify.add(idx)
if stripped_line.startswith('>>>'):
if "(" in line:
is_codeblock_cont = True
#if stripped_line.endswith(')'):
if ")" in line:
is_codeblock_cont = False
if not is_codeblock and stripped_line.startswith('>>>'):
is_codeblock = True
codeblock_start_lines.add(idx)
#elif is_codeblock and (not stripped_line or (not stripped_line.startswith(('>>>', '...', '[', '(')) and not stripped_line.endswith((')', ',', '\\', '(', '[', ']')))):
elif is_codeblock and not is_codeblock_cont and (not stripped_line or (not stripped_line.startswith(('>>>', '...')))):
is_codeblock = False
#if is_codeblock and (not stripped_line.startswith(('>>>', '...')) and (stripped_line.startswith(('[', '(')) or stripped_line.endswith((')', ',', '\\', '(', '[', ']')))):
# lines_to_modify.add(idx)
if is_codeblock:
lb += line.count('(')
rb += line.count(')')
if rb >= lb:
rb = 0
lb = 0
is_codeblock_cont = False
else:
lb = lb - rb
rb = 0
is_codeblock_cont = True
if not stripped_line.startswith(('>>>', '...')):
lines_to_modify.add(idx)

# Add blank lines before code blocks
formatted_lines = []
Expand Down

0 comments on commit 0f98a43

Please sign in to comment.