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();
const workspace = new Workspace({
'line-length': 88,
'indent-width': 4,
format: {
'indent-style': 'space',
'quote-style': 'double',
},
lint: {
select: [
'E4',
'E7',
'E9',
'F'
],
},
});
const diagnostics: Diagnostic[] = workspace.check(exampleDocument);
const formatted = workspace.format(exampleDocument);
0.6.0
Check out the blog post for a migration guide and overview of the changes!
Breaking changes
See also, the "Remapped rules" section which may result in disabled rules.
- Lint and format Jupyter Notebook by default (#12878).
- Detect imports in
src
layouts by default for isort
rules (#12848) - The pytest rules
PT001
and PT023
now default to omitting the decorator parentheses when there are no arguments (#12838).
Deprecations
The following rules are now deprecated:
Remapped rules
The following rules have been remapped to new rule codes:
Stabilization
The following rules have been stabilized and are no longer in preview:
The following behaviors have been stabilized:
The following fixes have been stabilized:
Preview features
- [
flake8-simplify
] Further simplify to binary in preview for (SIM108
) (#12796) - [
pyupgrade
] Show violations without auto-fix (UP031
) (#11229)
Rule changes
- [
flake8-import-conventions
] Add xml.etree.ElementTree
to default conventions (#12455) - [
flake8-pytest-style
] Add a space after comma in CSV output (PT006
) (#12853)
Server
- Show a message for incorrect settings (#12781)
Bug fixes
- [
flake8-async
] Do not lint yield in context manager (ASYNC100
) (#12896) - [
flake8-comprehensions
] Do not lint async for
comprehensions (C419
) (#12895) - [
flake8-return
] Only add return None
at end of a function (RET503
) (#11074) - [
flake8-type-checking
] Avoid treating dataclasses.KW_ONLY
as typing-only (TCH003
) (#12863) - [
pep8-naming
] Treat type(Protocol)
et al as metaclass base (N805
) (#12770) - [
pydoclint
] Don't enforce returns and yields in abstract methods (DOC201
, DOC202
) (#12771) - [
ruff
] Skip tuples with slice expressions in (RUF031
) (#12768) - [
ruff
] Ignore unparenthesized tuples in subscripts when the subscript is a type annotation or type alias (RUF031
) (#12762) - [
ruff
] Ignore template strings passed to logging and builtins._()
calls (RUF027
) (#12889) - [
ruff
] Do not remove parens for tuples with starred expressions in Python <=3.10 (RUF031
) (#12784) - Evaluate default parameter values for a function in that function's enclosing scope (#12852)
Other changes
- Respect VS Code cell metadata when detecting the language of Jupyter Notebook cells (#12864)
- Respect
kernelspec
notebook metadata when detecting the preferred language for a Jupyter Notebook (#12875)