jinxdash / prettier-plugin-rust

Prettier Rust is an opinionated code formatter that autocorrects bad syntax.
MIT License
178 stars 7 forks source link
developer-tools formatter prettier prettier-plugin rust vscode-extension
Prettier Rust

Prettier Rust

![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg) [![npm version](https://img.shields.io/npm/v/prettier-plugin-rust.svg?style=flat)](https://www.npmjs.com/package/prettier-plugin-rust) [![extension installs](https://img.shields.io/visual-studio-marketplace/i/jinxdash.prettier-rust?logo=visualstudiocode&style=social)](https://marketplace.visualstudio.com/items?itemName=jinxdash.prettier-rust) ![GitHub Repo stars](https://img.shields.io/github/stars/jinxdash/prettier-plugin-rust?style=social) [![Twitter Follow](https://img.shields.io/twitter/follow/jinxdash?style=social)](https://twitter.com/jinxdash) _The massively popular [Prettier](https://prettier.io/) code formatter, now with [Rust](https://www.rust-lang.org/) support!_ **Get Started:** Install [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=jinxdash.prettier-rust) `Prettier - Code formatter (Rust)`

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.



> input > formatted
```rs 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 } ``` ```rs 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 } ```
_Formatting succeeds and fixes 7 syntax errors._


Configuration

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

// .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 } }
}
See alternative configuration using a TOML file ```toml # .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 } } ] ```

How to ignore things

How are macros formatted?

Are nightly features supported?

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


Editor integration


Project integration


Q&A