Formatting Move Contracts
movefmt
is a formatter tool that makes Move code much easier to write, read, and maintain — greatly improving the development experience on Aptos.
Installation
Section titled “Installation”movefmt
is integrated into the Aptos CLI. To begin using it, first install it using the CLI update command.
# Install movefmt for first time usageaptos update movefmt
To install a specific version of movefmt
:
# Install movefmt with the target <VERSION>aptos update movefmt --target-version <VERSION>
The latest release of movefmt
can be found here.
Format your code
Section titled “Format your code”Similar to compilation and testing, you can use the following command to format the Move package:
# Format the Move packageaptos move fmt
Different ways of emitting the formatting result is supported:
# Format and overwrite all the target move files in the package.# This is the default behavior if `--emit-mode` is not explicitly specifiedaptos move fmt --emit-mode=overwrite
# Print the formatting result to terminalaptos move fmt --emit-mode=std-out
# Print the formatting result to new files with the suffix `.fmt.out` in the same directoryaptos move fmt --emit-mode=new-file
# Print the difference between before and after formattingaptos move fmt --emit-mode=diff
movefmt
also provides different options to configure how the code will be formatted.
Here is the default configuration:
max_width = 90 # each line can have at most 90 charactersindent_size = 4 # the indent is 4 spacestab_spaces = 4 # each tab is identical to 4 spaceshard_tabs = false # when a tab is inserted, it will be automatically replaced by 4 spaces
To override the default option, users can either specify a configuration file movefmt.toml
and put it in Move package directory or manually specify it in the command line:
# When formatting the code, set `max_width` to 80 and `indent_size` to 2aptos move fmt --config max_width=80,indent_size=2
Feedback
Section titled “Feedback”Aptos Labs remains committed to improving the developer experience for builders using Move on Aptos. If you’re interested in shaping the style guidelines for Move, we would love to hear your comments and feedback here.