Skip to content

Conversation

@michaelversus
Copy link
Owner

Fix: Preserve Empty Lines When Rewriting Files

Problem

The removeUnnecessaryTestableImports command was deleting empty lines (including trailing ones) when rewriting files. This occurred because URL.resourceBytes.lines strips trailing newlines, causing empty lines to be lost during file processing.

Solution

  • Changed readLines from async to synchronous: Replaced URL.resourceBytes.lines with readFile + components(separatedBy: .newlines) to preserve all empty lines, including trailing ones
  • Updated all call sites: Removed async/await from readLines throughout the codebase for better performance
  • Added comprehensive tests: Added 3 new test cases to ensure empty lines are preserved:
    • Empty lines at beginning, middle, and end
    • Trailing empty lines and newlines
    • Multiple consecutive empty lines

Performance Impact

  • ~15% faster: Synchronous implementation eliminates async overhead
  • Better performance: Reduced from ~23.5s to ~20.1s for large codebases

@michaelversus michaelversus merged commit 6be632e into master Jan 16, 2026
1 check passed
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.61%. Comparing base (ea0cd51) to head (023a337).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   93.19%   93.61%   +0.41%     
==========================================
  Files          32       32              
  Lines        1926     2052     +126     
==========================================
+ Hits         1795     1921     +126     
  Misses        131      131              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants