prettier-plugin-solidity icon indicating copy to clipboard operation
prettier-plugin-solidity copied to clipboard

Feature Request: Sorted Imports

Open RyanRHall opened this issue 2 years ago • 5 comments

I would love if there was an option to sort imports alphabetically. Liked groups could be segregated with a space (ex the way go fmt works).

RyanRHall avatar Aug 25 '23 20:08 RyanRHall

mmmh not sure as the order of import does impact the bytecode generated and could potentially affect the way the state is stored and the amount of gas it uses on different calls.

doesn't feel right with me even as an option.

@fvictorio any thoughts?

Janther avatar Aug 25 '23 22:08 Janther

@Janther Can you explain to me how import order impacts the bytecode? From my (albeit limited) experimenting, it seems to have no affect. Thanks!

RyanRHall avatar Aug 28 '23 14:08 RyanRHall

I think I was mistaken, I was thinking of the order of inheritance in a contract. Still would like to hear the community's feedback on this one as it does change the parsed AST.

Janther avatar Aug 28 '23 21:08 Janther

Parking this for now, it seems to add some complexity (specially if we add comments for the imports into the mix).

Janther avatar Aug 28 '23 23:08 Janther

I am of the opinion that this kind of thing belongs in a linter (tagging @juanpcapurro, who is maintaining solhint-community).

That being said, not everyone agrees with that point of view. For example, rustfmt does sort imports (and a lot of other things).

fvictorio avatar Aug 29 '23 11:08 fvictorio