foundry-rs / foundry-rs/foundry

forge(fmt): Align function/struct parameters

Open
#5,074 3 comments 0 reactions 0 assignees View on GitHub
Cmd-forge-fmt T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
16h 38m
Merged PRs (30d)
511

Description

### Component

Forge

### Describe the feature you would like

Basically I'm envisioning this having 4 rules for functions:
1. Only align items with the same function used, and when there are no line breaks in between them.
2. Left-justify all lines to the character length of the longest item from the previous parameter.
3. Align all params with each other.
4. Break into multiline syntax with a line break above if the alignment causes a line to become too long.

For structs, it would just be rule 2 for all the params in the struct.

Here's some examples of some diffs of me doing this manually:
![Screenshot 2023-05-29 at 4 23 49 PM](https://github.com/foundry-rs/foundry/assets/44272939/05529725-9df9-4e22-b76b-f9592db02133)

![Screenshot 2023-05-29 at 4 25 31 PM](https://github.com/foundry-rs/foundry/assets/44272939/0a14ea2f-bb97-4841-aa51-6f7f49c2064a)

![Screenshot 2023-05-29 at 4 26 51 PM](https://github.com/foundry-rs/foundry/assets/44272939/ade0b5de-b332-4f77-a24f-426ebd47277d)

Multi-param alignment demonstrated below
```solidity
vm.serializeUint(keyLongerLength, 'baseRateConversion', strategy.baseRateConversion());
vm.serializeUint(key, 'borrowSpread', strategy.borrowSpread());
vm.serializeUint(key, 'supplySpread', strategy.supplySpread());
vm.serializeUint(key, 'maxRate', strategy.maxRate());
```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by locating Forge's formatting entry point and the formatter handling Solidity function and struct parameters. Use the four function-alignment rules, the struct rule, and the shown multi-parameter example as behavioral requirements; done means formatting produces the requested alignment without exceeding the line length.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, solidity
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.