mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 05:51:03 -05:00
Summary -- This PR fixes https://github.com/astral-sh/ty/issues/2186 by replacing uses of `Diagnostic::body` with [`Diagnostic::concise_message`][d]. The initial report was only about ty's GitHub and GitLab output formats, but I think it makes sense to prefer `concise_message` in the other output formats too. Ruff currently only sets the primary message on its diagnostics, which is why this has no effect on Ruff, and ty currently only supports the GitHub and GitLab formats that used `body`, but removing `body` should help to avoid this problem as Ruff starts to use more diagnostic features or ty gets new output formats. Test Plan -- Updated existing GitLab and GitHub CLI tests to have `reveal_type` diagnostics [d]: https://github.com/astral-sh/ruff/blob/395bf106ab/crates/ruff_db/src/diagnostic/mod.rs#L185 [t]: https://github.com/astral-sh/ruff/blob/395bf106ab/crates/ruff/tests/cli/lint.rs#L3509
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, PositionEncoding } from '@astral-sh/ruff-wasm-web';
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'
],
},
}, PositionEncoding.UTF16);
// Will contain 1 diagnostic code for E702: Multiple statements on one line
const diagnostics: Diagnostic[] = workspace.check(exampleDocument);
const formatted = workspace.format(exampleDocument);