This repository contains shared linting and formatting rules for Solidity projects.
# Install with peer packages
yarn add --dev solhint solhint-graph-config
# For projects on this monorepo
yarn add --dev solhint solhint-graph-config@workspace:^x.y.z
Run solhint
with node_modules/solhint-graph-config/index.js
as the configuration file. We suggest creating an npm script to make it easier to run:
{
"scripts": {
"lint": "solhint --fix --noPrompt contracts/**/*.sol --config node_modules/solhint-graph-config/index.js"
}
}
# Install with peer packages
yarn add --dev solhint-graph-config prettier prettier-plugin-solidity
# For projects on this monorepo
yarn add --dev solhint-graph-config@workspace:^x.y.z prettier prettier-plugin-solidity
Create a configuration file for prettier at prettier.config.js
:
const prettierGraphConfig = require('solhint-graph-config/prettier')
module.exports = prettierGraphConfig
Running prettier
will automatically pick up the configuration file. We suggest creating an npm script to make it easier to run:
{
"scripts": {
"format": "prettier --write 'contracts/**/*.sol'"
}
}
This package uses the following tools:
- solhint as the base linting tool
- prettier as the base formatting tool
- prettier-plugin-solidity to format Solidity code
If you are using VSCode you can install the Solidity extension by Nomic Foundation. Unfortunately there is currently no way of getting real-time linting output from solhint, but this extension will provide formatting support using our prettier config and will also provide inline code validation using solc compiler output.
For formatting, the following settings should be added to your settings.json
file:
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
},
Additionally you can configure the Format document
keyboard shortcut to run prettier --write
on demand.