Skip to content

Commit d43a5b9

Browse files
committed
feat(linter/plugins): oxlint export types
1 parent 41354ae commit d43a5b9

File tree

13 files changed

+90
-62
lines changed

13 files changed

+90
-62
lines changed

apps/oxlint/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"type": "module",
55
"main": "dist/index.js",
66
"bin": "dist/cli.js",
7+
"types": "dist/index.d.ts",
78
"scripts": {
89
"build": "pnpm run build-napi-release && pnpm run build-js",
910
"build-dev": "pnpm run build-napi && pnpm run build-js",
@@ -34,9 +35,13 @@
3435
"files": [
3536
"dist"
3637
],
38+
"dependencies": {
39+
"@oxc-project/types": "workspace:^"
40+
},
3741
"devDependencies": {
3842
"eslint": "^9.36.0",
3943
"execa": "^9.6.0",
44+
"jiti": "^2.6.0",
4045
"tsdown": "0.15.1",
4146
"typescript": "catalog:",
4247
"vitest": "catalog:"

apps/oxlint/src-js/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { Context } from './plugins/context.ts';
22
import type { CreateOnceRule, Plugin, Rule } from './plugins/load.ts';
33
import type { BeforeHook, Visitor, VisitorWithHooks } from './plugins/types.ts';
44

5+
export type { Context, Plugin, Rule, Visitor, VisitorWithHooks };
6+
57
const { defineProperty, getPrototypeOf, hasOwn, setPrototypeOf, create: ObjectCreate } = Object;
68

79
const dummyOptions: unknown[] = [],

apps/oxlint/test/fixtures/definePlugin/.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"jsPlugins": ["./plugin.js"],
2+
"jsPlugins": ["./plugin.ts"],
33
"categories": { "correctness": "off" },
44
"rules": {
55
"define-plugin-plugin/create": "error",

apps/oxlint/test/fixtures/definePlugin/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import plugin from './plugin.js';
1+
import plugin from './plugin.ts';
22

33
export default [
44
{

apps/oxlint/test/fixtures/definePlugin/plugin.js renamed to apps/oxlint/test/fixtures/definePlugin/plugin.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { sep } from 'node:path';
22
import { definePlugin } from '../../../dist/index.js';
3+
import type { Rule } from '../../../dist/index.js';
34

45
// `loc` is required for ESLint
56
const SPAN = {
@@ -14,10 +15,10 @@ const SPAN = {
1415
const DIR_PATH_LEN = import.meta.dirname.length + 1;
1516

1617
const relativePath = sep === '/'
17-
? path => path.slice(DIR_PATH_LEN)
18-
: path => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
18+
? (path: string) => path.slice(DIR_PATH_LEN)
19+
: (path: string) => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
1920

20-
const createRule = {
21+
const createRule: Rule = {
2122
create(context) {
2223
context.report({ message: `create body:\nthis === rule: ${this === createRule}`, node: SPAN });
2324

@@ -36,16 +37,16 @@ const createRule = {
3637
// i.e. Oxlint calls `createOnce` directly, and not the `create` method that `defineRule` (via `definePlugin`)
3738
// adds to the rule.
3839
let createOnceCallCount = 0;
39-
const createOnceRule = {
40+
const createOnceRule: Rule = {
4041
createOnce(context) {
4142
createOnceCallCount++;
4243

4344
// `fileNum` should be different for each file.
4445
// `identNum` should start at 1 for each file.
45-
let fileNum = 0, identNum;
46+
let fileNum = 0, identNum: number;
4647
// Note: Files are processed in unpredictable order, so `files/1.js` may be `fileNum` 1 or 2.
4748
// Therefore, collect all visits and check them in `after` hook of the 2nd file.
48-
const visits = [];
49+
const visits: { fileNum: number; identNum: number }[] = [];
4950

5051
// `this` should be the rule object
5152
const topLevelThis = this;
@@ -105,7 +106,7 @@ const createOnceRule = {
105106
};
106107

107108
// Tests that `before` hook returning `false` disables visiting AST for the file.
108-
const createOnceBeforeFalseRule = {
109+
const createOnceBeforeFalseRule: Rule = {
109110
createOnce(context) {
110111
return {
111112
before() {
@@ -138,7 +139,7 @@ const createOnceBeforeFalseRule = {
138139

139140
// These 3 rules test that `createOnce` without `before` and `after` hooks works correctly.
140141

141-
const createOnceBeforeOnlyRule = {
142+
const createOnceBeforeOnlyRule: Rule = {
142143
createOnce(context) {
143144
return {
144145
before() {
@@ -159,7 +160,7 @@ const createOnceBeforeOnlyRule = {
159160
},
160161
};
161162

162-
const createOnceAfterOnlyRule = {
163+
const createOnceAfterOnlyRule: Rule = {
163164
createOnce(context) {
164165
return {
165166
Identifier(node) {
@@ -180,7 +181,7 @@ const createOnceAfterOnlyRule = {
180181
},
181182
};
182183

183-
const createOnceNoHooksRule = {
184+
const createOnceNoHooksRule: Rule = {
184185
createOnce(context) {
185186
return {
186187
Identifier(node) {

apps/oxlint/test/fixtures/definePlugin_and_defineRule/.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"jsPlugins": ["./plugin.js"],
2+
"jsPlugins": ["./plugin.ts"],
33
"categories": { "correctness": "off" },
44
"rules": {
55
"define-plugin-and-rule-plugin/create": "error",

apps/oxlint/test/fixtures/definePlugin_and_defineRule/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import plugin from './plugin.js';
1+
import plugin from './plugin.ts';
22

33
export default [
44
{

apps/oxlint/test/fixtures/definePlugin_and_defineRule/plugin.js renamed to apps/oxlint/test/fixtures/definePlugin_and_defineRule/plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const SPAN = {
1414
const DIR_PATH_LEN = import.meta.dirname.length + 1;
1515

1616
const relativePath = sep === '/'
17-
? path => path.slice(DIR_PATH_LEN)
18-
: path => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
17+
? (path: string) => path.slice(DIR_PATH_LEN)
18+
: (path: string) => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
1919

2020
const createRule = defineRule({
2121
create(context) {
@@ -41,10 +41,10 @@ const createOnceRule = defineRule({
4141

4242
// `fileNum` should be different for each file.
4343
// `identNum` should start at 1 for each file.
44-
let fileNum = 0, identNum;
44+
let fileNum = 0, identNum: number;
4545
// Note: Files are processed in unpredictable order, so `files/1.js` may be `fileNum` 1 or 2.
4646
// Therefore, collect all visits and check them in `after` hook of the 2nd file.
47-
const visits = [];
47+
const visits: { fileNum: number; identNum: number }[] = [];
4848

4949
// `this` should be the rule object returned by `defineRule`
5050
const topLevelThis = this;

apps/oxlint/test/fixtures/defineRule/.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"jsPlugins": ["./plugin.js"],
2+
"jsPlugins": ["./plugin.ts"],
33
"categories": { "correctness": "off" },
44
"rules": {
55
"define-rule-plugin/create": "error",

apps/oxlint/test/fixtures/defineRule/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import plugin from './plugin.js';
1+
import plugin from './plugin.ts';
22

33
export default [
44
{

0 commit comments

Comments
 (0)