@ohos-rs/oxk 0.4.1 → 0.6.0
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/README.md +113 -11
- package/bin/oxk.js +33 -1
- package/configuration_schema.json +1817 -0
- package/format.d.ts +2 -0
- package/format.js +2 -3
- package/index.d.ts +30 -19
- package/index.js +57 -53
- package/lint.d.ts +1 -0
- package/lint.js +283 -0
- package/oxlint-runtime/js_config.cjs +8 -0
- package/oxlint-runtime/plugins.cjs +31 -0
- package/package.json +41 -21
package/README.md
CHANGED
|
@@ -1,31 +1,133 @@
|
|
|
1
1
|
# `@ohos-rs/oxk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ArkTS/ArkUI parser, formatter, and lint tooling based on OXC and oxlint.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
Install with npm
|
|
5
|
+
## Install
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npm install @ohos-rs/oxk
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
For CLI usage, install it in your project and run it through your package
|
|
12
|
+
manager, or install it globally:
|
|
14
13
|
|
|
15
14
|
```bash
|
|
16
|
-
|
|
15
|
+
npm install -g @ohos-rs/oxk
|
|
16
|
+
oxk --help
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
The npm package requires Node.js `^20.19.0 || >=22.18.0`.
|
|
20
|
+
|
|
21
|
+
## Format
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
oxk format src/index.ets
|
|
25
|
+
oxk format "src/**/*.{ts,ets}"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Formatter config is loaded from `.oxfmtrc.json` or `.oxfmtrc.jsonc`.
|
|
29
|
+
|
|
30
|
+
## Lint
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
oxk lint src --threads 1
|
|
34
|
+
oxk lint src/index.ets --format json
|
|
35
|
+
oxk lint --config .oxlintrc.jsonc "src/**/*.ets"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`oxk lint` embeds `oxlint::CliRunner`; it does not shell out to an external
|
|
39
|
+
`oxlint` binary. The npm CLI includes the oxlint JavaScript runtime for:
|
|
40
|
+
|
|
41
|
+
- `.oxlintrc.json` and `.oxlintrc.jsonc`
|
|
42
|
+
- `oxlint.config.ts`
|
|
43
|
+
- oxlint built-in plugin configuration, such as `plugins: ["react"]`
|
|
44
|
+
- JavaScript plugins configured with `jsPlugins`
|
|
45
|
+
- plugin settings and globals
|
|
46
|
+
|
|
47
|
+
The cargo CLI keeps a pure Rust runner. Use JSON or JSONC config files there;
|
|
48
|
+
the JavaScript runtime and `oxlint.config.ts` are npm-only.
|
|
20
49
|
|
|
21
|
-
|
|
50
|
+
## ArkTS Rules
|
|
51
|
+
|
|
52
|
+
ArkTS migration rules are built in as the virtual `arkts` plugin. See
|
|
53
|
+
[Built-in Lint](../../crates/lint/README.md) for the rule list, configuration
|
|
54
|
+
examples, `arkts/system-api-version`, and the SDK sync workflow.
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// index.ets
|
|
60
|
+
const key = Symbol('id')
|
|
61
|
+
let marker: symbol
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
oxk lint index.ets --threads 1 --format json
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## JavaScript API
|
|
69
|
+
|
|
70
|
+
Use the formatter wrapper:
|
|
22
71
|
|
|
23
72
|
```js
|
|
24
|
-
const
|
|
73
|
+
const { format } = require('@ohos-rs/oxk/format')
|
|
25
74
|
```
|
|
26
75
|
|
|
27
|
-
|
|
76
|
+
Use the lint wrapper with oxlint-compatible CLI arguments:
|
|
28
77
|
|
|
29
78
|
```js
|
|
30
|
-
const
|
|
79
|
+
const { lint } = require('@ohos-rs/oxk/lint')
|
|
80
|
+
|
|
81
|
+
const ok = await lint(['src/index.ets', '--threads', '1'])
|
|
82
|
+
process.exitCode = ok ? 0 : 1
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The native module is also available from the package root:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const oxk = require('@ohos-rs/oxk')
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For linting from JavaScript, prefer `@ohos-rs/oxk/lint`; it wires the oxlint JS
|
|
92
|
+
runtime callbacks for plugins and JavaScript config files.
|
|
93
|
+
|
|
94
|
+
## WASI
|
|
95
|
+
|
|
96
|
+
Build the WASI artifact locally:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pnpm build --target wasm32-wasip1-threads
|
|
100
|
+
pnpm run test:wasi
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`test:wasi` forces `NAPI_RS_FORCE_WASI=1` and verifies the generated WASI
|
|
104
|
+
binding can load and execute `parse` and `format`. Linting is intentionally not
|
|
105
|
+
available from the WASI build because the oxlint runner and JavaScript plugin
|
|
106
|
+
runtime are native-only; use the native npm package or cargo CLI for linting.
|
|
107
|
+
|
|
108
|
+
## Local Development
|
|
109
|
+
|
|
110
|
+
Build the local NAPI binary before running npm CLI tests:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pnpm --filter @ohos-rs/oxk run build:debug
|
|
114
|
+
pnpm --filter @ohos-rs/oxk test
|
|
115
|
+
pnpm --filter @ohos-rs/oxk run build --target wasm32-wasip1-threads
|
|
116
|
+
pnpm --filter @ohos-rs/oxk run test:wasi
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Update the bundled oxlint JavaScript runtime after changing the upstream source
|
|
120
|
+
or dependency versions:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pnpm --filter @ohos-rs/oxk run build:oxlint-runtime
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Run the Rust checks:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
cargo check -p lint -p oxk
|
|
130
|
+
cargo check -p oxk-napi
|
|
131
|
+
cargo test -p lint -p oxk
|
|
132
|
+
git diff --check
|
|
31
133
|
```
|
package/bin/oxk.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const VERSION = require('../package.json').version
|
|
4
4
|
const { formatFiles } = require('./format.js')
|
|
5
|
+
const { formatLsp } = require('../index.js')
|
|
6
|
+
const { lint } = require('../lint.js')
|
|
5
7
|
|
|
6
8
|
function parseBoolean(value, flagName) {
|
|
7
9
|
if (value === 'true') {
|
|
@@ -43,12 +45,18 @@ Usage:
|
|
|
43
45
|
|
|
44
46
|
Commands:
|
|
45
47
|
format Format files
|
|
48
|
+
lint Lint files
|
|
46
49
|
|
|
47
50
|
Global Options:
|
|
48
51
|
--help, -h Show help
|
|
49
52
|
--version, -v Show version
|
|
50
53
|
|
|
54
|
+
Lint Options:
|
|
55
|
+
Supports oxlint-compatible options, configuration files, built-in plugins, and JS plugins.
|
|
56
|
+
Run "oxk lint --help" for the full lint option list.
|
|
57
|
+
|
|
51
58
|
Format Options:
|
|
59
|
+
--lsp
|
|
52
60
|
--config PATH
|
|
53
61
|
--thread, -t THREAD
|
|
54
62
|
--exclude PATTERN
|
|
@@ -72,6 +80,9 @@ Format Options:
|
|
|
72
80
|
Examples:
|
|
73
81
|
oxk format src/**/*.ets
|
|
74
82
|
oxk format --exclude dist/** --config .oxfmtrc.json "src/**/*.{ts,ets}"
|
|
83
|
+
oxk lint src
|
|
84
|
+
oxk lint --config .oxlintrc.json --react-plugin "src/**/*.{ts,tsx,ets}"
|
|
85
|
+
oxk lint --config .oxlintrc.json "src/**/*.ets"
|
|
75
86
|
`)
|
|
76
87
|
}
|
|
77
88
|
|
|
@@ -85,6 +96,7 @@ function parseFormatArgs(args) {
|
|
|
85
96
|
excludes: [],
|
|
86
97
|
threadCount: 1,
|
|
87
98
|
configPath: undefined,
|
|
99
|
+
lsp: false,
|
|
88
100
|
cliOptions: {},
|
|
89
101
|
}
|
|
90
102
|
|
|
@@ -101,6 +113,10 @@ function parseFormatArgs(args) {
|
|
|
101
113
|
}
|
|
102
114
|
|
|
103
115
|
switch (token.split('=')[0]) {
|
|
116
|
+
case '--lsp': {
|
|
117
|
+
formatArgs.lsp = true
|
|
118
|
+
break
|
|
119
|
+
}
|
|
104
120
|
case '--config': {
|
|
105
121
|
const { value, nextIndex } = parseOptionValue(args, index, token)
|
|
106
122
|
formatArgs.configPath = value
|
|
@@ -268,19 +284,35 @@ async function main() {
|
|
|
268
284
|
process.exit(0)
|
|
269
285
|
}
|
|
270
286
|
|
|
271
|
-
if (command !== 'format') {
|
|
287
|
+
if (command !== 'format' && command !== 'lint') {
|
|
272
288
|
console.error(`Unknown command: ${command}`)
|
|
273
289
|
console.error("Run 'oxk --help' for usage information")
|
|
274
290
|
process.exit(1)
|
|
275
291
|
}
|
|
276
292
|
|
|
277
293
|
try {
|
|
294
|
+
if (command === 'lint') {
|
|
295
|
+
const success = await lint(args.slice(1))
|
|
296
|
+
if (!success) {
|
|
297
|
+
process.exit(1)
|
|
298
|
+
}
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
|
|
278
302
|
const { help, formatArgs } = parseFormatArgs(args.slice(1))
|
|
279
303
|
if (help) {
|
|
280
304
|
showHelp()
|
|
281
305
|
process.exit(0)
|
|
282
306
|
}
|
|
283
307
|
|
|
308
|
+
if (formatArgs.lsp) {
|
|
309
|
+
if (typeof formatLsp !== 'function') {
|
|
310
|
+
throw new Error('oxk format --lsp requires the native oxk binding')
|
|
311
|
+
}
|
|
312
|
+
await formatLsp()
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
|
|
284
316
|
await formatFiles(formatArgs)
|
|
285
317
|
} catch (error) {
|
|
286
318
|
console.error(error instanceof Error ? error.message : String(error))
|