@astral-sh/ruff-wasm-web 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1373 -0
- package/README.md +51 -0
- package/package.json +25 -0
- package/ruff_wasm.d.ts +126 -0
- package/ruff_wasm.js +827 -0
- package/ruff_wasm_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Ruff WASM
|
|
2
|
+
|
|
3
|
+
> **⚠️ WARNING: This API is experimental and may change at any time**
|
|
4
|
+
|
|
5
|
+
[**Docs**](https://docs.astral.sh/ruff/) | [**Playground**](https://play.ruff.rs/)
|
|
6
|
+
|
|
7
|
+
An extremely fast Python linter and code formatter, written in Rust.
|
|
8
|
+
|
|
9
|
+
This is a WASM version of the Ruff API which can be used to lint/format Python in a browser environment.
|
|
10
|
+
|
|
11
|
+
There are multiple versions for the different wasm-pack targets. See [here](https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html) for more info on targets.
|
|
12
|
+
|
|
13
|
+
- [Bundler](https://www.npmjs.com/package/@astral-sh/ruff-wasm-bundler)
|
|
14
|
+
- [Web](https://www.npmjs.com/package/@astral-sh/ruff-wasm-web)
|
|
15
|
+
- [Node.js](https://www.npmjs.com/package/@astral-sh/ruff-wasm-nodejs)
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
This example uses the wasm-pack web target and is known to work with Vite.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import init, { Workspace, type Diagnostic } from '@astral-sh/ruff-api';
|
|
23
|
+
|
|
24
|
+
const exampleDocument = `print('hello'); print("world")`
|
|
25
|
+
|
|
26
|
+
await init(); // Initializes WASM module
|
|
27
|
+
|
|
28
|
+
// These are default settings just to illustrate configuring Ruff
|
|
29
|
+
// Settings info: https://docs.astral.sh/ruff/settings
|
|
30
|
+
const workspace = new Workspace({
|
|
31
|
+
'line-length': 88,
|
|
32
|
+
'indent-width': 4,
|
|
33
|
+
format: {
|
|
34
|
+
'indent-style': 'space',
|
|
35
|
+
'quote-style': 'double',
|
|
36
|
+
},
|
|
37
|
+
lint: {
|
|
38
|
+
select: [
|
|
39
|
+
'E4',
|
|
40
|
+
'E7',
|
|
41
|
+
'E9',
|
|
42
|
+
'F'
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Will contain 1 diagnostic code for E702: Multiple statements on one line
|
|
48
|
+
const diagnostics: Diagnostic[] = workspace.check(exampleDocument);
|
|
49
|
+
|
|
50
|
+
const formatted = workspace.format(exampleDocument);
|
|
51
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@astral-sh/ruff-wasm-web",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Charlie Marsh <charlie.r.marsh@gmail.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "WebAssembly bindings for Ruff",
|
|
8
|
+
"version": "0.5.3",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/astral-sh/ruff"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"ruff_wasm_bg.wasm",
|
|
16
|
+
"ruff_wasm.js",
|
|
17
|
+
"ruff_wasm.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"main": "ruff_wasm.js",
|
|
20
|
+
"homepage": "https://docs.astral.sh/ruff",
|
|
21
|
+
"types": "ruff_wasm.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./snippets/*"
|
|
24
|
+
]
|
|
25
|
+
}
|
package/ruff_wasm.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
*/
|
|
5
|
+
export function run(): void;
|
|
6
|
+
|
|
7
|
+
export interface Diagnostic {
|
|
8
|
+
code: string | null;
|
|
9
|
+
message: string;
|
|
10
|
+
location: {
|
|
11
|
+
row: number;
|
|
12
|
+
column: number;
|
|
13
|
+
};
|
|
14
|
+
end_location: {
|
|
15
|
+
row: number;
|
|
16
|
+
column: number;
|
|
17
|
+
};
|
|
18
|
+
fix: {
|
|
19
|
+
message: string | null;
|
|
20
|
+
edits: {
|
|
21
|
+
content: string | null;
|
|
22
|
+
location: {
|
|
23
|
+
row: number;
|
|
24
|
+
column: number;
|
|
25
|
+
};
|
|
26
|
+
end_location: {
|
|
27
|
+
row: number;
|
|
28
|
+
column: number;
|
|
29
|
+
};
|
|
30
|
+
}[];
|
|
31
|
+
} | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*/
|
|
37
|
+
export class Workspace {
|
|
38
|
+
free(): void;
|
|
39
|
+
/**
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
static version(): string;
|
|
43
|
+
/**
|
|
44
|
+
* @param {any} options
|
|
45
|
+
*/
|
|
46
|
+
constructor(options: any);
|
|
47
|
+
/**
|
|
48
|
+
* @returns {any}
|
|
49
|
+
*/
|
|
50
|
+
static defaultSettings(): any;
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} contents
|
|
53
|
+
* @returns {any}
|
|
54
|
+
*/
|
|
55
|
+
check(contents: string): any;
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} contents
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
format(contents: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} contents
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
format_ir(contents: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* @param {string} contents
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
comments(contents: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Parses the content and returns its AST
|
|
73
|
+
* @param {string} contents
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
parse(contents: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} contents
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
tokens(contents: string): string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
85
|
+
|
|
86
|
+
export interface InitOutput {
|
|
87
|
+
readonly memory: WebAssembly.Memory;
|
|
88
|
+
readonly run: () => void;
|
|
89
|
+
readonly __wbg_workspace_free: (a: number) => void;
|
|
90
|
+
readonly workspace_version: (a: number) => void;
|
|
91
|
+
readonly workspace_new: (a: number, b: number) => void;
|
|
92
|
+
readonly workspace_defaultSettings: (a: number) => void;
|
|
93
|
+
readonly workspace_check: (a: number, b: number, c: number, d: number) => void;
|
|
94
|
+
readonly workspace_format: (a: number, b: number, c: number, d: number) => void;
|
|
95
|
+
readonly workspace_format_ir: (a: number, b: number, c: number, d: number) => void;
|
|
96
|
+
readonly workspace_comments: (a: number, b: number, c: number, d: number) => void;
|
|
97
|
+
readonly workspace_parse: (a: number, b: number, c: number, d: number) => void;
|
|
98
|
+
readonly workspace_tokens: (a: number, b: number, c: number, d: number) => void;
|
|
99
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
100
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
101
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
102
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
103
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
104
|
+
readonly __wbindgen_start: () => void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
108
|
+
/**
|
|
109
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
110
|
+
* a precompiled `WebAssembly.Module`.
|
|
111
|
+
*
|
|
112
|
+
* @param {SyncInitInput} module
|
|
113
|
+
*
|
|
114
|
+
* @returns {InitOutput}
|
|
115
|
+
*/
|
|
116
|
+
export function initSync(module: SyncInitInput): InitOutput;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
120
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
121
|
+
*
|
|
122
|
+
* @param {InitInput | Promise<InitInput>} module_or_path
|
|
123
|
+
*
|
|
124
|
+
* @returns {Promise<InitOutput>}
|
|
125
|
+
*/
|
|
126
|
+
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|