Registry / devops / prettier-plugin-rust

prettier-plugin-rust

JSON →
library0.1.9jsnpmunverified

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-rust
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-RU
P
prettier-plugin-rust
devopsjavascriptv0.1.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import prettierPluginRust from 'prettier-plugin-rust'
const prettierPluginRust = require('prettier-plugin-rust')
Package is ESM-only since v0.1.5; CommonJS require will fail.
prettier-plugin-rust
Add to .prettierrc: { "plugins": ["prettier-plugin-rust"] }
Importing as a regular module and passing incorrectly
The plugin must be loaded via Prettier's plugin system, not imported in code directly.

Demonstrates formatting Rust code using Prettier's programmatic API with the plugin. Shows parser option 'rust' and plugin path.

const prettier = require('prettier'); const code = `const LEET = 1337\nfn main() {\n let x = 1 + 2\n}`; async function formatRust() { const result = await prettier.format(code, { parser: 'rust', plugins: ['./node_modules/prettier-plugin-rust'], tabWidth: 4, printWidth: 100, }); console.log(result); } formatRust().catch(console.error);
Debug
Known issues
breakingPlugin fails if imported via CommonJS require() due to ESM-only exports.
fix
Use ES module import or configure Prettier to load the plugin via its plugin system.
affects: >=0.1.5
gotchaThe plugin requires Prettier to be installed as a peer dependency; it does not work standalone.
fix
Install prettier as a dependency alongside prettier-plugin-rust.
affects: >=0.0.0
deprecatedCertain Prettier options like trailingComma and embeddedLanguageFormatting are not supported yet.
fix
Avoid using those options; they will be ignored or cause errors.
affects: >=0.0.0
gotchaCargo workspace layout may not be detected; files outside a recognized Cargo project may not be formatted correctly.
fix
Ensure your .rs files are inside a Cargo project or use Prettier's file detection overrides.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'prettier-plugin-rust'
Module not installed or not resolved correctly in CommonJS environment.
fix
Install the plugin as a devDependency: npm install --save-dev prettier-plugin-rust. Use ES import if in module context.
Cannot use import statement outside a module
The plugin is ESM-only since v0.1.5, but user's Node.js project is not configured as module.
fix
Add "type": "module" to package.json or use dynamic import(). Alternatively, use Prettier's plugin system via .prettierrc.
Error: No parser could be inferred for file: src/main.rs
Prettier may not automatically select the Rust parser; need to specify explicitly.
fix
Set "parser": "rust" in your Prettier config or use a file extension override: { "overrides": { "files": "*.rs", "options": { "parser": "rust" } } }.
Upgrade
Version history
0.1.9latest on npm
Audit
Dependencies
prettieroptionalPeer dependency; plugin runs on top of Prettier
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-rust — npm install prettier-plugin-rust · libregistry