Skip to main content

mops format

Format Motoko source files

mops format

Filter files by name

mops format [filter]

Alias mops fmt

Uses Prettier with Motoko plugin.

Configuration

Add .prettierrc file to the root of the project.

{
"overrides": [{
"files": "*.mo",
"options": {
# your custom options...
"useTabs": true
}
}]
}

Supported options:

OptionTypeDefaultDescription
useTabsbooleanfalseUse tabs instead of spaces for indentation
tabWidthnumber2Number of spaces per indentation level (only if useTabs is false)
printWidthnumber80Maximum line length before wrapping
semibooleantrueAdd semicolons at the end of statements
bracketSpacingbooleantrueAdd spaces between brackets in object literals
trailingComma"all" or "none""all"Add trailing commas wherever possible

Options

--check

Check if files are formatted correctly without modifying them.

mops format --check

Examples

Format all Motoko files in the project

mops format

Filter files by directory

mops format backend/main/
# will format all files in the `backend/main` directory.

Filter files by name

mops format DownloadLog
# will format files that match `**/*DownloadLog*.mo` pattern.

Check if files are formatted correctly without modifying them

mops format --check