ruff/crates/ruff_wasm
Brent Westbrook 87f0feb21a
Bump 0.12.0 (#18724)
- [x] Updated changelog
- [x] Updated breaking changes
2025-06-17 11:05:59 -04:00
..
src Remove Message::to_rule (#18447) 2025-06-05 12:48:29 -04:00
tests [syntax errors] Stabilize version-specific unsupported syntax errors (#18522) 2025-06-17 09:58:12 -04:00
Cargo.toml Bump 0.12.0 (#18724) 2025-06-17 11:05:59 -04:00
README.md Publish wasm API to npm (#12317) 2024-07-17 08:50:38 +02:00

Ruff WASM

⚠️ WARNING: This API is experimental and may change at any time

Docs | Playground

An extremely fast Python linter and code formatter, written in Rust.

This is a WASM version of the Ruff API which can be used to lint/format Python in a browser environment.

There are multiple versions for the different wasm-pack targets. See here for more info on targets.

Usage

This example uses the wasm-pack web target and is known to work with Vite.

import init, { Workspace, type Diagnostic } from '@astral-sh/ruff-api';

const exampleDocument = `print('hello'); print("world")`

await init(); // Initializes WASM module

// These are default settings just to illustrate configuring Ruff
// Settings info: https://docs.astral.sh/ruff/settings
const workspace = new Workspace({
  'line-length': 88,
  'indent-width': 4,
  format: {
    'indent-style': 'space',
    'quote-style': 'double',
  },
  lint: {
    select: [
      'E4',
      'E7',
      'E9',
      'F'
    ],
  },
});

// Will contain 1 diagnostic code for E702: Multiple statements on one line
const diagnostics: Diagnostic[] = workspace.check(exampleDocument);

const formatted = workspace.format(exampleDocument);