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): sort imports #3396

Closed
mds1 opened this issue Sep 28, 2022 · 2 comments · Fixed by #5442
Closed

feat (fmt): sort imports #3396

mds1 opened this issue Sep 28, 2022 · 2 comments · Fixed by #5442
Assignees
Labels
C-forge Command: forge Cmd-forge-fmt Command: forge fmt T-feature Type: feature

Comments

@mds1
Copy link
Collaborator

mds1 commented Sep 28, 2022

Component

Forge

Describe the feature you would like

There's two levels of sorting here:

First, the filepath level. Personally I like to sort imports as forge-std > dependencies > test > script > src, then alphabetically by path within each of those categories. This is similar to the sort order suggested in python's style guide. I'm not sure of conventions in rust or elsewhere, but don't feel too strongly on the exact order here. Maybe we default to sorting imports like rustfmt and let users toggle that off?

Then with named imports. For example, import {foo, bar} from "src/Contract.sol" should become import {bar, foo} from "src/Contract.sol".

Probably can have a single sort-imports config item that covers both sort options.

Additional context

No response

@mds1 mds1 added the T-feature Type: feature label Sep 28, 2022
@rkrasiuk rkrasiuk self-assigned this Sep 28, 2022
@rkrasiuk rkrasiuk added C-forge Command: forge Cmd-forge-fmt Command: forge fmt labels Sep 28, 2022
@sambacha
Copy link
Contributor

Import order can effect build output in some rare instances.

here is a config using prettier that does sort
sambacha/prettier-config-solidity@b37967c

@mds1
Copy link
Collaborator Author

mds1 commented Sep 30, 2022

Import order can effect build output in some rare instances.

Interesting, does it just affect the metadata hash? I'd be surprised if this affects the contract bytecode in some non-trivial way, curious to see more docs/info on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-fmt Command: forge fmt T-feature Type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants