Skip to content

Commit 46e150d

Browse files
committed
more types
1 parent b3ddde1 commit 46e150d

File tree

3 files changed

+101
-89
lines changed

3 files changed

+101
-89
lines changed

cli/js/40_lint.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,8 @@ const PropFlags = {
7777
/** @typedef {import("./40_lint_types.d.ts").VisitorFn} VisitorFn */
7878
/** @typedef {import("./40_lint_types.d.ts").CompiledVisitor} CompiledVisitor */
7979
/** @typedef {import("./40_lint_types.d.ts").LintState} LintState */
80-
/** @typedef {import("./40_lint_types.d.ts").IFixer} IFixer */
81-
/** @typedef {import("./40_lint_types.d.ts").RuleContext} RuleContext */
82-
/** @typedef {import("./40_lint_types.d.ts").LintPlugin} LintPlugin */
8380
/** @typedef {import("./40_lint_types.d.ts").TransformFn} TransformFn */
8481
/** @typedef {import("./40_lint_types.d.ts").MatchContext} MatchContext */
85-
/** @typedef {import("./40_lint_types.d.ts").INode} INode */
86-
/** @typedef {import("./40_lint_types.d.ts").IReportData} IReportData */
8782

8883
/** @type {LintState} */
8984
const state = {
@@ -108,10 +103,10 @@ class CancellationToken {
108103
}
109104
}
110105

111-
/** @implements {IFixer} */
106+
/** @implements {Deno.lint.Fixer} */
112107
class Fixer {
113108
/**
114-
* @param {INode} node
109+
* @param {Deno.lint.Node} node
115110
* @param {string} text
116111
*/
117112
insertTextAfter(node, text) {
@@ -122,7 +117,7 @@ class Fixer {
122117
}
123118

124119
/**
125-
* @param {INode["range"]} range
120+
* @param {Deno.lint.Node["range"]} range
126121
* @param {string} text
127122
*/
128123
insertTextAfterRange(range, text) {
@@ -133,7 +128,7 @@ class Fixer {
133128
}
134129

135130
/**
136-
* @param {INode} node
131+
* @param {Deno.lint.Node} node
137132
* @param {string} text
138133
*/
139134
insertTextBefore(node, text) {
@@ -144,7 +139,7 @@ class Fixer {
144139
}
145140

146141
/**
147-
* @param {INode["range"]} range
142+
* @param {Deno.lint.Node["range"]} range
148143
* @param {string} text
149144
*/
150145
insertTextBeforeRange(range, text) {
@@ -155,7 +150,7 @@ class Fixer {
155150
}
156151

157152
/**
158-
* @param {INode} node
153+
* @param {Deno.lint.Node} node
159154
*/
160155
remove(node) {
161156
return {
@@ -165,7 +160,7 @@ class Fixer {
165160
}
166161

167162
/**
168-
* @param {INode["range"]} range
163+
* @param {Deno.lint.Node["range"]} range
169164
*/
170165
removeRange(range) {
171166
return {
@@ -175,7 +170,7 @@ class Fixer {
175170
}
176171

177172
/**
178-
* @param {INode} node
173+
* @param {Deno.lint.Node} node
179174
* @param {string} text
180175
*/
181176
replaceText(node, text) {
@@ -186,7 +181,7 @@ class Fixer {
186181
}
187182

188183
/**
189-
* @param {INode["range"]} range
184+
* @param {Deno.lint.Node["range"]} range
190185
* @param {string} text
191186
*/
192187
replaceTextRange(range, text) {
@@ -200,7 +195,7 @@ class Fixer {
200195
/**
201196
* Every rule gets their own instance of this class. This is the main
202197
* API lint rules interact with.
203-
* @implements {RuleContext}
198+
* @implements {Deno.lint.RuleContext}
204199
*/
205200
export class Context {
206201
id;
@@ -226,7 +221,7 @@ export class Context {
226221
}
227222

228223
/**
229-
* @param {IReportData} data
224+
* @param {Deno.lint.ReportData} data
230225
*/
231226
report(data) {
232227
const range = data.node ? data.node.range : data.range ? data.range : null;
@@ -260,7 +255,7 @@ export class Context {
260255
}
261256

262257
/**
263-
* @param {LintPlugin[]} plugins
258+
* @param {Deno.lint.Plugin[]} plugins
264259
* @param {string[]} exclude
265260
*/
266261
export function installPlugins(plugins, exclude) {
@@ -274,7 +269,7 @@ export function installPlugins(plugins, exclude) {
274269
}
275270

276271
/**
277-
* @param {LintPlugin} plugin
272+
* @param {Deno.lint.Plugin} plugin
278273
*/
279274
function installPlugin(plugin) {
280275
if (typeof plugin !== "object") {
@@ -459,7 +454,7 @@ function readType(buf, idx) {
459454
/**
460455
* @param {AstContext} ctx
461456
* @param {number} idx
462-
* @returns {INode["range"]}
457+
* @returns {Deno.lint.Node["range"]}
463458
*/
464459
function readSpan(ctx, idx) {
465460
let offset = ctx.spansOffset + (idx * SPAN_SIZE);

cli/js/40_lint_types.d.ts

+2-52
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

3-
export interface INode {
4-
type: string;
5-
range: [number, number];
6-
[key: string]: unknown;
7-
}
8-
93
export interface AstContext {
104
buf: Uint8Array;
115
strTable: Map<number, string>;
126
strTableOffset: number;
137
rootOffset: number;
14-
nodes: Map<number, INode>;
8+
nodes: Map<number, Deno.lint.Node>;
159
spansOffset: number;
1610
propsOffset: number;
1711
strByType: number[];
@@ -21,52 +15,8 @@ export interface AstContext {
2115
matcher: MatchContext;
2216
}
2317

24-
export type TRange = [number, number];
25-
26-
export interface IFixData {
27-
range: TRange;
28-
text?: string;
29-
}
30-
31-
export interface IFixer {
32-
insertTextAfter(node: INode, text: string): IFixData;
33-
insertTextAfterRange(range: TRange, text: string): IFixData;
34-
insertTextBefore(node: INode, text: string): IFixData;
35-
insertTextBeforeRange(range: TRange, text: string): IFixData;
36-
remove(node: INode): IFixData;
37-
removeRange(range: TRange): IFixData;
38-
replaceText(node: INode, text: string): IFixData;
39-
replaceTextRange(range: TRange, text: string): IFixData;
40-
}
41-
42-
export interface IReportData {
43-
node?: INode;
44-
range?: TRange;
45-
message: string;
46-
hint?: string;
47-
fix?(fixer: IFixer): IFixData;
48-
}
49-
50-
// TODO(@marvinhagemeister) Remove once we land "official" types
51-
export interface RuleContext {
52-
id: string;
53-
report(data: IReportData): void;
54-
}
55-
56-
// TODO(@marvinhagemeister) Remove once we land "official" types
57-
export interface LintRule {
58-
create(ctx: RuleContext): Record<string, (node: unknown) => void>;
59-
destroy?(ctx: RuleContext): void;
60-
}
61-
62-
// TODO(@marvinhagemeister) Remove once we land "official" types
63-
export interface LintPlugin {
64-
name: string;
65-
rules: Record<string, LintRule>;
66-
}
67-
6818
export interface LintState {
69-
plugins: LintPlugin[];
19+
plugins: Deno.lint.Plugin[];
7020
installedPlugins: Set<string>;
7121
/** format: `<plugin>/<rule>` */
7222
ignoredRules: Set<string>;

cli/tsc/dts/lib.deno.unstable.d.ts

+85-18
Original file line numberDiff line numberDiff line change
@@ -1345,30 +1345,97 @@ declare namespace Deno {
13451345
* @category Linter
13461346
* @experimental
13471347
*/
1348-
export interface LintRule {
1349-
create(context: any): any;
1350-
destroy?(context: any): void;
1351-
}
1348+
export namespace lint {
1349+
/**
1350+
* @category Linter
1351+
* @experimental
1352+
*/
1353+
export type Range = [number, number];
13521354

1353-
/**
1354-
* @category Linter
1355-
* @experimental
1356-
*/
1357-
export interface LintPlugin {
1358-
name: string;
1359-
rules: Record<string, LintRule>;
1360-
}
1355+
/**
1356+
* @category Linter
1357+
* @experimental
1358+
*/
1359+
export interface Node {
1360+
type: string;
1361+
range: Range;
1362+
[key: string]: unknown;
1363+
}
1364+
1365+
/**
1366+
* @category Linter
1367+
* @experimental
1368+
*/
1369+
export interface FixData {
1370+
range: Range;
1371+
text?: string;
1372+
}
1373+
1374+
/**
1375+
* @category Linter
1376+
* @experimental
1377+
*/
1378+
export interface Fixer {
1379+
insertTextAfter(node: Node, text: string): FixData;
1380+
insertTextAfterRange(range: Range, text: string): FixData;
1381+
insertTextBefore(node: Node, text: string): FixData;
1382+
insertTextBeforeRange(range: Range, text: string): FixData;
1383+
remove(node: Node): FixData;
1384+
removeRange(range: Range): FixData;
1385+
replaceText(node: Node, text: string): FixData;
1386+
replaceTextRange(range: Range, text: string): FixData;
1387+
}
1388+
1389+
/**
1390+
* @category Linter
1391+
* @experimental
1392+
*/
1393+
export interface ReportData {
1394+
node?: Node;
1395+
range?: Range;
1396+
message: string;
1397+
hint?: string;
1398+
fix?(fixer: Fixer): FixData;
1399+
}
1400+
1401+
/**
1402+
* @category Linter
1403+
* @experimental
1404+
*/
1405+
export interface RuleContext {
1406+
id: string;
1407+
report(data: ReportData): void;
1408+
}
1409+
1410+
export interface Rule {
1411+
create(ctx: RuleContext): Record<string, (node: unknown) => void>;
1412+
destroy?(ctx: RuleContext): void;
1413+
}
1414+
1415+
/**
1416+
* In your plugins file do something like
1417+
*
1418+
* ```ts
1419+
* export default {
1420+
* name: "my-plugin",
1421+
* rules: {
1422+
* TODO:...
1423+
* }
1424+
* } satisfies Deno.lint.Plugin
1425+
* ```
1426+
* @category Linter
1427+
* @experimental
1428+
*/
1429+
export interface Plugin {
1430+
name: string;
1431+
rules: Record<string, Rule>;
1432+
}
13611433

1362-
/**
1363-
* @category Linter
1364-
* @experimental
1365-
*/
1366-
export namespace lint {
13671434
/**
13681435
* @category Linter
13691436
* @experimental
13701437
*/
1371-
export interface LintFix {
1438+
export interface Fix {
13721439
range: [number, number];
13731440
text?: string;
13741441
}

0 commit comments

Comments
 (0)