mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
![]() ## Summary This PR unifies the ruff `Message` enum variants for syntax errors and rule violations into a single `Message` struct consisting of a shared `db::Diagnostic` and some additional, optional fields used for some rule violations. This version of `Message` is nearly a drop-in replacement for `ruff_diagnostics::Diagnostic`, which is the next step I have in mind for the refactor. I think this is also a useful checkpoint because we could possibly add some of these optional fields to the new `Diagnostic` type. I think we've previously discussed wanting support for `Fix`es, but the other fields seem less relevant, so we may just need to preserve the `Message` wrapper for a bit longer. ## Test plan Existing tests --------- Co-authored-by: Micha Reiser <micha@reiser.io> |
||
---|---|---|
.. | ||
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);