{"id":21709,"library":"prettier-plugin-rust","title":"Prettier Plugin for Rust","description":"A prettier plugin for formatting Rust code, version 0.1.9. It provides Prettier-based formatting for Rust files, supporting both code that compiles and code that doesn't (e.g., missing annotations). It fixes common syntax errors like missing semicolons, blocks, and parentheses. The plugin also includes a VSCode extension. It uses the jinx-rust parser. Key differentiators vs rustfmt: ability to format incomplete code, auto-fix common errors, and integration with Prettier ecosystem. Released monthly or so; actively maintained.","status":"active","version":"0.1.9","language":"javascript","source_language":"en","source_url":"https://github.com/jinxdash/prettier-plugin-rust","tags":["javascript","prettier","formatter","rust","typescript"],"install":[{"cmd":"npm install prettier-plugin-rust","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-rust","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-rust","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin runs on top of Prettier","package":"prettier","optional":true}],"imports":[{"note":"Package is ESM-only since v0.1.5; CommonJS require will fail.","wrong":"const prettierPluginRust = require('prettier-plugin-rust')","symbol":"default","correct":"import prettierPluginRust from 'prettier-plugin-rust'"},{"note":"The plugin must be loaded via Prettier's plugin system, not imported in code directly.","wrong":"Importing as a regular module and passing incorrectly","symbol":"prettier-plugin-rust","correct":"Add to .prettierrc: { \"plugins\": [\"prettier-plugin-rust\"] }"}],"quickstart":{"code":"const prettier = require('prettier');\nconst code = `const LEET = 1337\\nfn main() {\\n  let x = 1 + 2\\n}`;\nasync function formatRust() {\n  const result = await prettier.format(code, {\n    parser: 'rust',\n    plugins: ['./node_modules/prettier-plugin-rust'],\n    tabWidth: 4,\n    printWidth: 100,\n  });\n  console.log(result);\n}\nformatRust().catch(console.error);","lang":"javascript","description":"Demonstrates formatting Rust code using Prettier's programmatic API with the plugin. Shows parser option 'rust' and plugin path."},"warnings":[{"fix":"Use ES module import or configure Prettier to load the plugin via its plugin system.","message":"Plugin fails if imported via CommonJS require() due to ESM-only exports.","severity":"breaking","affected_versions":">=0.1.5"},{"fix":"Install prettier as a dependency alongside prettier-plugin-rust.","message":"The plugin requires Prettier to be installed as a peer dependency; it does not work standalone.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Avoid using those options; they will be ignored or cause errors.","message":"Certain Prettier options like trailingComma and embeddedLanguageFormatting are not supported yet.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure your .rs files are inside a Cargo project or use Prettier's file detection overrides.","message":"Cargo workspace layout may not be detected; files outside a recognized Cargo project may not be formatted correctly.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install the plugin as a devDependency: npm install --save-dev prettier-plugin-rust. Use ES import if in module context.","cause":"Module not installed or not resolved correctly in CommonJS environment.","error":"Error: Cannot find module 'prettier-plugin-rust'"},{"fix":"Add \"type\": \"module\" to package.json or use dynamic import(). Alternatively, use Prettier's plugin system via .prettierrc.","cause":"The plugin is ESM-only since v0.1.5, but user's Node.js project is not configured as module.","error":"Cannot use import statement outside a module"},{"fix":"Set \"parser\": \"rust\" in your Prettier config or use a file extension override: { \"overrides\": { \"files\": \"*.rs\", \"options\": { \"parser\": \"rust\" } } }.","cause":"Prettier may not automatically select the Rust parser; need to specify explicitly.","error":"Error: No parser could be inferred for file: src/main.rs"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}