prettier-plugin-motoko
TypeScript icon, indicating that this package has built-in type declarations

0.8.4 • Public • Published

Motoko Formatter · npm version GitHub license PRs Welcome

A Prettier plugin for the Motoko programming language.


Setup

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

Command-line usage

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 **/*

VS Code support

Customization

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"],
}

Example .prettierrc configuration with default values:

{
    "plugins": ["prettier-plugin-motoko"],
    "bracketSpacing": true,
    "printWidth": 80,
    "semi": true,
    "tabWidth": 2,
    "trailingComma": "es5",
    "useTabs": false
}

Multiple languages

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
        }
    }]
}

Ignoring code

Skip formatting a statement using a prettier-ignore comment:

// prettier-ignore
func ignored<A>(a:A){a};

func formatted<B>(b : B) { b };

Contributing

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.

Readme

Keywords

none

Package Sidebar

Install

npm i prettier-plugin-motoko

Weekly Downloads

128

Version

0.8.4

License

Apache-2.0

Unpacked Size

340 kB

Total Files

111

Last publish

Collaborators

  • rvanasa