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.
npm install prettier-plugin-rustVerified import paths — ran on the pinned version, not inferred.
Demonstrates formatting Rust code using Prettier's programmatic API with the plugin. Shows parser option 'rust' and plugin path.
Use ES module import or configure Prettier to load the plugin via its plugin system.
Install prettier as a dependency alongside prettier-plugin-rust.
Avoid using those options; they will be ignored or cause errors.
Ensure your .rs files are inside a Cargo project or use Prettier's file detection overrides.
Install the plugin as a devDependency: npm install --save-dev prettier-plugin-rust. Use ES import if in module context.
Add "type": "module" to package.json or use dynamic import(). Alternatively, use Prettier's plugin system via .prettierrc.
Set "parser": "rust" in your Prettier config or use a file extension override: { "overrides": { "files": "*.rs", "options": { "parser": "rust" } } }.