Adapter for Oxc for use as a formatting plugin in dprint.
The plugin formats the languages that Oxc's formatter (oxfmt) formats natively in Rust:
- JavaScript and TypeScript (including JSX)
- JSON, JSONC, and JSON5
- CSS, SCSS, and Less
- GraphQL
- YAML
- Markdown
- TOML
Code embedded in these is formatted too (ex. CSS or GraphQL in a JS template literal, YAML front matter in CSS, or code blocks in Markdown).
If you only want to use this plugin for some of these languages, disable the other languages.
Then in your project's directory with a dprint.json file, run:
dprint add oxcNote: You do not need Oxc installed globally as dprint will run the Oxc formatter from the .wasm file in a sandboxed environment.
To add configuration, specify an "oxc" key in your dprint.json:
For an overview of the config, see https://dprint.dev/plugins/oxc/config/
Like in oxfmt, the configuration is shared between the languages. For example, quoteStyle applies to JavaScript, CSS, YAML, and so on.
Every language is formatted by default. To have the plugin leave the files of a language alone, set its <language>.enabled option to false:
{
"oxc": {
"markdown.enabled": false,
"yaml.enabled": false,
},
}The languages are javascript, typescript, json, jsonc, json5, graphql, css, scss, less, yaml, markdown, and toml. JSX is part of javascript and TSX is part of typescript.
A disabled language's files are no longer matched by this plugin, so dprint formats them with the next plugin that matches them, if any. This only decides which files are formatted: code embedded in a file of an enabled language is still formatted (ex. CSS in a JS template literal when css.enabled is false).
Note: The plugin does not understand Oxc's configuration file because it runs sandboxed in a Wasm runtime—it has no access to the file system in order to read Oxc's config.
- JS Formatter - Browser/Deno and Node
- npm package
This repo automatically upgrades to the latest version of Oxc once a day. You can check which version of Oxc is being used by looking at the tag property in the oxc_formatter entry in the Cargo.toml file in this repo:
https://github.com/dprint/dprint-plugin-oxc/blob/main/Cargo.toml
At the moment, the version of this plugin does not reflect the version of Oxc.
{ "oxc": { "indentStyle": "space", "lineWidth": 100, "indentWidth": 2, }, "plugins": [ // ...etc... ], }