mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-30 19:47:52 +00:00 
			
		
		
		
	|  f51a228f04 
		
			Some checks are pending
		
		
	 CI / Determine changes (push) Waiting to run CI / cargo fmt (push) Waiting to run CI / cargo clippy (push) Blocked by required conditions CI / cargo test (linux) (push) Blocked by required conditions CI / cargo test (linux, release) (push) Blocked by required conditions CI / cargo test (windows) (push) Blocked by required conditions CI / cargo test (wasm) (push) Blocked by required conditions CI / cargo build (release) (push) Waiting to run CI / cargo build (msrv) (push) Blocked by required conditions CI / cargo fuzz build (push) Blocked by required conditions CI / fuzz parser (push) Blocked by required conditions CI / test scripts (push) Blocked by required conditions CI / ecosystem (push) Blocked by required conditions CI / Fuzz for new ty panics (push) Blocked by required conditions CI / cargo shear (push) Blocked by required conditions CI / python package (push) Waiting to run CI / pre-commit (push) Waiting to run CI / mkdocs (push) Waiting to run CI / formatter instabilities and black similarity (push) Blocked by required conditions CI / test ruff-lsp (push) Blocked by required conditions CI / check playground (push) Blocked by required conditions CI / benchmarks-instrumented (push) Blocked by required conditions CI / benchmarks-walltime (push) Blocked by required conditions [ty Playground] Release / publish (push) Waiting to run | ||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| README.md | ||
Ruff WASM
⚠️ WARNING: This API is experimental and may change at any time
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);