Skip to content

Conversation

grandizzy
Copy link
Collaborator

Motivation

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@grandizzy grandizzy force-pushed the fmt-solar-gg branch 10 times, most recently from aa71d29 to 695e98a Compare September 23, 2025 10:43
@grandizzy grandizzy requested a review from DaniPopes September 23, 2025 13:25
@grandizzy grandizzy marked this pull request as ready for review September 23, 2025 13:25
Copy link
Contributor

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

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

testing this it looks good from my end

then: &'ast ast::Stmt<'ast>,
inline: bool,
) {
// NOTE(rusowsky): unless we add bracket spans to solar,
Copy link
Member

@DaniPopes DaniPopes Sep 23, 2025

Choose a reason for hiding this comment

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

this comment is outdated, can this be fixed / what's missing? @0xrusowsky
the until is correct here, but should be to as indicated by the comment

Copy link
Contributor

@0xrusowsky 0xrusowsky Sep 23, 2025

Choose a reason for hiding this comment

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

why is it outdated? @DaniPopes

    /// An `if` statement with an optional `else` block: `if (expr) { ... } else { ... }`.
    If(Box<'ast, Expr<'ast>>, Box<'ast, Stmt<'ast>>, Option<Box<'ast, Stmt<'ast>>>),

with this info i cannot print the comments as in the original code for these 2 scenarios:

    if /* comment10 */ (anotherLongCondition) // comment11
       /* comment12 */ {
            execute() ;
    } // comment13
    if (
        step.opcode == 0x52
            && /*MSTORE*/ step.stack[0] == testContract.memPtr() // MSTORE offset
            && step.stack[1] == testContract.expectedValueInMemory() // MSTORE val
    ) {
        mstoreCalled = true;
    }

cause the span of the if expr in the 1st scenario is only the anotherLongCondition ident, and in the 2nd one the binary operator expr

so i either need to:

  • self.print_if_cond("if", cond, then.span.lo())
  • self.print_if_cond("if", cond, cond.span.hi())

the former is the one we do now, cause imo is more consistent with the old behavior (puts everything inside the condition's parenthesis)

the later leaves all comments out of the parenthesis, so the first scenario would work, but the other one would output something like:

    if (
        step.opcode == 0x52
            && /*MSTORE*/ step.stack[0] == testContract.memPtr() // MSTORE offset
            && step.stack[1] == testContract.expectedValueInMemory()
    ) // MSTORE val
    {
        mstoreCalled = true;
    }

anyways, i think we can simply remove the comment. i only added it initially because i didn't know we were willing to not have 100% exact compatibility with the old formatter.
imo the if statement comment handling looks good, so the comment is not really necessary (unlike the DeclMulti comment, which could be a little bit more annoying for users, although they can simply use inline disable)

Copy link
Contributor

@0xrusowsky 0xrusowsky Sep 23, 2025

Choose a reason for hiding this comment

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

fyi, i deleted the cmnt.

the only implication is that this code:

    if /* comment10 */ (anotherLongCondition) // comment11
       /* comment12 */ {
            execute() ;
    } // comment13

was previously formatted as:

    if /* comment10 */ (
       anotherLongCondition // comment11
    ) {
       /* comment12 */
       execute();
    } // comment13

and now is:

    if /* comment10 */ (
       anotherLongCondition // comment11
       /* comment12 */
    ) {
       execute();
    } // comment13

which is totally acceptable.
and if users want cmnt12 to go below, they simply need to put it inside the block, so that its parsed as part of the stmt

Copy link
Member

Choose a reason for hiding this comment

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

that's fine

the comment was outdated wrt the inline code .span etc inside of the comment itself

Copy link
Contributor

@0xrusowsky 0xrusowsky left a comment

Choose a reason for hiding this comment

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

LGTM, pending Dani's validation

@grandizzy grandizzy merged commit 8e26664 into foundry-rs:rusowsky/fmt-solar Sep 24, 2025
44 of 46 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 24, 2025
@grandizzy grandizzy deleted the fmt-solar-gg branch September 24, 2025 03:33
grandizzy added a commit that referenced this pull request Sep 24, 2025
…10907)

* init

* wip

* wip

* add dbg from prettyplease

* wip

* fixes, pragma&imports

* feat: using, types, literals

* feat: contract

* rm duplicate testdata

* wip: finish items; exprs, stmts

* wips

* feat: line_length, tab_width

* feat: contract_new_lines

* wip: single_line_statement_blocks

* tweaks

* chore: bump solar to latest main

* fix: test dir

* bump

* fix docs

* fix: adjust '()' for modifier calls

* test: typed yul does not exist anymore

argotorg/solidity#15329

* test: function parameters cannot be empty

* fix: adjust '()' for modifier calls for real

* fix: forge fmt hates '*' imports

* test: fix some invalid syntax

* test: disable-stop does not exist

* test: fix all parse errors

* fix: literal touchups

* bump

* test: add snapshotting

* test: update NumberLiteralUnderscore

* fixes

* struct space

* test: fix StructDefinition; empty structs are not allowed anyway

* test: update EventDefinition; matches Solidity style guide

* test: update EnumDefinition; same as StructDefinition

* test: update StructDefinition 2

* fix: comments in structs/enums

* test: update ErrorDefinition; matches Solidity style guide

* feat: print docs with other comments; update EnumVariants

* chore: update EnumDefinition, StructDefinition

* chore: readd post_break

* chore: rename is_hardbreak_tok

* feat: cleanups, more impls

* test: fix some compile errors

* feat: add FormatterResult with more variants

* stuff

* refactor: move print_item arms into their own functions

* chore: consolidate item hardbreaks

* fix: inline config parsing for block comments

* wip: rm FunctionLike, wip functions

* fix: clamp margin to max as well

* megawip

* feat: most of yul

* wip: try-catch

* wip: try-catch

* feat: print compact tuple

* wip: inline comments

* wip: try-cactch

* bump solar to have try-catch spans (#10832)

* wip comment fmt

* wip: array expr

* finish arrays

* block comments

* doc block comments

* ternary operators

* wip: fn header

* wip: fn header

* fix: doc block comments + block braces

* refactor state to organize helpers

* fix commasep with initial trailing cmnt

* fix: improve contract fmt

* fix: block comments + contract definition

* fix: wrap trailing comments

* fix fn alingment

* fix: rmv unecessary check

* working fn headers!!!

* block with comments at the beginning

* bump solar

* inline if statements based on user config

* operator expr

* finish binary operators + housekeeping

* housekeeping

* feat: binary expressions

* fix: string literals

* refactor comments + finish mappings

* named functions

* item spacing

* more flexible comments + return stmts

* var definition and flexible comments (#11093)

* comment wrapping

* sorted imports

* middle cmnts for arrays and literals with subdenominations

* revert: solar won't have spanned dataloc + subdenom

* refactor inline config + almost finished impl

* finish inline disable

* finish inline disable

* wip inline disable for repros

* passing repros

* almost working yul

* chore: remove unrelated changes / merge artifacts

* chore: remove unrelated changes / merge artifacts 2

* chore: remove unrelated changes / merge artifacts 3

* update fmt files to reflect current status

* enable both passes

* undo repros changes

* config: style = tabs

* test: inline config

* style: drop "lint" references in favor of "ids"

* function header config

* finish fn header config!

* re-enable 2nd pass

* finish fn header style

* feat: yul

* test: update tracking cmnts

* fix: yul repros

* chore: small comment

* chore: random + typos

* chore: rm dead code

* chore: rm unused vars

* chore: clippy --fix

* chore: some manual clippying

* chore: final clippy --fix

* refactor: tidy up

* yul: inline blocks

* yul: inline fn params

* ensure all tests are successful

* chore(fmt): merge new compiler setup (#11487)

* patch/impl/test pending repros

* style: typos

* docs: update readme

* docs: readme feedback

* style: clippy

* fix: merge conflicts

* fix: disable legacy fmt tests

* fix: config test

* fix(win): normalize breaks

* style: clippy

* fix(win): normalize escaped quotes

* fix(win): normalize multiline strings

* fix(win): only normalize line breaks for expected data

* chore: solar-powered fmt rollout (#11570)

* fix: comment spans for asm + try blocks

* fix: don't fmt yul addresses

* fix: empty buffer due to really long comment

* add repro

* Revert "fix: empty buffer due to really long comment"

This reverts commit f6768b4.

* fix: advance cursor correctly in print_comment

* fix: bin op indentation in complex exprs

* docs

Co-authored-by: DaniPopes <[email protected]>

* chore: clean up

* refactor: inline config

* chore: share inline config

* feat: remove HIR inline config visitor

* test: bless

* style: clippy

* feat(fmt): call chain awareness (#11611)

* wip: better call chains + return stmts + more tests

* fix: more yul cmnts

* fix: modifier cmnts + more yul cmnts

* fix: returns with bin ops

* fix breaks, still pending indentation

* wip: call cahins and nested... getting closer

* call stack to fmt complex calls

* fix: more yul cmnts

* Fix config test, typos

* wip

* fix: new call alignement cases

* Fix tests

* fix: return + bin ops + calls

* style: clippy

* feat: wrap long comments and merge with next line

* fix: stale test

* style: rmv comments

* fmt nits (#11750)

* nits

* Try no format

* chore: simplify call logic

* fix: reenable 2nd pass

* chore: cleanup

* docs: solar cmnt

* format testdata with new style

* fix: extra space in function type

* Readd relevant todo

* style: use span builder methods

* Review changes

* fix: remove outdated cmnt

* fix: test spacing

* Revert "fix: test spacing"

This reverts commit 541f4c8.

---------

Co-authored-by: 0xrusowsky <[email protected]>

---------

Co-authored-by: DaniPopes <[email protected]>
Co-authored-by: grandizzy <[email protected]>
Co-authored-by: grandizzy <[email protected]>
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.

4 participants