New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: account for explicit_start=False when handling whitelines #224
Conversation
Pull Request Test Coverage Report for Build 4134059727Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking the time to do a contribution :)
There are some details I'd like to polish before we merge this though, please look at the comments below.
@@ -673,7 +673,7 @@ def _replace_whitelines(match: Match[str], n_whitelines: int) -> str: | |||
|
|||
def _fix_section_whitelines(self, source_code: str) -> str: | |||
re_section = "\n*(^#.*\n)*\n*^[^ ].*:\n(\n|(^ .*))+\n*" | |||
re_beginning_section = f"(?P<b>---\n{re_section})" | |||
re_beginning_section = f"(?P<b>(?:---\n|\\A){re_section})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never heard of the \A
section beginning? Is this an official thing?.
Could you add a comment above the line pointing to a link in the official documentation where it explains it's use?
I'm trying to avoid the WTF moment in 6 months when we read this regexp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. It was new to me too. I've linked to the Python regex syntax docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I thought that the \A
was a yaml thing not a regexp thing (facepalm). LGTM
The regex would check for `---\n` as the file start which would not necessarily apply if `explicit_start=False`. This change also considers `\A` as an alternative file start.
1272ef9
to
dda623a
Compare
@@ -673,7 +673,7 @@ def _replace_whitelines(match: Match[str], n_whitelines: int) -> str: | |||
|
|||
def _fix_section_whitelines(self, source_code: str) -> str: | |||
re_section = "\n*(^#.*\n)*\n*^[^ ].*:\n(\n|(^ .*))+\n*" | |||
re_beginning_section = f"(?P<b>---\n{re_section})" | |||
re_beginning_section = f"(?P<b>(?:---\n|\\A){re_section})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I thought that the \A
was a yaml thing not a regexp thing (facepalm). LGTM
Available since |
The regex would check for
---\n
as the file start which would not necessarily apply ifexplicit_start=False
. This change also considers\A
as an alternative file start.I wasn't able to find an open issue to link this change to. Please advise if any documentation is required for this change.
Checklist