Skip to content
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

feat(fmt): literal expressions #2170

Merged
merged 6 commits into from
Jul 6, 2022
Merged

feat(fmt): literal expressions #2170

merged 6 commits into from
Jul 6, 2022

Conversation

rkrasiuk
Copy link
Collaborator

@rkrasiuk rkrasiuk commented Jun 30, 2022

Solution

fmt formatting of:

  • Expression::BoolLiteral
  • Expression::NumberLiteral
  • Expression::HexNumberLiteral
  • Expression::RationalNumberLiteral
  • Expression::StringLiteral
  • Expression::HexLiteral
  • Expression::AddressLiteral

@rkrasiuk rkrasiuk added L-ignore Log: ignore PR in changelog Cmd-forge-fmt Command: forge fmt labels Jun 30, 2022
@gakonst
Copy link
Member

gakonst commented Jun 30, 2022

crazy idea, maybe we can have forge fmt auto check-sum addresses (BIG pain when copy-pasting stuff from etherscan URL etc.) and auto separate decimal fields for large numbers? ie 1000000 -> 1_000_000?

@rkrasiuk
Copy link
Collaborator Author

@gakonst heh, thought of that as well. agree on address auto check-sum 💯 , but i'd rather leave underscores for when we implement config and make it an option there

@gakonst
Copy link
Member

gakonst commented Jun 30, 2022

SGTM - just dumping thoughts

@onbjerg onbjerg added T-feature Type: feature and removed L-ignore Log: ignore PR in changelog labels Jul 3, 2022
rkrasiuk and others added 6 commits July 6, 2022 18:16
* Make FormatBuffer handle strings

The FormatBuffer automatically adds indents after newlines, so it needs
to handle string based newlines and be aware that no indent should be
added. Therefore the FormatBuffer tracks the state of whether or not its in a
string (it also needs to track the state of whether or not its inside of
a comment in order to do this) and only adds indents where necessary.

Signed-off-by: Julian Popescu <hi@julian.dev>
Comment on lines +43 to +44
hex"001122FF";
hex"00112233" hex"44556677";
Copy link
Member

Choose a reason for hiding this comment

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

maybe for follow up, this removes the _

@gakonst gakonst merged commit af2a9f0 into master Jul 6, 2022
@gakonst gakonst deleted the rkrasiuk/fmt-literal-exprs branch July 6, 2022 19:16
Rjected pushed a commit to Rjected/foundry that referenced this pull request Jul 7, 2022
* literal exprs

* remove todo

* clippy

* addr literal & enum loc fix

* Make FormatBuffer handle strings (foundry-rs#2225)

* Make FormatBuffer handle strings

The FormatBuffer automatically adds indents after newlines, so it needs
to handle string based newlines and be aware that no indent should be
added. Therefore the FormatBuffer tracks the state of whether or not its in a
string (it also needs to track the state of whether or not its inside of
a comment in order to do this) and only adds indents where necessary.

Signed-off-by: Julian Popescu <hi@julian.dev>

* added unicode support

Co-authored-by: Julian Popescu <jpopesculian@gmail.com>
Co-authored-by: Julian Popescu <hi@julian.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmd-forge-fmt Command: forge fmt T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants