Skip to content

Commit 5415924

Browse files
committed
refactor(linter/plugins): convert Node type to interface
1 parent 1387aaa commit 5415924

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

apps/oxlint/src-js/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { BeforeHook, Visitor, VisitorWithHooks } from './plugins/types.ts';
55
export type { Context, Diagnostic } from './plugins/context.ts';
66
export type { Fix, Fixer, FixFn, NodeOrToken, Range } from './plugins/fix.ts';
77
export type { CreateOnceRule, CreateRule, Plugin, Rule } from './plugins/load.ts';
8-
export type { AfterHook, BeforeHook, RuleMeta, Visitor, VisitorWithHooks } from './plugins/types.ts';
8+
export type { AfterHook, BeforeHook, Node, RuleMeta, Visitor, VisitorWithHooks } from './plugins/types.ts';
99

1010
const { defineProperty, getPrototypeOf, hasOwn, setPrototypeOf, create: ObjectCreate } = Object;
1111

apps/oxlint/src-js/plugins/context.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { getFixes } from './fix.js';
22

33
import type { Fix, FixFn } from './fix.ts';
4+
import type { Node } from './types.ts';
45

56
// Diagnostic in form passed by user to `Context#report()`
67
export interface Diagnostic {
78
message: string;
8-
node: {
9-
start: number;
10-
end: number;
11-
};
9+
node: Node;
1210
fix?: FixFn;
1311
}
1412

apps/oxlint/src-js/plugins/fix.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assertIs } from './utils.js';
22

33
import type { Diagnostic, InternalContext } from './context.ts';
4+
import type { Node } from './types.ts';
45

56
const { prototype: ArrayPrototype, from: ArrayFrom } = Array,
67
{ getPrototypeOf, hasOwn, prototype: ObjectPrototype } = Object,
@@ -20,10 +21,7 @@ export type Fix = { range: Range; text: string };
2021
export type Range = [number, number];
2122

2223
// Currently we only support `Node`s, but will add support for `Token`s later
23-
export interface NodeOrToken {
24-
start: number;
25-
end: number;
26-
}
24+
export type NodeOrToken = Node;
2725

2826
// Fixer, passed as argument to `fix` function passed to `Context#report()`.
2927
//

apps/oxlint/src-js/plugins/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export interface VisitorWithHooks extends Visitor {
2626
export type VisitFn = (node: Node) => void;
2727

2828
// AST node type.
29-
// We'll make this type a union later on.
30-
export type Node = { type: string; start: number; end: number; [key: string]: unknown };
29+
export interface Node {
30+
start: number;
31+
end: number;
32+
}
3133

3234
// Element of compiled visitor array.
3335
// * `VisitFn | null` for leaf nodes.

0 commit comments

Comments
 (0)