hardhat-prettier
raw JSON → 0.0.1 verified Sat Apr 25 auth: no javascript
Hardhat plugin integrating Prettier Solidity for automatic code formatting and style checking. Current stable version 0.0.1 (pre-release) with no regular release cadence — it's experimental. Key differentiators: adds a format task and overrides the check task for Solidity files, leveraging prettier-plugin-solidity's Solidity-specific formatting rules. Minimal configuration via .prettierrc. Requires Hardhat ^2.0.0, Prettier ^2.1.0, and prettier-plugin-solidity 1.0.0-beta.1. Alternatives like solhint focus on linting; this plugin focuses solely on formatting. Active development on GitHub by a single maintainer.
Common errors
error Error: Cannot find module 'hardhat-prettier' ↓
cause Plugin not installed or missing from dependencies
fix
Run: npm install hardhat-prettier
error Error HH12: Trying to use a non-existent hardhat task: format ↓
cause Plugin not imported in hardhat config
fix
Add require('hardhat-prettier') or import 'hardhat-prettier' to your hardhat.config.js/ts
error Cannot find module 'prettier-plugin-solidity' ↓
cause Missing peer dependency
fix
Install peer: npm install prettier-plugin-solidity
Warnings
deprecated prettier-plugin-solidity version pinned to 1.0.0-beta.1 — not semver-stable and may have breaking changes ↓
fix Monitor the package for updates; consider using a more recent version of prettier-plugin-solidity if compatible
gotcha Plugin overrides the 'check' task globally — affects all Hardhat check behavior ↓
fix Be aware that 'npx hardhat check' will now also check Solidity formatting; use 'npx hardhat format' to fix issues
gotcha No custom task configuration — uses .prettierrc defaults only ↓
fix Create a .prettierrc file for any customization; cannot pass options via hardhat.config
breaking Requires Hardhat ^2.0.0 — incompatible with Hardhat v1 ↓
fix Upgrade Hardhat to v2 or later
Install
npm install hardhat-prettier yarn add hardhat-prettier pnpm add hardhat-prettier Imports
- hardhat-prettier (plugin) wrong
import { hardhatPrettier } from 'hardhat-prettier'correctimport 'hardhat-prettier' - format task wrong
npx hardhat prettiercorrectnpx hardhat format - check task (overridden) wrong
npx hardhat check:formatcorrectnpx hardhat check
Quickstart
// Install dependencies
// npm install hardhat-prettier prettier prettier-plugin-solidity
// hardhat.config.js
require('hardhat-prettier');
// hardhat.config.ts (TypeScript)
import 'hardhat-prettier';
// .prettierrc (optional, use default settings)
{
"plugins": ["prettier-plugin-solidity"],
"singleQuote": true,
"printWidth": 120
}
// Format your Solidity files
// npx hardhat format
// Check formatting without overwriting (via check task)
// npx hardhat check