foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`forge fmt` minor unexpected formatting results

Open Hyodar opened this issue 3 years ago • 4 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

forge 0.2.0 (cce3a44 2022-07-20T00:34:27.703293Z)

What command(s) is the bug in?

forge fmt

Operating System

Windows

Describe the bug

Hello there!

Nothing major but I believe the formatting is a bit odd in some cases. Two cases I noticed:

  • Opening brace goes to the next line when the line is long (but not too long!):

    Before:

            if (something() || somethingElse() || anotherThing() || someOtherThin()) {
                return false;
            }
    

    After:

            if (something() || somethingElse() || anotherThing() || someOtherThin())
            {
                return false;
            }
    

    Curiously, if the last function in the expression is someOtherTh(), which would still make the line length go past 80, the line stays the same, and if it's someOtherThing(), it works as expected by moving the expression to the next line.

  • Binary operators seem to always be positioned at the same column when breaking long expressions into multiple lines:

    This one I'm less sure than the first one about whether it's a bug or just something that's not currenty implemented but will be.

    Before:

    bool somethingElse = something == 2 || something == 3 || something == 5 || something == 7 || something == 11;
    

    After:

    bool somethingElse = something
        == 2
        || something
        == 3
        || something
        == 5
        || something
        == 7
        || something
        == 11;
    

That's it. By the way, I've been trying out forge and it's been a great experience. Good work!

Hyodar avatar Jul 20 '22 01:07 Hyodar

Here is a similar example but even more extreme: https://github.com/sambacha/dappspec/blob/master/solidity/src/Recommendations/Large-Integers.md

sambacha avatar Jul 22 '22 23:07 sambacha

cc @rkrasiuk / @jpopesculian unsure if this is still the case

onbjerg avatar Aug 11 '22 19:08 onbjerg

I was hoping that the linter would allow one line conditionals. Going to append this here as a comment for now instead of making a new issue.

image

ewilz avatar Aug 29 '22 18:08 ewilz

@ewilz currently we support this only in yul blocks. feel free to open a feature request for fmt config option

rkrasiuk avatar Aug 29 '22 18:08 rkrasiuk

Everything here appears to be resolved now, so closing this

mds1 avatar Feb 28 '23 18:02 mds1