Skip to content

wasm-fmt/ruff_fmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Feb 28, 2025
e23933f · Feb 28, 2025
Nov 7, 2024
Oct 19, 2024
Jan 9, 2025
Aug 9, 2023
Jan 14, 2024
Nov 7, 2024
Oct 19, 2024
Aug 9, 2023
May 2, 2024
Feb 28, 2025
Feb 28, 2025
Aug 8, 2023
Aug 17, 2024
Oct 19, 2024

Repository files navigation

Test

Install

npm

npm install @wasm-fmt/ruff_fmt

jsr.io

npx jsr add @fmt/ruff-fmt

Usage

import init, { format } from "@wasm-fmt/ruff_fmt";

await init();

const input = `x = {  'a':37,'b':42,

'c':927}

y = 'hello ''world'
z = 'hello '+'world'
a = 'hello {}'.format('world')
class foo  (     object  ):
  def f    (self   ):
    return       37*-+2
  def g(self, x,y=42):
      return y
def f  (   a ) :
  return      37+-+a[42-x :  y**3]`;

const formatted = format(input);
console.log(formatted);

with custom options:

import init, { format } from "@wasm-fmt/ruff_fmt";

// ...
const formatted = format(input, {
    indent_style: "space",
    indent_width: 4,
    line_width: 88,
    quote_style: "double",
    magic_trailing_comma: "respect",
});
console.log(formatted);

For Vite users:

Add "@wasm-fmt/ruff_fmt" to optimizeDeps.exclude in your vite config:

{
    "optimizeDeps": {
        "exclude": ["@wasm-fmt/ruff_fmt"]
    }
}
If you cannot change the vite config, you can use another import entry
import init, { format } from "@wasm-fmt/ruff_fmt/vite";

// ...

dprint plugin

Note

dpint plugin is deprecated, please use https://dprint.dev/plugins/ruff instead.

dprint config add wasm-fmt/ruff_fmt

How does it work?

Ruff is an extremely fast Python linter, written in Rust.

This package is a WebAssembly build of Ruff formatter, with a JavaScript wrapper.