Skip to content

Commit

Permalink
add single_blank_line_after_doc_string()
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Mar 2, 2024
1 parent 31883a4 commit 04efa4a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions format_ipy_cells/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,24 @@ def delete_last_cell_if_empty(text: str) -> str:
"""
# \Z matches only at end of string
return re.sub(r"(?m)\s+^# %%\s*\Z", r"\n", text)


def single_blank_line_after_doc_string(text: str) -> str:
"""Ensure single blank line between cell delimiter and preceding module doc string.
Added to avoid clash with ruff format. Started enforcing single blank line in 0.3.0.
--- before ---
'''module doc string.'''
# %%
some_code = 'here'
--- after ---
'''module doc string.'''
# %%
some_code = 'here'
"""
return re.sub(r'(?m)(["\']{3})\n+(# %%)', r"\1\n\n\2", text)
3 changes: 3 additions & 0 deletions format_ipy_cells/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
format_comments_after_cell_delimiters,
remove_empty_cells,
remove_empty_lines_starting_cell,
single_blank_line_after_doc_string,
)


Expand Down Expand Up @@ -39,6 +40,8 @@ def fix_file(filename: str) -> int:

text = delete_last_cell_if_empty(text)

text = single_blank_line_after_doc_string(text)

if orig_text != text:
print(f"Rewriting {filename}")

Expand Down

0 comments on commit 04efa4a

Please sign in to comment.