Skip to content

Conversation

@DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Apr 22, 2025

Rewrite forge-fmt entirely to use Solar as the Solidity/Yul parser and AST, and using a structured pretty-printing algorithm.

The language-agnostic implementation of the pretty-printer (src/pp) is based on rustc_ast_pretty and prettyplease, both MIT and Apache licensed. See prettyplease's README for algorithm notes.

The goal of this PR is to make progress with #9317, and fixing existing issues with the formatter while trying to maintain compatibility as much as possible.

This PR will not be replacing the formatter yet, opting to create a separate crate crates/fmt-2 to reduce unrelated changes and aid with review. A follow-up PR will replace crates/fmt and deal with fallout in-tree.

WIP

Progress

Tests:

13 passed; 40 failed; 1 ignored

Implementation:

  • items
    • pragma
    • import
    • using
    • contract/interface/library
    • function/modifier
    • variable declaration
    • struct
    • enum
    • UDVT
    • error
    • event
  • types
  • expressions
    • literals
    • ...
  • statements
    • if
    • while
    • do while
    • for
    • try-catch
    • ...
  • yul
    • expressions
    • statements
    • functions

Other:

  • Update README.md
  • Refactor printing delimited groups to handle span/comments
  • Print docs that get discarded during parsing like other comments
  • Add a non-fatal error that returns the formatted source with the errors
  • Add snapshot infra to tests to automatically update 'expected' files

Configs:

  • line_length: usize
  • tab_width: usize
  • bracket_spacing: bool
  • int_types: IntTypes
  • multiline_func_header: MultilineFuncHeaderStyle
  • quote_style: QuoteStyle
  • number_underscore: NumberUnderscore
  • hex_underscore: HexUnderscore
  • single_line_statement_blocks: SingleLineBlockStyle
  • override_spacing: bool
  • wrap_comments: bool
  • ignore: Vec<String>
  • contract_new_lines: bool
  • sort_imports: bool

Issues

Issues that will be fixed with the new implementation. Not closed by this PR, but by the follow-up that will hook the new implementation up; see paragraph above.

@jenpaff jenpaff moved this to In Progress in Foundry May 15, 2025
@jenpaff jenpaff added this to the v1.3.0 milestone Jun 17, 2025
@jenpaff jenpaff linked an issue Jul 1, 2025 that may be closed by this pull request
@jenpaff jenpaff modified the milestones: v1.3.0, v1.4.0 Jul 7, 2025
@DaniPopes
Copy link
Member Author

Closing in favor of #10907

@DaniPopes DaniPopes closed this Aug 6, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Foundry Aug 6, 2025
@grandizzy grandizzy moved this from Done to Completed in Foundry Aug 18, 2025
@DaniPopes DaniPopes deleted the dani/fmt-solar branch August 26, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

feat(fmt): option to remove spaces between number and exponent

5 participants