-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(fmt): rewrite formatter using Solar and a structured algorithm #10907
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
Conversation
…to rusowsky/fmt-solar
* 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 <0xrusowsky@proton.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boom
not sure if this was expected but i think this change yields different formatting result than previously leading to broken formatting checks without any changes. just fyi. |
@0xferrous some of them are intended, interested to check your, mind to open a ticket with diff and we'll review? Thank you |
oh the diff is too big, i will have to set some time aside to dedupe. but one that seems obviously wrong/unexpected is nestedStruct.val.contract.function(
param1, param2, param3 // long line
); getting converted to: nestedStruct.val.contract
.function(param1, param2, param3); |
@0xferrous we are aware of that and working for a fix with #11834 |
@0xferrous also, is your repo public so we can give it a try with new formatter? |
unfortunately its not public and not my project |
@@ -0,0 +1,26 @@ | |||
alias forge-fmt="cargo r --quiet -p forge-fmt --" | |||
forge-fmt-cmp() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xrusowsky nit: did we intend for this to be pushed to master
, looks like a dev leftover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you encounter any presumed inconsistencies or invalid fmt output please open an issue! |
Motivation
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 onrustc_ast_pretty
andprettyplease
, both MIT and Apache licensed. Seeprettyplease
's README for algorithm notes, as well as the new fmt README.md for more details.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 crateThis was done with #11570 and merged into this PR.crates/fmt-2
to reduce unrelated changes and aid with review. A follow-up PR will replacecrates/fmt
and deal with fallout in-tree.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.
line_length
to be a hard requirement #4450forge fmt
): sorting of imports adds newlines in groups #7944- [ ] Fixes\ bug(for the time being won't be fixed as it requires more spans in solarforge fmt
): ignoresforgefmt: disable-next-line
in argument lists #8557transient
keyword by moving to Solar #9088forgefmt: disable-next-line
#11249Tests state
Supported Configs:
indent_style = IndentStyle
multiline_func_header: MultilineFuncHeaderStyle
line_length: usize
tab_width: usize
bracket_spacing: bool
int_types: IntTypes
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
pow_no_space: bool
Fixes feat(fmt): option to remove spaces between number and exponent #4512Pending TODOs