Skip to content

fix(cargo-heather): preserve CRLF line endings in --fix mode#31

Merged
Vaiz merged 1 commit into
mainfrom
u/vaiz/heather-line-endings
May 25, 2026
Merged

fix(cargo-heather): preserve CRLF line endings in --fix mode#31
Vaiz merged 1 commit into
mainfrom
u/vaiz/heather-line-endings

Conversation

@Vaiz
Copy link
Copy Markdown
Contributor

@Vaiz Vaiz commented May 25, 2026

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.

Copilot AI review requested due to automatic review settings May 25, 2026 13:18
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 25, 2026

Codecov Report

❌ Patch coverage is 94.38202% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.0%. Comparing base (93c6346) to head (a1b59e9).

Files with missing lines Patch % Lines
crates/cargo-heather/src/checker/strip.rs 83.3% 5 Missing ⚠️
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.
📢 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 25, 2026

⚠️ Breaking Changes Detected


--- failure method_parameter_count_changed: pub method parameter count changed ---

Description:
A publicly-visible method now takes a different number of parameters, not counting the receiver (self) parameter.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/method_parameter_count_changed.ron

Failed in:
  cargo_heather::CommentStyle::format_header now takes 2 parameters instead of 1, in /home/runner/work/ox-tools/ox-tools/crates/cargo-heather/src/comment.rs:125

If the breaking changes are intentional then everything is fine - this message is merely informative.

Remember to apply a version number bump with the correct severity when publishing a version with breaking changes (1.x.x -> 2.x.x or 0.1.x -> 0.2.x).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/cargo-heather/src/process.rs
Comment thread crates/cargo-heather/src/comment.rs
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>
@Vaiz Vaiz force-pushed the u/vaiz/heather-line-endings branch from 6c871ba to a1b59e9 Compare May 25, 2026 14:00
@Vaiz Vaiz enabled auto-merge (squash) May 25, 2026 14:47
@Vaiz Vaiz merged commit 17e35dc into main May 25, 2026
25 checks passed
@Vaiz Vaiz deleted the u/vaiz/heather-line-endings branch May 25, 2026 15:36
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.

5 participants