Skip to content

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Oct 7, 2025

Motivation

closes #12000

Solution

ensure leading blank lines are always removed, even when there are no items in the source

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@0xrusowsky 0xrusowsky changed the title fix(fmt): ws only edgecase fix(fmt): ensure leading blank lines are always removed Oct 7, 2025
@grandizzy grandizzy added this to the v1.5.0 milestone Oct 7, 2025
@0xrusowsky
Copy link
Contributor Author

0xrusowsky commented Oct 7, 2025

@0xalpharush i was unable to repro the issue with contracts that had some source items:

$ echo "\n\ncontract Test {}" > test.sol

$ forge fmt test.sol --check
Warning: This is a nightly build of Foundry. It is recommended to use the latest stable version. To mute this warning set `FOUNDRY_DISABLE_NIGHTLY_WARNING` in your environment.

Diff in src/test.sol:
1        |-
2        |-
3   1    | contract Test {}

please confirm that you were exploring edgecases when the source code only contains cmnts, and that your repro wasn't just a minimal repro from a scenario with actual code.

with the proposed fix, leading blank lines are always removed, even when there is no actual code (just cmnts)

$ echo "\n\n" > test.sol

$ ../../foundry/master/target/release/forge fmt --check
Diff in src/test.sol:
1        |-
2        |-
3        |-

$ echo "\n\n// this is a cmnt" > test.sol

$ ../../foundry/master/target/release/forge fmt --check
Diff in src/test.sol:
1        |-
2        |-
3   1    | // this is a cmnt

@DaniPopes
Copy link
Member

can we add a test?

@0xalpharush
Copy link
Contributor

@0xrusowsky It is an edge case

@0xrusowsky 0xrusowsky enabled auto-merge (squash) October 7, 2025 15:29
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

lgtm

@0xrusowsky 0xrusowsky merged commit a0ba15c into master Oct 7, 2025
16 checks passed
@0xrusowsky 0xrusowsky deleted the rusowsky/12000 branch October 7, 2025 16:12
@github-project-automation github-project-automation bot moved this to Done in Foundry Oct 7, 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.

bug(fmt): 1st blank line is always removed (not idempotent)

4 participants