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 Black formatting on Windows (issue #133) #142

Merged
merged 14 commits into from
Jun 26, 2021

Conversation

akaihola
Copy link
Owner

@akaihola akaihola commented May 23, 2021

black.format_str() expects content to have Unix newlines. With Windows CRLF, it will give different results.

Make sure content newlines are converted from CRLF to LF before calling black.format_str(). Fixes #133.

  • unit tests for new and changed code
  • change log

@akaihola akaihola added the bug Something isn't working label May 23, 2021
@akaihola akaihola self-assigned this May 23, 2021
@akaihola akaihola marked this pull request as draft May 23, 2021 05:50
@akaihola akaihola force-pushed the windows-formatting-mismatch branch 3 times, most recently from bd29f6b to c4ff3f4 Compare May 23, 2021 15:50
@akaihola akaihola changed the title Debug the Windows formatting mismatch (issue #133) Fix Black formatting on Windows (issue #133) May 24, 2021
@akaihola akaihola requested a review from martinRenou May 24, 2021 05:38
@akaihola akaihola added this to the 1.2.4 milestone May 24, 2021
@akaihola akaihola force-pushed the windows-formatting-mismatch branch 3 times, most recently from 1cb78e9 to 70bc8b8 Compare May 24, 2021 15:15
@akaihola akaihola marked this pull request as ready for review May 24, 2021 18:32
@akaihola
Copy link
Owner Author

@martinRenou, I think I solved the issue of Black giving different results on Windows. It was because Darker would pass files with CRLF as newlines to black.format_str() as such, when Black expects UNIX newlines (LF).

The issue has been debugged and fixed in this PR.

Would you happen to have time for a review?

@akaihola akaihola force-pushed the windows-formatting-mismatch branch from 70bc8b8 to 2b9213d Compare May 25, 2021 11:07
@akaihola akaihola requested a review from ivanov May 25, 2021 18:11
This was referenced May 25, 2021
@akaihola akaihola requested a review from Mystic-Mirage May 26, 2021 18:39
@akaihola akaihola force-pushed the windows-formatting-mismatch branch from 2b9213d to dfa23f5 Compare June 26, 2021 21:06
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 26, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.23%.

Quality metrics Before After Change
Complexity 1.55 ⭐ 1.36 ⭐ -0.19 👍
Method Length 45.09 ⭐ 46.51 ⭐ 1.42 👎
Working memory 5.66 ⭐ 5.64 ⭐ -0.02 👍
Quality 84.62% 84.85% 0.23% 👍
Other metrics Before After Change
Lines 639 674 35
Changed files Quality Before Quality After Quality Change
src/darker/black_diff.py 81.26% ⭐ 79.91% ⭐ -1.35% 👎
src/darker/utils.py 84.17% ⭐ 85.60% ⭐ 1.43% 👍
src/darker/tests/test_black_diff.py 77.63% ⭐ 80.69% ⭐ 3.06% 👍
src/darker/tests/test_utils.py 87.73% ⭐ 86.68% ⭐ -1.05% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
src/darker/tests/test_utils.py test_textdocument_eq 0 ⭐ 216 ⛔ 7 🙂 63.89% 🙂 Try splitting into smaller methods
src/darker/tests/test_utils.py test_textdocument_string_with_newline 0 ⭐ 103 🙂 10 😞 68.60% 🙂 Extract out complex expressions
src/darker/utils.py TextDocument.__repr__ 3 ⭐ 66 🙂 10 😞 70.98% 🙂 Extract out complex expressions
src/darker/utils.py TextDocument.__init__ 1 ⭐ 41 ⭐ 10 😞 76.94% ⭐ Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@akaihola
Copy link
Owner Author

Contributors are busy, all tests pass. I'll just trust my past self and merge this now.

@akaihola akaihola merged commit 4d0b0f5 into master Jun 26, 2021
@akaihola akaihola deleted the windows-formatting-mismatch branch June 26, 2021 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging this pull request may close these issues.

Different Black formatting results on Windows
1 participant