Skip to content

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Sep 29, 2025

Motivation

closes:

Solution

rather than blindly advancing the cursor by 1, we need to check if the current character is \r to account for the whole CRLF sequence and advance 2 chars instead.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@0xrusowsky 0xrusowsky marked this pull request as ready for review September 29, 2025 17:33
Comment on lines +28 to +31
// Figure out if the cursor needs to check for CR (`\r`).
if let Some(item) = source_unit.items.first() {
self.check_crlf(item.span.to(source_unit.items.last().unwrap().span));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i believe that initially checking if the file contains \r to then skip checking the sourcemap each time is more efficient, but feel free to push back if u disagree

@0xrusowsky 0xrusowsky linked an issue Sep 29, 2025 that may be closed by this pull request
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

this is fine, it assumes cr = crlf but thats ok because bare cr is usually invalid code although might not be rejected by solc

please fix the "closes" directive in the PR description to actually auto close the issue

@grandizzy grandizzy merged commit cafabf0 into master Sep 29, 2025
40 of 44 checks passed
@grandizzy grandizzy deleted the rusowsky/cursor-crlf branch September 29, 2025 19:03
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

fix(fmt): properly handle CRLF on windows files
3 participants