Skip to main content
Home

@fmt/ruff-fmt@0.10.0
Built and signed on GitHub Actions

A WASM Based Python Formatter

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
58%
Published
2 months ago (0.10.0)

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.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@fmt/ruff-fmt

Import symbol

import * as ruff_fmt from "@fmt/ruff-fmt";
or

Import directly with a jsr specifier

import * as ruff_fmt from "jsr:@fmt/ruff-fmt";

Add Package

pnpm i jsr:@fmt/ruff-fmt
or (using pnpm 10.8 or older)
pnpm dlx jsr add @fmt/ruff-fmt

Import symbol

import * as ruff_fmt from "@fmt/ruff-fmt";

Add Package

yarn add jsr:@fmt/ruff-fmt
or (using Yarn 4.8 or older)
yarn dlx jsr add @fmt/ruff-fmt

Import symbol

import * as ruff_fmt from "@fmt/ruff-fmt";

Add Package

vlt install jsr:@fmt/ruff-fmt

Import symbol

import * as ruff_fmt from "@fmt/ruff-fmt";

Add Package

npx jsr add @fmt/ruff-fmt

Import symbol

import * as ruff_fmt from "@fmt/ruff-fmt";

Add Package

bunx jsr add @fmt/ruff-fmt

Import symbol

import * as ruff_fmt from "@fmt/ruff-fmt";