Linting & Formatting
Relevant source files
The following files were used as context for generating this wiki page:
The Canon Guard project employs a rigorous linting and formatting strategy to maintain high code quality and consistency across its Solidity smart contracts and supporting TypeScript/JavaScript infrastructure. The system leverages industry-standard tools like Foundry's built-in formatter, Solhint for static analysis, and specialized tools like Bulloak for test structure validation.
These processes are integrated into the development workflow via NPM scripts and automated git hooks, ensuring that all contributions adhere to the project's technical standards before being committed or deployed.
Sources: CLAUDE.md:46-51, package.json:23-27
Core Tooling and Configuration
The project utilizes a multi-layered approach to code quality, targeting different file types and stages of the development lifecycle.
Solidity Formatting (Forge FMT)
The primary tool for Solidity code style is forge fmt. The configuration is defined in the project's root configuration file, specifying strict rules for layout and syntax.
| Option | Value | Description |
|---|---|---|
line_length | 120 | Maximum characters per line |
tab_width | 2 | Number of spaces per indentation level |
bracket_spacing | false | Spaces inside brackets |
int_types | 'long' | Explicit integer type naming (e.g., uint256 vs uint) |
quote_style | 'single' | Preference for single quotes in strings |
number_underscore | 'thousands' | Underscore placement in large numbers |
sort_imports | true | Automatic alphabetical sorting of import statements |
Sources: foundry.toml:1-10, package.json:24-25
Static Analysis (Solhint)
Solhint is used to enforce security patterns and best practices within Solidity files located in src/, script/, and test/ directories. It is configured to run both as a check and an automated fix tool.
Sources: package.json:26, CLAUDE.md:49
Specialized Linting
- Bulloak: Validates
.treefiles withintest/unit/to ensure invariant and unit test specifications follow the "Branching Tree" logic. - Lintspec: A Rust-based dependency used for specialized specification linting of source files.
- Sort-package-json: Ensures the
package.jsonfile maintains a consistent key order. - Commitlint: Enforces the Conventional Commits specification for all git commit messages.
Sources: package.json:23, CLAUDE.md:50, commitlint.config.js:1, README.md:12
Workflow Integration
Linting and formatting are triggered through various entry points to ensure compliance throughout the development cycle.
Manual Commands
Developers can execute quality checks and fixes using the following Yarn scripts:
| Command | Action |
|---|---|
yarn lint:check | Runs forge fmt --check and solhint to identify violations without modifying files. |
yarn lint:fix | Automatically formats files using forge fmt, applies Solhint fixes, and sorts package.json. |
yarn lint:sol | Specifically runs Solhint on all Solidity contract, script, and test files. |
yarn lint:bulloak | Validates the integrity of test specification tree files. |
Sources: package.json:23-26, CLAUDE.md:47-50
Automated Hooks (Husky & lint-staged)
The project uses husky to manage git hooks and lint-staged to run specific linters only on files that are being committed. This ensures that no malformed code enters the version control system.
The diagram shows the automated workflow when a developer attempts to commit code.
Sources: package.json:28-36, package.json:38-44
Commit Message Standards
The project enforces the Conventional Commits standard. This is managed via @commitlint/cli and a dedicated configuration file that extends the conventional ruleset. This ensures that the repository history remains readable and compatible with automated changelog generation tools.
Sources: commitlint.config.js:1, package.json:49-50
Summary
The Canon Guard project's linting and formatting system is a comprehensive suite designed to maintain a clean, readable, and secure codebase. By combining the speed of Foundry's native formatter with the deep analysis of Solhint and the structural validation of Bulloak, the project ensures that code remains high-quality from the initial draft through to deployment. Automated enforcement via Husky and lint-staged guarantees that these standards are consistently met by all contributors.