Registry / devops / prettier-plugin-motoko

prettier-plugin-motoko

JSON →
library0.13.0jsnpmunverified

A Prettier plugin that adds formatting support for Motoko, the smart contract language of the Internet Computer (ICP). Current stable version is 0.13.0, released under the Apache 2.0 license. It integrates seamlessly into the Prettier ecosystem, allowing Motoko files to be formatted alongside other languages. Key differentiators include Motoko-specific options like motokoOrganizeImports (to group and sort imports by prefix) and motokoRemoveLinesAroundCodeBlocks (to strip extra blank lines), plus prettier-ignore comment support. It requires Prettier v2.7 or v3 as a peer dependency and ships with TypeScript type declarations.

npm install prettier-plugin-motoko
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-MO
P
prettier-plugin-motoko
devopsjavascriptv0.13.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
import motokoPlugin from 'prettier-plugin-motoko'
const motokoPlugin = require('prettier-plugin-motoko')
The package is ESM-only; use import syntax. It provides a default export that configures Prettier.
plugins array
plugins: ['prettier-plugin-motoko']
plugins: ['./node_modules/prettier-plugin-motoko/index.js']
In .prettierrc, use the package name string. Prettier resolves the plugin automatically.
TypeScript types
import type { Options } from 'prettier-plugin-motoko'
const Options = require('prettier-plugin-motoko').Options
Types are exported as a named type; use import type syntax. Available since v0.5.0.

Demonstrates installation, configuration, and usage of the Motoko Prettier plugin via CLI.

// Install: npm install --save-dev prettier prettier-plugin-motoko // Create .prettierrc { "plugins": ["prettier-plugin-motoko"], "motokoOrganizeImports": true } // Format directory: npx prettier --write --plugin=prettier-plugin-motoko **/*.mo // Check formatting: npx prettier --check --plugin=prettier-plugin-motoko **/*.mo
Debug
Known issues
breakingRequires Prettier v2.7 or v3; v2.6 and below are not supported
fix
Upgrade Prettier to ^2.7.0 || ^3.0.0
affects: <2.7.0
gotchaThe plugin must be specified in .prettierrc or via --plugin CLI flag; Prettier does not auto-discover it
fix
Add '"plugins": ["prettier-plugin-motoko"]' to your .prettierrc or use --plugin=prettier-plugin-motoko
affects: >=0.0.0
gotchamotokoOrganizeImports will reorganize imports. Comments inside the import block may be moved or preserved inconsistently.
fix
Review your .mo files after enabling this option; consider disabling for projects with complex import comments.
affects: >=0.10.0
deprecatedThe standalone mo-fmt CLI is separate from this plugin; do not use npm package 'mo-fmt' for Prettier integration
fix
Use 'prettier-plugin-motoko' with Prettier; for a standalone formatter, consider 'mo-fmt' package.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-motoko'
Package not installed or Prettier cannot resolve it.
fix
Run 'npm install --save-dev prettier-plugin-motoko' and check that node_modules contains it.
Error: No parser could be inferred for file: example.mo
Prettier cannot associate .mo files with the Motoko plugin.
fix
Ensure plugins array in .prettierrc includes 'prettier-plugin-motoko' or pass --plugin=prettier-plugin-motoko on CLI.
Error: Cannot find module 'prettier'
Prettier is not installed as a peer dependency.
fix
Install prettier with 'npm install --save-dev prettier'.
Upgrade
Version history
0.13.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency, required to run the plugin
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-motoko — npm install prettier-plugin-motoko · libregistry