Skip to content

About

Adapter plugin to use Oxc in dprint's CLI and with JavaScript via Wasm

Resources

Stars

9 stars

Watchers

0 watching

Forks

Repository files navigation

dprint-plugin-oxc

npm version CI

Adapter for Oxc for use as a formatting plugin in dprint.

Supported languages

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.

Install

Install and setup dprint.

Then in your project's directory with a dprint.json file, run:

dprint add oxc

Note: You do not need Oxc installed globally as dprint will run the Oxc formatter from the .wasm file in a sandboxed environment.

Configuration

To add configuration, specify an "oxc" key in your dprint.json:

{
  "oxc": {
    "indentStyle": "space",
    "lineWidth": 100,
    "indentWidth": 2,
  },
  "plugins": [
    // ...etc...
  ],
}

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.

Disabling languages

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 Formatting API

Versioning

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.

About

Adapter plugin to use Oxc in dprint's CLI and with JavaScript via Wasm

Resources

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages