Skip to content

feat(forge fmt): Adds tab support as indent char in fmt #10979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

mathewmeconry
Copy link

@mathewmeconry mathewmeconry commented Jul 10, 2025

Motivation

I want to start to contribute and the issue #10754 was marked as a good first issue.

Solution

Adds support for different styles in fmt config. This allows the user to configure whether tabs or spaces should be used (I don't want to start the age-old discussion here).
tab_width will be ignored by fmt if the style is set to tab.
If no style is given in foundry.toml space will be used as default.

Coverting block comments from space to tab results in issues where the previous spaces will not be ignored. I couldn't figure out a way to solve this properly but I believe it is a non-issue because most teams won't switch from spaces to tabs that often and fixing some comments is fine from my point of view.

Additional to the tab support, a bug in the parsing in InlineConfig for forgefmt: disable-line handling was found and fixed. The previous code doesn't handle CRLF line endings properly and returns the wrong loc for the disabled line (offset by 1 byte).

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@grandizzy
Copy link
Collaborator

thank you! looks like it breaks tests for win

@mathewmeconry
Copy link
Author

thank you! looks like it breaks tests for win

Thanks for running the tests. Fixing this will take a while for me because there seems to be a bug with newlines.
You can reproduce the same issue by formatting the original.sol in Repros with tab_width set to anything else than 4 and the file formatted with CRLF line endings.

With CRLF it still adds indents (tab_width set to 8) :

        function test4() public {
                // forgefmt: disable-next-line
                  assembly{
                        sstore(1, 1)
                        sstore(2, 2)
                        sstore(3,    3)// forgefmt: disable-line
                        sstore(4, 4)
        }// forgefmt: disable-line
                if (condition) execute(); // comment7
        }

While with LF line endings it doesn't (tab_width set to 8):

        function test4() public {
                // forgefmt: disable-next-line
                  assembly{
                        sstore(1, 1)
                        sstore(2, 2)
            sstore(3,    3)// forgefmt: disable-line
                        sstore(4, 4)
        }// forgefmt: disable-line
                if (condition) execute(); // comment7
        }

I assume there is a bug in handling //forgefmt: disable-line when the line ending is set to CRLF.
Do you have any hints where this bug could hide?

@mathewmeconry
Copy link
Author

@grandizzy I think I found and fixed the issue with the last commit. Tests succeed on my fork.
Please run the tests on the pull request to see if this resolves the issue.

@mathewmeconry
Copy link
Author

@grandizzy I think I fixed the bug, but other tests are now failing in parts that I haven't touched. Could this be a race condition or timeouts that happen in tests?

@grandizzy
Copy link
Collaborator

@grandizzy I think I fixed the bug, but other tests are now failing in parts that I haven't touched. Could this be a race condition or timeouts that happen in tests?

hey @mathewmeconry yeah, we're debugging some unexpected failures in CI, will get back to the pr once figured out. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants