Skip to content

fix spacing in generated code#23

Open
z80dev wants to merge 6 commits intosolana-developers:mainfrom
z80dev:format-annotations-fix
Open

fix spacing in generated code#23
z80dev wants to merge 6 commits intosolana-developers:mainfrom
z80dev:format-annotations-fix

Conversation

@z80dev
Copy link
Copy Markdown

@z80dev z80dev commented Nov 27, 2024

tldr: rustfmt doesn't handle stuff inside annotations well so we manually patch some spacing issues, mainly turning account stuff like this:

# [account (init , space = std :: mem :: size_of :: < dot :: program :: Calculator > () + 8 , payer = owner , seeds = ["Calculator" . as_bytes () . as_ref () , owner . key () . as_ref ()] , bump)]

into

#[account(init, space = std::mem::size_of::<dot::program::Calculator>() + 8, payer = owner, seeds = ["Calculator".as_bytes().as_ref(), owner.key().as_ref()], bump)]

Also, convert /// CHECK comments back to that format

Overall goal is to make the generated source easier to examine and more familiar by sticking to what Anchor usually looks like

tldr: rustfmt doesn't handle stuff inside annotations well
so we manually patch some spacing issues, mainly turning account stuff
like this:

```rust
```

into

```rust
```
Copy link
Copy Markdown
Collaborator

@mcintyre94 mcintyre94 left a comment

Choose a reason for hiding this comment

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

Thanks for this! I'm a bit hesitant about adding our own formatting stuff instead of just throwing it to rustfmt. Is rustfmt not formatting the current output sensibly?

@z80dev
Copy link
Copy Markdown
Author

z80dev commented Dec 8, 2024

Thanks for this! I'm a bit hesitant about adding our own formatting stuff instead of just throwing it to rustfmt. Is rustfmt not formatting the current output sensibly?

unfortunately not. what rustfmt gets is a stream of tokens which lack whitespace info, and rusfmt produces really ugly output in annotations specifically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants