Skip to content

Commit

Permalink
doc(refactor): Improve documentation on the Move prettier plugin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sceat committed Nov 23, 2024
1 parent 252c332 commit 56d5b35
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions external-crates/move/tooling/prettier-move/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,54 @@ using Prettier's VSCode
[extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode). When the
plugin is complete, we will make it available directly from Move's VSCode extension.

## Installation
## Usage (with Npm)

The plugin can be installed via npm:
1. To use the plugin, you can install it as a development dependency in your Move package:

```
npm i @mysten/prettier-plugin-move
> This will install both the prettier formatter and the plugin in the `./node_modules` directory.
```sh
npm install -D prettier @mysten/prettier-plugin-move
```

## Usage
1. Create a `.prettierrc` file containing the following configuration:

Go to the root directory of the Move package whose files you'd like to format (i.e., the directory
containing the Move.toml manifest file for this package) and run the following command:
```json
{
"plugins": ["@mysten/prettier-plugin-move"]
}
```

3. Add a script in your `package.json` file to format Move files:

```bash
npm install [email protected] "$SUI"/external-crates/move/crates/move-analyzer/prettier-plugin
```json
"scripts": {
"prettier": "prettier --write ."
}
```

This will install both the prettier formatter and the plugin in the `./node_modules` directory.
Now you can format all Move files in your package by running:

# Command-line Usage
```sh
npm run prettier
```

## Usage (with Npx)

You can format Move files in the package where you completed the installation [step](#installation) by running the
following command:
This will require having the prettier-move plugin built (`tsc`) locally in the SUI repository.

```bash
./node_modules/.bin/prettier --plugin=prettier-plugin-move "$PATH_TO_MOVE_FILE"
```sh
npx --yes [email protected] --plugin "$SUI/external-crates/move/tooling/prettier-move/out/index.js" --write "path/to/move/folder/**/*.move"
```

# VSCode integration

In order to use the plugin in VSCode you first need to install Prettier's VSCode
[extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
In order to use the plugin in VSCode you first need to install

Then, in the root directory of the package where you completed the installation [step](#installation) you need to place the `.prettierrc` file containing the following configuration:

```
{
"plugins": [
"prettier-plugin-move"
]
}
```
- Prettier's VSCode [extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
- Move's formatter [extension](https://marketplace.visualstudio.com/items?itemName=mysten.prettier-move).

After completing these steps, if you open the root directory of the package where you completed the
installation [step](#installation) and choose any of the Move source files in this package, you will
be able to format them by choosing `Format Code` command from VSCode's command palette.
After completing these steps, you will be able to format move files by choosing `Format Code` command from VSCode's command palette.

## Contribute

Expand Down

0 comments on commit 56d5b35

Please sign in to comment.