鲁夫・瓦斯姆
警告:这个API是实验性的,随时可能改变
一个极快的Python linter 和代码用于物质,用Rust来写.
这是Ruff API的WASM版本,可以在浏览器环境中用于lint/format Python.
不同的被包装对象有多个版本. 见 这里 需要更多关于目标的信息.
使用量
这个例子使用被打包的网络目标,已知与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 settings 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);
版本
这个箱子是内部部件 鲁夫. Rust API 曝光的 Rust API 这里不稳定, 并且会经常发生断裂变化 .
此版本( 0. 17.4) 是 Ruff 0.17.4号公路编辑 来源可见 这里。 。 。 .
见"鲁夫" 板条箱版本策略 页:1 关于版本的细节.