crates/lint/docs/multi-contract-file.md
Severity: Info
ID: multi-contract-file
Flags source files that declare more than one top-level contract, interface, or library.
Reports each top-level contract, interface, or library definition (after the first) in a
file that contains more than one such declaration.
Keeping one contract per file improves discoverability (grep, IDE jump-to-file), simplifies
import paths, and avoids unintentional bytecode bloat from artifacts that bundle unrelated
contracts.
// File: Token.sol
contract TokenA { /* ... */ }
contract TokenB { /* ... */ }
// File: TokenA.sol
contract TokenA { /* ... */ }
// File: TokenB.sol
contract TokenB { /* ... */ }
Set multi_contract_file_exceptions under [lint.lint_specific] in foundry.toml to allow
multiple interfaces, libraries, or abstract contracts in one file. Regular contracts cannot be
exempted.
[lint.lint_specific]
multi_contract_file_exceptions = ["interface", "library", "abstract_contract"]