solhint-plugin-prettier
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript
Solhint plugin that integrates Prettier formatting checks for Solidity files. Version 0.1.0 released as a stable package. It requires solhint-community, prettier >=3.0.0, and prettier-plugin-solidity >=1.0.0 as peer dependencies. The plugin reports each formatting difference as an individual lint issue, enabling consistent code style enforcement in Solidity projects. Unlike using Prettier directly in CI, this plugin runs formatting checks as part of the Solhint linting workflow, making it easy to integrate with existing lint configurations and reporting tools.
Common errors
error Error: Plugin prettier not found ↓
cause Plugin not registered in .solhint.json or not installed.
fix
Ensure solhint-plugin-prettier is installed and add 'plugins': ['prettier'] to .solhint.json.
error Error: Cannot find module 'prettier-plugin-solidity' ↓
cause Missing peer dependency.
fix
npm install --save-dev prettier-plugin-solidity
error Rule prettier/prettier is not configured ↓
cause Rule name mismatch or missing from rules object.
fix
Add 'prettier/prettier': 'error' to rules in .solhint.json.
Warnings
gotcha Plugin only works with solhint-community (not the original Solhint package). ↓
fix Use 'solhint-community' instead of 'solhint' in your npm install and config.
gotcha Requires Prettier v3 and prettier-plugin-solidity v1. Older versions are incompatible. ↓
fix Ensure prettier@^3.0.0 and prettier-plugin-solidity@^1.0.0 are installed.
deprecated The rule always reports formatting differences as errors; 'warning' is not supported. ↓
fix Use 'severity: error' only; 'warning' will be treated as error by Solhint.
Install
npm install solhint-plugin-prettier yarn add solhint-plugin-prettier pnpm add solhint-plugin-prettier Imports
- default
plugin is loaded via Solhint config (JSON) not JS import - Rule wrong
Requiring the module directly in JScorrectSet rule in .solhint.json: 'prettier/prettier': 'error' - Configuration wrong
Setting rule without registering plugincorrectAdd 'plugins': ['prettier'] to .solhint.json
Quickstart
// Install dependencies
npm install --save-dev solhint-community solhint-plugin-prettier prettier prettier-plugin-solidity
// Create .solhint.json
{
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
}
// Create .prettierrc (optional but recommended)
{
"plugins": ["prettier-plugin-solidity"],
"tabWidth": 4,
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse"
}
}
]
}
// Run solhint
npx solhint 'contracts/**/*.sol'