A code formatter for the Motoko smart contract language.
npm install prettier-plugin-motoko> ### A Prettier plugin for the Motoko programming language.
---
After making sure Node.js is installed on your local machine, run the following command in your Motoko project directory:
``sh`
npm install --save-dev prettier prettier-plugin-motoko
Format your Motoko files using the Prettier CLI:
`sh`
npx prettier --write --plugin=prettier-plugin-motoko */.mo
Check if your Motoko files are correctly formatted:
`sh`
npx prettier --check --plugin=prettier-plugin-motoko */.mo
Alternatively, check out mo-fmt for a standalone Motoko formatter CLI:
``
mo-fmt */
mo-fmt -c */
- Works out of the box with the Motoko extension.
- Compatible with the the Prettier extension.
Configure the formatter by creating a .prettierrc file in your project directory (full documentation).
Add the following line to your config file:
`json`
{
"plugins": ["prettier-plugin-motoko"],
}
`json`
{
"plugins": ["prettier-plugin-motoko"],
"bracketSpacing": true,
"printWidth": 80,
"semi": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
Prettier will apply the same configuration to Motoko, JavaScript, CSS, HTML, and any other supported languages.
You can specifically configure Motoko files using a configuration override in your .prettierrc file:
`json`
{
"overrides": [{
"files": "*.mo",
"options": {
"bracketSpacing": true
}
}]
}
Skip formatting a statement using a prettier-ignore comment:
`motoko
// prettier-ignore
func ignored(a:A){a};
func formatted(b : B) { b };
``
Feel free to submit a GitHub issue to report a bug or suggest a feature.
If you're interested in becoming an open-source contributor, be sure to check out the open issues in case anything catches your eye.