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:
npm install --save-dev prettier prettier-plugin-motoko
Format your Motoko files using the Prettier CLI:
npx prettier --write --plugin=prettier-plugin-motoko **/*.mo
Check if your Motoko files are correctly formatted:
npx prettier --check --plugin=prettier-plugin-motoko **/*.mo
Alternatively, check out mo-fmt for a standalone Motoko formatter CLI:
mo-fmt **/*
mo-fmt -c **/*
Configure the formatter by creating a .prettierrc file in your project directory (full documentation).
Add the following line to your config file:
{
"plugins": ["prettier-plugin-motoko"],
}
.prettierrc configuration with default values:{
"plugins": ["prettier-plugin-motoko"],
"bracketSpacing": true,
"printWidth": 80,
"semi": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
motokoOrganizeImports (default: false)Automatically organize and sort import statements. When enabled, imports are:
ic:, canister:, mo:, and relative paths)Example:
// Before formatting
import Text "mo:base/Text";
import Utils "./utils";
import Core "canister:core";
import Array "mo:base/Array";
// After formatting with motokoOrganizeImports: true
import Core "canister:core";
import Array "mo:base/Array";
import Text "mo:base/Text";
import Utils "./utils";
To enable this option, add it to your .prettierrc:
{
"plugins": ["prettier-plugin-motoko"],
"motokoOrganizeImports": true
}
motokoRemoveLinesAroundCodeBlocks (default: false)Remove extra blank lines at the beginning and end of code blocks.
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:
{
"overrides": [{
"files": "*.mo",
"options": {
"bracketSpacing": true
}
}]
}
Skip formatting a statement using a prettier-ignore comment:
// prettier-ignore
func ignored<A>(a:A){a};
func formatted<B>(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.
TypeScript
78.0%
JavaScript
19.3%
CSS
1.4%
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:
npm install --save-dev prettier prettier-plugin-motoko
Format your Motoko files using the Prettier CLI:
npx prettier --write --plugin=prettier-plugin-motoko **/*.mo
Check if your Motoko files are correctly formatted:
npx prettier --check --plugin=prettier-plugin-motoko **/*.mo
Alternatively, check out mo-fmt for a standalone Motoko formatter CLI:
mo-fmt **/*
mo-fmt -c **/*
Configure the formatter by creating a .prettierrc file in your project directory (full documentation).
Add the following line to your config file:
{
"plugins": ["prettier-plugin-motoko"],
}
.prettierrc configuration with default values:{
"plugins": ["prettier-plugin-motoko"],
"bracketSpacing": true,
"printWidth": 80,
"semi": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
motokoOrganizeImports (default: false)Automatically organize and sort import statements. When enabled, imports are:
ic:, canister:, mo:, and relative paths)Example:
// Before formatting
import Text "mo:base/Text";
import Utils "./utils";
import Core "canister:core";
import Array "mo:base/Array";
// After formatting with motokoOrganizeImports: true
import Core "canister:core";
import Array "mo:base/Array";
import Text "mo:base/Text";
import Utils "./utils";
To enable this option, add it to your .prettierrc:
{
"plugins": ["prettier-plugin-motoko"],
"motokoOrganizeImports": true
}
motokoRemoveLinesAroundCodeBlocks (default: false)Remove extra blank lines at the beginning and end of code blocks.
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:
{
"overrides": [{
"files": "*.mo",
"options": {
"bracketSpacing": true
}
}]
}
Skip formatting a statement using a prettier-ignore comment:
// prettier-ignore
func ignored<A>(a:A){a};
func formatted<B>(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.
TypeScript
78.0%
JavaScript
19.3%
CSS
1.4%