safe-global / safe-smart-account

Safe allows secure management of blockchain assets.
https://safe.global
GNU Lesser General Public License v3.0
1.84k stars 907 forks source link

Imports Ordering for Contracts #731

Closed remedcu closed 1 month ago

remedcu commented 8 months ago

Context / issue

While working on creating Interfaces for Safe, importing order inconsistency was found.

Proposed solution

Using a npm package like: https://github.com/trivago/prettier-plugin-sort-imports with settings mentioned in like: https://github.com/foundry-rs/foundry/issues/3396 (Thanks to @mmv08 for finding it out!)

Alternatives

Doing it manually. It can become a tedious process in the long run though.

Additional context

Initial discussion took place here: https://github.com/safe-global/safe-contracts/pull/722#discussion_r1453148827

mmv08 commented 4 months ago

This turned out to be more complex than I initially anticipated; the prettier plugin I mentioned doesn’t work with solidity out of the box because it’s missing a parser. Therefore I see three possible solutions:

  1. Fork and adjust the plugin to support solidity (I think it’s doable by reusing the existing solidity parser) -> this would imply maintaining the plugin
  2. Use foundry instead of prettier for formatting solidity contracts
  3. Continue without import sorting

I’m personally leaning towards option 2. What do you think?

EDIT: Foundry can only sort imports alphabetically, so it is impossible to use it, leaving 1 and 3 as the only options. Going with 1 will imply adjusting the complexity from 2 to 5/8

mmv08 commented 4 months ago

We decided to close this issue because it's not worth the effort, and no tool exists that can help us achieve the desired outcome out of the box.

remedcu commented 1 month ago

solhint now has import ordering based on the path: https://github.com/protofire/solhint/blob/develop/CHANGELOG.md#503---2024-08-03