{"id":13636077,"url":"https://github.com/jinxdash/prettier-plugin-rust","last_synced_at":"2025-04-05T23:08:22.623Z","repository":{"id":50377518,"uuid":"518097489","full_name":"jinxdash/prettier-plugin-rust","owner":"jinxdash","description":"Prettier Rust is an opinionated code formatter that autocorrects bad syntax.","archived":false,"fork":false,"pushed_at":"2023-05-26T20:03:39.000Z","size":440,"stargazers_count":192,"open_issues_count":12,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T22:07:51.645Z","etag":null,"topics":["developer-tools","formatter","prettier","prettier-plugin","rust","vscode-extension"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jinxdash.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-26T14:34:54.000Z","updated_at":"2025-03-15T21:47:01.000Z","dependencies_parsed_at":"2024-06-18T18:14:03.162Z","dependency_job_id":"0477b50c-107e-4eaf-8415-99a08af8386f","html_url":"https://github.com/jinxdash/prettier-plugin-rust","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"79101b5c99e7946f535715ea0c0de2bd25aa9dd4"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinxdash%2Fprettier-plugin-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinxdash%2Fprettier-plugin-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinxdash%2Fprettier-plugin-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinxdash%2Fprettier-plugin-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinxdash","download_url":"https://codeload.github.com/jinxdash/prettier-plugin-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411234,"owners_count":20934653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["developer-tools","formatter","prettier","prettier-plugin","rust","vscode-extension"],"created_at":"2024-08-02T00:00:56.834Z","updated_at":"2025-04-05T23:08:22.596Z","avatar_url":"https://github.com/jinxdash.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"Prettier Rust\" height=\"256px\" src=\"https://user-images.githubusercontent.com/109366411/181039409-b66d6a4c-bbc7-4fbb-8a79-d7bb1af87a63.png\"\u003e\n\u003c/div\u003e\n\n\u003ch1 align=\"center\"\u003ePrettier Rust\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n![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\u0026style=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)\n\n_The massively popular [Prettier](https://prettier.io/) code formatter, now with [Rust](https://www.rust-lang.org/) support!_\n\n**Get Started:** Install [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=jinxdash.prettier-rust) `Prettier - Code formatter (Rust)`\n\n\u003c/div\u003e\n\n## Why Prettier?\n\n\u003e 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.\n\n\u003cbr\u003e\n\n- **Beautiful, uniform and consistent** — Prettier is strongly opinionated, with no style options.\n- **There when you need it the most** — Prettier can format code that won't compile _(e.g. missing annotations)_\n- **Speed up the day-to-day** — Prettier auto-fixes common syntax errors _(e.g. missing semicolons, blocks, parentheses)_\n\n\u003cbr\u003e\n\n\u003ctable align=\"center\"\u003e\n\u003ctr\u003e \u003cth\u003e\u003e input\u003c/th\u003e \u003cth\u003e\u003e formatted\u003c/th\u003e \u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd\u003e\n\n\u003c!-- prettier-ignore --\u003e\n```rs\nconst LEET = 1337\n/// My WIP code draft\n#![feature(crate_visibility_modifier)]\nasync crate fn foo(arg) {\n  arg.0 *= 3.14 + LEET \u0026 1337\n  arg.1(|b, c| -\u003e T \u0026c).await\n}\n```\n\n  \u003c/td\u003e\n  \u003ctd\u003e\n\n\u003c!-- prettier-ignore --\u003e\n```rs\nconst LEET = 1337;\n#![feature(crate_visibility_modifier)]\n/// My WIP code draft\ncrate async fn foo(arg) {\n    arg.0 *= (3.14 + LEET) \u0026 1337;\n    (arg.1)(|b, c| -\u003e T { \u0026c }).await\n}\n```\n\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\u003cdiv align=\"center\"\u003e\n\n_Formatting succeeds and fixes 7 syntax errors._\n\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n## Configuration\n\nhttps://prettier.io/docs/en/configuration\n\n\u003c!-- prettier-ignore --\u003e\n```json5\n// .prettierrc.json\n{\n  \"useTabs\": false,\n  \"tabWidth\": 4,\n  \"printWidth\": 100,\n  \"endOfLine\": \"lf\",\n\n  // -- Not supported yet --\n  // \"trailingComma\": \"es5\",\n  // \"embeddedLanguageFormatting\": \"auto\",\n\n  // Example override\n  \"overrides\": { \"files\": [\"tests/*.rs\"], \"options\": { \"printWidth\": 80 } }\n}\n```\n\n\u003cdetails\u003e\n    \u003csummary\u003eSee alternative configuration using a TOML file\u003c/summary\u003e\n\n```toml\n# .prettierrc.toml\n\nuseTabs = false\ntabWidth = 4\nprintWidth = 100\nendOfLine = \"lf\"\n\n# -- Not supported yet --\n# trailingComma = \"es5\"\n# embeddedLanguageFormatting = \"auto\"\n\n# Example override\noverrides = [\n  { files = [\"tests/*.rs\"], options = { printWidth = 80 } }\n]\n```\n\n\u003c/details\u003e\n\n### How to ignore things\n\n- Add `// prettier-ignore` or `#[rustfmt::skip]` above it\n- Add `#![rustfmt::skip]` inside blocks or files\n- Create a `.prettierignore` file to glob-match files, like `.gitignore`\n\n### How are macros formatted?\n\n- Curlies `!{}` format like blocks, `![]` and `!()` like comma-separated expressions\n- Formatting inside macro invocations is more conservative, since macros can be token-sensitive\n- Popular/built-in macros with original syntax rules get custom formatting (e.g. `matches!`, `if_chains!`...) _[Not implemented yet]_\n- Macro Declarations are only partially formatted (the transformed part isn't yet, but could be in the future)\n- Macros that can't be formatted are silently ignored\n\n### Are nightly features supported?\n\nYes! Prettier Rust formats most nightly features. Support depends on [`jinx-rust`](https://github.com/jinxdash/jinx-rust).\n\n\u003cbr\u003e\n\n## Editor integration\n\n- ### `Recommended` Extension Standalone\n\n  _Easy install + auto-updates_\n\n  - VSCode | Search and install `Prettier - Code formatter (Rust)` [[direct link]](https://marketplace.visualstudio.com/items?itemName=jinxdash.prettier-rust)\n\n  - _Request your favorite editor:_ [[file an issue]](https://github.com/jinxdash/prettier-plugin-rust/issues/new)\n\n- ### `Alternative` Core Extension Plugin\n\n  _Requires [NodeJS](https://nodejs.dev/download/) + [Prettier Extension](https://prettier.io/docs/en/editors.html)_ (built-in Jetbrains IDEs)\n\n  ```sh\n  npm install --global prettier-plugin-rust prettier\n  ```\n\n  _Restart IDE after installing._  \n  _To update (manual only!!):_ `npm upgrade --global prettier-plugin-rust prettier`  \n  _To check installed version:_ `npm ls -g --depth=0 prettier-plugin-rust prettier`  \n  _To check latest version:_ `npm info prettier-plugin-rust version`\n\n\u003cbr\u003e\n\n## Project integration\n\n- ### Command line\n\n  _Requires [NodeJS](https://nodejs.dev/download/)_\n\n  - Install `prettier` and `prettier-plugin-rust` globally\n\n    ```sh\n    npm install --global prettier-plugin-rust prettier\n    ```\n\n  - Use the [prettier CLI](https://prettier.io/docs/en/cli.html) to format rust files. E.g. run:\n\n    ```sh\n    prettier --write **/*.rs\n    ```\n\n- ### NodeJS package\n\n  _Requires [NodeJS](https://nodejs.dev/download/)_\n\n  - Install `prettier` and `prettier-plugin-rust` in the project\n\n    ```sh\n    npm install --save-dev prettier-plugin-rust prettier\n    ```\n\n  - Link to the plugin's location in your prettier config:\n\n    ```json\n    \"plugins\": [\"./node_modules/prettier-plugin-rust\"]\n    ```\n\n  - Use the [prettier CLI](https://prettier.io/docs/en/cli.html) to format rust files. E.g. run:\n\n    ```sh\n    npx prettier --write **/*.rs\n    ```\n\n  - You can also use the plugin programmatically:\n\n    ```ts\n    import prettier from \"prettier\";\n    import * as rustPlugin from \"prettier-plugin-rust\";\n\n    prettier.format(code, { plugins: [rustPlugin] });\n    ```\n\n- ### Rust crate\n\n  _No crate yet. Above options are available in the meantime._\n\n\u003cbr\u003e\n\n## Q\u0026A\n\n- ### _Why would I use this and not the established `cargo fmt` ?_\n\n  _It's all about the Editor Integration_ — Having the ability to format your code while you work on it really makes for a great developer experience, and autocompletion for Rust's strict syntax is such a massive time save. Once you've tried the extension there really is no coming back.\n\n  All-in-all the difference in code style is minimal, so adopting Prettier Rust won't drastically change your codebase. The real downside is the harsher integration with the Rust ecosystem, but it'll get better eventually.\n\n  Point by point:\n\n  - the extension streamlines your work in the editor\n    - it can format code that won't compile _(e.g. code with missing type annotations)_\n    - it autocorrects syntax errors _(e.g. missing semicolons, blocks, parentheses...)_\n  - it is strongly opinionated with no style options, so code is uniform across projects.\n  - it produces more readable code in some cases (e.g. condition chains, compound expressions, patterns)\n  - it supports everything out-of-the-box (e.g. nightly features, macros)\n  - it consistently prints code in the same way, whereas Rustfmt preserves arbitrary style at places\n  - it can be used for other languages (e.g. markdown, html, typescript, java, python, ruby)\n  - it formats language embeds. So rust code blocks in non-rust files (e.g. markdown), and supported languages in rust doc comments. _[NOTE: the latter is not yet implemented]_\n\n- ### _Why not just add those features to rustfmt instead?_\n\n  Unfortunately Rustfmt cannot implement those features by design.\n\n  Rustfmt parses code with rustc. Rustc is strict and unforgiving as it always assumes code is at its \"final version\", thus every slight deviation from the accepted syntax crashes the parser. There's also that rustc has many lint-like checks within the parser. The intention is to save work for the compiler down the line, unfortunately it also means that rustc sometimes fails to parse syntactically correct code.\n\n  Prettier Rust however is based on [jinx-rust](https://github.com/jinxdash/jinx-rust). Jinx-rust is built specifically for Rust tooling. Hence it's designed to tolerate a wide range of syntax errors, supports missing nodes and sometimes even infers user intent (e.g. Javascript's `!==`)\n\n  Jinx-rust has a little _plaidoyer_ in its readme arguing for Rust Tooling _not_ to use the official rustc parser [here](https://github.com/jinxdash/jinx-rust#why-jinx-rust-and-why-in-typescript).\n\n- ### _When exactly does Prettier Rust change code syntax?_\n\n  The Prettier Rust syntax autocorrection feature is intended to be an adaptation of how Prettier Typescript autocorrects javascript code with missing semicolons.\n\n  You can effectively think of Prettier Rust syntax autocorrection as auto-applying the Rust compiler's suggested syntax fixes automatically (e.g. \"semicolon missing here\", \"parenthesize this\" or \"add a block around that\")\n\n  Otherwise if your codebase compiles, then Prettier Rust is just a formatter like any other. It won't change the syntax of valid rust code. Moreover, it doesn't reorganize imports, split comments or combine attributes.\n\n- ### _This is an \"opinionated formatter\". But it's brand new! How reliable are those opinions?_\n\n  Rest assured, Prettier Rust actually does not take style decisions on its own. Prettier Rust is essentially a 1:1 adaptation of Prettier Typescript, hence the opinions it implements have been battle tested and agreed-upon by [millions and millions of users](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) already.\n","funding_links":[],"categories":["Development tools","开发工具 Development tools"],"sub_categories":["Formatters","格式器 Formatters"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinxdash%2Fprettier-plugin-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinxdash%2Fprettier-plugin-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinxdash%2Fprettier-plugin-rust/lists"}