Motoko Indentation Consistency: Should the Prettier Plugin Enforce 2 Spaces?

I want to start a focused discussion about indentation in Motoko formatting tools.

Currently, there is no consistent practice across projects.
Some use 2 spaces, some use 4 spaces.
This happens because the VSCode Motoko extension picks up the editor’s default indentation (often 4 spaces), while the Motoko style guide and base library use 2 spaces.

Another data point: the mo-fmt CLI tool uses prettier-plugin-motoko (also used by the VSCode plugin) internally and always formats with 2 spaces, with no option to choose 4 spaces.

I personally don’t mind whether it’s 2, 4, or 7 spaces, but I think it would be much better if formatting was consistent across the ecosystem.

Should the Prettier plugin enforce 2 spaces by default (in line with the style guide and mo-fmt) so all codebases end up with the same indentation automatically?

I’d like to hear your thoughts so we can hopefully agree on a path forward and avoid this ongoing inconsistency.

Related links:

2 Likes

I agree. Don’t care what but pick one
I’m more of a tabs guy but that’s another conversation lol

4 Likes

Thank you for bringing this up! I opened this PR to change the built-in VS Code formatter to use 2 spaces by default, which seems like a reasonable solution.

It’s already possible to override the default indentation by creating a .prettierrc file and specifying tabWidth (or even useTabs if preferred).

6 Likes

As a quick update, the VS Code extension now uses 2 spaces by default as of v0.18.4. Cheers!

5 Likes