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

EVM Engineering: contract import style enforcement checks #13057

Open
smartcontracts opened this issue Nov 24, 2024 · 0 comments
Open

EVM Engineering: contract import style enforcement checks #13057

smartcontracts opened this issue Nov 24, 2024 · 0 comments

Comments

@smartcontracts
Copy link
Contributor

Opened a PR here that cleans up imports into our standard style where contracts, libraries, and interfaces are sorted nicely. It's useful to be able to quickly understand what's being imported but there's no automatic enforcement on this style. We don't like having styles that aren't enforced automatically!

Using forge fmt with the sort_imports option doesn't really work here because that option sorts alphabetically and not by import type which is generally way more useful when understanding what's being used in the contract.

A good tool here would live inside of scripts/checks. We need to be careful about how to implement this because the logic isn't immediately obvious for edge cases like a contract and an interface being imported from the same place. My recommendation for now is that if multiple things are imported from the same file then we use the type of the very first import to determine how to classify that import. It usually works well enough.

Import groups are:

  • Contracts (whenever a contract is imported)
  • Libraries (whenever a library is imported)
    • Errors count as libraries
  • Interfaces (whenever an interface is imported)
  • Scripts (whenever you import from the scripts folder)
  • Testing (whenever you import from the testing folder)

Scripts and Testing takes precedent over the rest. E.g., anything in the scripts folder should be under Scripts regardless of whether it's a contract, library, or interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant