Skip to content
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

Merged
merged 1 commit into from Feb 13, 2023

Conversation

rvause
Copy link
Contributor

@rvause rvause commented Feb 9, 2023

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.

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

  • Add test cases to all the changes you introduce
  • Update the documentation for the changes

@rvause rvause changed the title fix: account for explicit_start=False when handline whitelines fix: account for explicit_start=False when handling whitelines Feb 9, 2023
@coveralls
Copy link

coveralls commented Feb 9, 2023

Pull Request Test Coverage Report for Build 4134059727

Warning: 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

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 99.797%

Totals Coverage Status
Change from base Build 4102628896: 0.0%
Covered Lines: 491
Relevant Lines: 492

💛 - Coveralls

Copy link
Owner

@lyz-code lyz-code left a 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})"
Copy link
Owner

@lyz-code lyz-code Feb 10, 2023

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

Copy link
Contributor Author

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.

Copy link
Owner

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

tests/unit/test_adapter_yaml.py Show resolved Hide resolved
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.
@@ -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})"
Copy link
Owner

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

@lyz-code lyz-code merged commit aff9e49 into lyz-code:main Feb 13, 2023
@lyz-code
Copy link
Owner

Available since 1.8.1 thanks @rvause !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants