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

fix spacing in generated code #23

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

z80dev
Copy link

@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
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
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.

None yet

2 participants