Home

Awesome

<div align="center"> <img alt="Prettier Rust" height="256px" src="https://user-images.githubusercontent.com/109366411/181039409-b66d6a4c-bbc7-4fbb-8a79-d7bb1af87a63.png"> </div> <h1 align="center">Prettier Rust</h1> <div align="center">

GitHub license npm version extension installs GitHub Repo stars Twitter Follow

The massively popular Prettier code formatter, now with Rust support!

Get Started: Install VSCode Extension Prettier - Code formatter (Rust)

</div>

Why Prettier?

What usually happens once people start using Prettier is that they realize how much time and mental energy they actually spend formatting their code. No matter how incomplete or broken the code you're working on is, with the Prettier Editor Extension you can always just press the Format Document key binding and *poof*, the code snaps right into place.

<br> <br> <table align="center"> <tr> <th>> input</th> <th>> formatted</th> </tr> <tr> <td> <!-- prettier-ignore -->
const LEET = 1337
/// My WIP code draft
#![feature(crate_visibility_modifier)]
async crate fn foo(arg) {
  arg.0 *= 3.14 + LEET & 1337
  arg.1(|b, c| -> T &c).await
}
</td> <td> <!-- prettier-ignore -->
const LEET = 1337;
#![feature(crate_visibility_modifier)]
/// My WIP code draft
crate async fn foo(arg) {
    arg.0 *= (3.14 + LEET) & 1337;
    (arg.1)(|b, c| -> T { &c }).await
}
</td> </tr> </table> <div align="center">

Formatting succeeds and fixes 7 syntax errors.

</div> <br>

Configuration

https://prettier.io/docs/en/configuration

<!-- prettier-ignore -->
// .prettierrc.json
{
  "useTabs": false,
  "tabWidth": 4,
  "printWidth": 100,
  "endOfLine": "lf",

  // -- Not supported yet --
  // "trailingComma": "es5",
  // "embeddedLanguageFormatting": "auto",

  // Example override
  "overrides": { "files": ["tests/*.rs"], "options": { "printWidth": 80 } }
}
<details> <summary>See alternative configuration using a TOML file</summary>
# .prettierrc.toml

useTabs = false
tabWidth = 4
printWidth = 100
endOfLine = "lf"

# -- Not supported yet --
# trailingComma = "es5"
# embeddedLanguageFormatting = "auto"

# Example override
overrides = [
  { files = ["tests/*.rs"], options = { printWidth = 80 } }
]
</details>

How to ignore things

How are macros formatted?

Are nightly features supported?

Yes! Prettier Rust formats most nightly features. Support depends on jinx-rust.

<br>

Editor integration

<br>

Project integration

<br>

Q&A