fix(cargo-heather): preserve CRLF line endings in --fix mode#31
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #31 +/- ##
=======================================
+ Coverage 89.4% 90.0% +0.6%
=======================================
Files 15 15
Lines 756 808 +52
=======================================
+ Hits 676 728 +52
Misses 80 80 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
There was a problem hiding this comment.
Pull request overview
This PR updates cargo-heather’s --fix path to preserve the input file’s line-ending style (CRLF vs LF) when rewriting/adding license headers, addressing unintended CRLF→LF normalization especially on Windows setups.
Changes:
- Detect the input file’s line-ending style in
process::fix()and thread it through internal formatting/reassembly helpers. - Update header formatting and reassembly helpers to join lines with the detected separator instead of hard-coded
"\n". - Add regression tests to ensure CRLF/LF preservation and byte-equivalence when no changes are needed.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/cargo-heather/src/process.rs | Detect line endings in fix(), thread into checker, and add CRLF/LF preservation tests. |
| crates/cargo-heather/src/comment.rs | Change header formatting to join with a provided line ending. |
| crates/cargo-heather/src/checker/strip.rs | Preserve line endings in header stripping/reassembly helpers by using the provided separator. |
| crates/cargo-heather/src/checker/mod.rs | Thread detected line ending through fix() and header prepending logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The internal helpers all use `.lines()` (which strips both `\n` and
`\r\n`) followed by `.join("\n")`, silently converting CRLF files to
LF when `--fix` rewrites them. This is especially problematic on
Windows where git may be configured with `core.autocrlf = true`.
Fix: detect the line-ending style at the `process::fix()` entry point
and thread it through every formatting and reassembly helper so they
emit the correct separator natively. When the header is already
correct, the original bytes are written unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6c871ba to
a1b59e9
Compare
The internal helpers all use
.lines()(which strips both\nand\r\n) followed by.join("\n"), silently converting CRLF files to LF when--fixrewrites them. This is especially problematic on Windows where git may be configured withcore.autocrlf = true.Fix: detect the line-ending style at the
process::fix()entry point and thread it through every formatting and reassembly helper so they emit the correct separator natively. When the header is already correct, the original bytes are written unchanged.