import re


def delete_last_cell_if_empty(text: str) -> str:
    """Delete last cell in file if it contains no code and no comment.

    --- before ---
    # %%
    some_code = 'here'

    # %%

    --- after ---
    # %%
    some_code = 'here'

    """
    # \Z matches only at end of string
    return re.sub(r"(?m)\s+^# %%\s*\Z", r"\n", text)