Skip to content

Commit 63ddbdb

Browse files
committed
test(linter/plugins): add types test for VisitorObject
1 parent 4495ed1 commit 63ddbdb

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

apps/oxlint/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@arethetypeswrong/core": "catalog:",
4040
"@babel/code-frame": "^7.28.6",
4141
"@napi-rs/cli": "catalog:",
42+
"@type-challenges/utils": "^0.1.1",
4243
"@types/babel__code-frame": "^7.27.0",
4344
"@types/esquery": "^1.5.4",
4445
"@types/estree": "^1.0.8",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { VisitorObject } from "./generated/visitor";
2+
import type { Node, CallExpression } from "./generated/types";
3+
import type { ExpectExtends, ExpectTrue } from "@type-challenges/utils";
4+
5+
const emptyVisitorObject = {};
6+
const callExpressionVisitorObject = {
7+
CallExpression: (_node: CallExpression) => {},
8+
};
9+
const callExpressionExitVisitorObject = {
10+
"CallExpression:exit": (_node: CallExpression) => {},
11+
};
12+
const genericVisitorObject = {
13+
"FunctionExpression > Identifier": (_node: Node) => {},
14+
":matches(FunctionExpression, FunctionDeclaration)": (_node: Node) => {},
15+
};
16+
17+
export type cases1 = [
18+
// Empty visitor object is allowed
19+
ExpectTrue<ExpectExtends<VisitorObject, typeof emptyVisitorObject>>,
20+
// Specific node visitors has a stricter type for the parameter
21+
ExpectTrue<ExpectExtends<VisitorObject, typeof callExpressionVisitorObject>>,
22+
ExpectTrue<ExpectExtends<VisitorObject, typeof callExpressionExitVisitorObject>>,
23+
// Node selectors has generic Node type for the parameter
24+
ExpectTrue<ExpectExtends<VisitorObject, typeof genericVisitorObject>>,
25+
];

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)