@astral-sh/ruff-wasm-nodejs 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 +21 -0
- package/ruff_wasm.d.ts +82 -0
- package/ruff_wasm.js +810 -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,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@astral-sh/ruff-wasm-nodejs",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"Charlie Marsh <charlie.r.marsh@gmail.com>"
|
|
5
|
+
],
|
|
6
|
+
"description": "WebAssembly bindings for Ruff",
|
|
7
|
+
"version": "0.5.3",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/astral-sh/ruff"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"ruff_wasm_bg.wasm",
|
|
15
|
+
"ruff_wasm.js",
|
|
16
|
+
"ruff_wasm.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"main": "ruff_wasm.js",
|
|
19
|
+
"homepage": "https://docs.astral.sh/ruff",
|
|
20
|
+
"types": "ruff_wasm.d.ts"
|
|
21
|
+
}
|
package/ruff_wasm.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}
|