Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
prettier-plugin-rust
Advanced tools
The massively popular Prettier code formatter, now with Rust support!
Get Started: Install VSCode Extension Prettier - Code formatter (Rust)
What usually happens once people start using Prettier is that they realize how much time and mental energy they actually spend formatting their code. With Prettier editor integration, you can just press the
Format Document
key binding and poof, the code is formatted. This is an eye-opening experience if anything.
> input | > formatted |
---|---|
|
|
Formatting succeeds and fixes 7 syntax errors.
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 } }
}
# .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 } }
]
// prettier-ignore
or #[rustfmt::skip]
above it#![rustfmt::skip]
inside blocks or files.prettierignore
file to glob-match files, like .gitignore
!{}
format like blocks, ![]
and !()
like comma-separated expressionsmatches!
, if_chains!
...)Yes! Prettier Rust formats most nightly features. Support depends on jinx-rust
.
Recommended
Extension StandaloneEasy install + auto-updates
VSCode | Search and install Prettier - Code formatter (Rust)
[direct link]
Request your favorite editor: [file an issue]
Alternative
Core Extension PluginRequires NodeJS + Prettier Extension (built-in Jetbrains IDEs)
npm install --global prettier-plugin-rust prettier
Restart IDE after installing.
To update (manual only!!): npm upgrade --global prettier-plugin-rust prettier
To check installed version: npm ls -g --depth=0 prettier-plugin-rust prettier
To check latest version: npm info prettier-plugin-rust version
Requires NodeJS
Install prettier
and prettier-plugin-rust
globally
npm install --global prettier-plugin-rust prettier
Use the prettier CLI to format rust files. E.g. run:
prettier --write **/*.rs
Requires NodeJS
Install prettier
and prettier-plugin-rust
in the project
npm install --save-dev prettier-plugin-rust prettier
Link to the plugin's location in your prettier config:
"plugins": ["./node_modules/prettier-plugin-rust"]
Use the prettier CLI to format rust files. E.g. run:
npx prettier --write **/*.rs
No crate yet. Above options are available in the meantime.
cargo fmt
?It mostly comes down to the Editor Integration. — With Prettier Rust, you have the ability to hit the Format Document
keybind on incomplete code and everything fits right into place. Again reiterating on what was said in the introduction, but this is actually life-changing. Just try it out, 1-click install the extension, write a few lines and hit the keybind.
There's only little difference in terms of how code is printed, so adopting Prettier Rust won't drastically change a codebase. Prettier's only downside against Rustfmt is its troublesome integration into the Rust ecosystem. Fortunately it's only a matter of time before it gets resolved.
See also:
Prettier Rust is based on jinx-rust
, a Rust Parser specially built for Rust Tooling. Learn more about jinx-rust here.
Prettier Rust is essentially a port of Prettier Typescript. The Rust plugin barely introduces style opinions on its own.
0.1.5
->
ReturnType is definedlet_else
featureFAQs
Prettier plugin for Rust
The npm package prettier-plugin-rust receives a total of 512 weekly downloads. As such, prettier-plugin-rust popularity was classified as not popular.
We found that prettier-plugin-rust demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.