Skip to content

Commit 5a10b7a

Browse files
committed
test(snapshots): cover the Oxlint plugin API rewrite end to end
Two PTY fixtures for the `vite-plus/lint/plugins` work: - `lint_oxlint_plugin_api`: a local JS plugin authored against `vite-plus/lint/plugins` with no `@oxlint/plugins` dependency of its own. A reported diagnostic proves the export resolves and loads under `vp lint`, which is the whole premise of the change. The same case covers the `prefer-vite-plus-imports` autofix for all three legacy authoring specifiers, and that the config surface stays clean. - `migration_oxlint_js_plugin_imports`: `vp migrate` rewriting a plugin, a rule module, and a rule test, while leaving `defineConfig` / `OxlintOverride` imports alone. The migrate snapshot also records a pre-existing gap unrelated to this change: `sanitizeMigratedOxlintConfig` derives a plugin's rule namespace from its package name, so rules belonging to a relative-path JS plugin are dropped during the `.oxlintrc.json` merge. Captured with a comment rather than papered over, so a fix shows up as a snapshot diff.
1 parent 0f39206 commit 5a10b7a

16 files changed

Lines changed: 421 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Authored against the API vite-plus re-exports, with no `@oxlint/plugins`
2+
// dependency of its own: the point of the test is that this resolves and loads.
3+
import { definePlugin, defineRule } from 'vite-plus/lint/plugins';
4+
5+
const noFoo = defineRule({
6+
meta: { messages: { noFoo: 'Do not name things "foo".' } },
7+
create(context) {
8+
return {
9+
Identifier(node) {
10+
if (node.name === 'foo') {
11+
context.report({ node, messageId: 'noFoo' });
12+
}
13+
},
14+
};
15+
},
16+
});
17+
18+
export default definePlugin({
19+
meta: { name: 'local' },
20+
rules: { 'no-foo': noFoo },
21+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "lint-oxlint-plugin-api",
3+
"version": "0.0.0",
4+
"private": true
5+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[[case]]
2+
name = "lint_oxlint_plugin_api"
3+
vp = "local"
4+
skip-platforms = [{ os = "linux", libc = "musl" }]
5+
steps = [
6+
{ argv = [
7+
"vp",
8+
"lint",
9+
"src/uses-foo.ts",
10+
], comment = "the local JS plugin imports its API from vite-plus/lint/plugins and declares no @oxlint/plugins dependency; a reported diagnostic proves the export resolved and loaded", continue-on-failure = true },
11+
{ argv = [
12+
"vp",
13+
"lint",
14+
"src/legacy-imports.ts",
15+
], comment = "prefer-vite-plus-imports flags the legacy authoring specifiers", continue-on-failure = true },
16+
{ argv = [
17+
"vp",
18+
"lint",
19+
"src/config-surface.ts",
20+
], comment = "oxlint still owns defineConfig/OxlintOverride, so these are clean", continue-on-failure = true },
21+
{ argv = [
22+
"vp",
23+
"lint",
24+
"--fix",
25+
"src/legacy-imports.ts",
26+
], comment = "autofix mirrors what vp migrate rewrites", continue-on-failure = true },
27+
{ argv = [
28+
"vpt",
29+
"print-file",
30+
"src/legacy-imports.ts",
31+
], continue-on-failure = true },
32+
{ argv = [
33+
"vp",
34+
"lint",
35+
"src/legacy-imports.ts",
36+
], comment = "confirm the rewritten file is clean", continue-on-failure = true },
37+
]
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# lint_oxlint_plugin_api
2+
3+
## `vp lint src/uses-foo.ts`
4+
5+
the local JS plugin imports its API from vite-plus/lint/plugins and declares no @oxlint/plugins dependency; a reported diagnostic proves the export resolved and loaded
6+
7+
**Exit code:** 1
8+
9+
```
10+
11+
× local(no-foo): Do not name things "foo".
12+
╭─[src/uses-foo.ts:1:14]
13+
1 │ export const foo = 1;
14+
· ───
15+
2 │ export const bar = 2;
16+
╰────
17+
18+
Found 0 warnings and 1 error.
19+
Finished in <duration> on 1 file with <n> rules using <n> threads.
20+
```
21+
22+
## `vp lint src/legacy-imports.ts`
23+
24+
prefer-vite-plus-imports flags the legacy authoring specifiers
25+
26+
**Exit code:** 1
27+
28+
```
29+
30+
× vite-plus(prefer-vite-plus-imports): Use 'vite-plus/lint/plugins' instead of 'oxlint' in Vite+ projects.
31+
╭─[src/legacy-imports.ts:1:28]
32+
1 │ import { defineRule } from 'oxlint';
33+
· ────────
34+
2 │ import { definePlugin } from '@oxlint/plugins';
35+
╰────
36+
37+
× vite-plus(prefer-vite-plus-imports): Use 'vite-plus/lint/plugins' instead of '@oxlint/plugins' in Vite+ projects.
38+
╭─[src/legacy-imports.ts:2:30]
39+
1 │ import { defineRule } from 'oxlint';
40+
2 │ import { definePlugin } from '@oxlint/plugins';
41+
· ─────────────────
42+
3 │ import { RuleTester } from 'oxlint/plugins-dev';
43+
╰────
44+
45+
× vite-plus(prefer-vite-plus-imports): Use 'vite-plus/lint/rule-tester' instead of 'oxlint/plugins-dev' in Vite+ projects.
46+
╭─[src/legacy-imports.ts:3:28]
47+
2 │ import { definePlugin } from '@oxlint/plugins';
48+
3 │ import { RuleTester } from 'oxlint/plugins-dev';
49+
· ────────────────────
50+
4 │
51+
╰────
52+
53+
Found 0 warnings and 3 errors.
54+
Finished in <duration> on 1 file with <n> rules using <n> threads.
55+
```
56+
57+
## `vp lint src/config-surface.ts`
58+
59+
oxlint still owns defineConfig/OxlintOverride, so these are clean
60+
61+
```
62+
Found 0 warnings and 0 errors.
63+
Finished in <duration> on 1 file with <n> rules using <n> threads.
64+
```
65+
66+
## `vp lint --fix src/legacy-imports.ts`
67+
68+
autofix mirrors what vp migrate rewrites
69+
70+
```
71+
Found 0 warnings and 0 errors.
72+
Finished in <duration> on 1 file with <n> rules using <n> threads.
73+
```
74+
75+
## `vpt print-file src/legacy-imports.ts`
76+
77+
```
78+
import { defineRule } from 'vite-plus/lint/plugins';
79+
import { definePlugin } from 'vite-plus/lint/plugins';
80+
import { RuleTester } from 'vite-plus/lint/rule-tester';
81+
82+
export { defineRule, definePlugin, RuleTester };
83+
```
84+
85+
## `vp lint src/legacy-imports.ts`
86+
87+
confirm the rewritten file is clean
88+
89+
```
90+
Found 0 warnings and 0 errors.
91+
Finished in <duration> on 1 file with <n> rules using <n> threads.
92+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from 'oxlint';
2+
import type { OxlintOverride } from 'oxlint';
3+
4+
export const override: OxlintOverride = { files: ['**/*.ts'] };
5+
6+
export default defineConfig({ overrides: [override] });
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineRule } from 'oxlint';
2+
import { definePlugin } from '@oxlint/plugins';
3+
import { RuleTester } from 'oxlint/plugins-dev';
4+
5+
export { defineRule, definePlugin, RuleTester };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const foo = 1;
2+
export const bar = 2;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'vite-plus';
2+
3+
export default defineConfig({
4+
lint: {
5+
jsPlugins: [
6+
'./lint/plugin.js',
7+
{ name: 'vite-plus', specifier: 'vite-plus/oxlint-plugin' },
8+
],
9+
rules: {
10+
'local/no-foo': 'error',
11+
'vite-plus/prefer-vite-plus-imports': 'error',
12+
},
13+
},
14+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"jsPlugins": ["./lint/plugin.js"],
3+
"rules": {
4+
"local/no-foo": "error"
5+
}
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineRule } from 'oxlint';
2+
3+
export const noFoo = defineRule({
4+
meta: { messages: { noFoo: 'Do not name things "foo".' } },
5+
create(context) {
6+
return {
7+
Identifier(node) {
8+
if (node.name === 'foo') {
9+
context.report({ node, messageId: 'noFoo' });
10+
}
11+
},
12+
};
13+
},
14+
});

0 commit comments

Comments
 (0)