@biomejs/runtime 2.6.5 → 2.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js_ast.d.ts +14 -0
- package/package.json +2 -2
- package/plugin.d.ts +78 -32
- package/semantic.d.ts +8 -8
package/js_ast.d.ts
CHANGED
|
@@ -1985,6 +1985,17 @@ export interface JsSvelteDeclarationRoot extends JsAstNode {
|
|
|
1985
1985
|
token(field: "semicolonToken" | "eofToken"): JsAstToken | undefined;
|
|
1986
1986
|
token(field: string): JsAstToken | undefined;
|
|
1987
1987
|
}
|
|
1988
|
+
export interface JsSvelteLegacyConstRoot extends JsAstNode {
|
|
1989
|
+
readonly kind: "JS_SVELTE_LEGACY_CONST_ROOT";
|
|
1990
|
+
readonly declarator: AnyJsSvelteLegacyConstDeclarator | undefined;
|
|
1991
|
+
withDeclarator(
|
|
1992
|
+
value: AnyJsSvelteLegacyConstDeclarator,
|
|
1993
|
+
): JsSvelteLegacyConstRoot;
|
|
1994
|
+
readonly eofToken: string | undefined;
|
|
1995
|
+
withEofToken(value: JsAstToken): JsSvelteLegacyConstRoot;
|
|
1996
|
+
token(field: "eofToken"): JsAstToken | undefined;
|
|
1997
|
+
token(field: string): JsAstToken | undefined;
|
|
1998
|
+
}
|
|
1988
1999
|
export interface JsSvelteSnippetRoot extends JsAstNode {
|
|
1989
2000
|
readonly kind: "JS_SVELTE_SNIPPET_ROOT";
|
|
1990
2001
|
readonly name: AnyJsBinding | undefined;
|
|
@@ -4194,6 +4205,7 @@ export type AnyJsRoot =
|
|
|
4194
4205
|
| JsModule
|
|
4195
4206
|
| JsScript
|
|
4196
4207
|
| JsSvelteDeclarationRoot
|
|
4208
|
+
| JsSvelteLegacyConstRoot
|
|
4197
4209
|
| JsSvelteSnippetRoot
|
|
4198
4210
|
| JsVueGenericRoot
|
|
4199
4211
|
| JsVueSlotPropsRoot
|
|
@@ -4235,6 +4247,7 @@ export type AnyJsStatement =
|
|
|
4235
4247
|
export type AnyJsSvelteDeclaration =
|
|
4236
4248
|
| JsBogusVariableDeclaration
|
|
4237
4249
|
| JsVariableDeclaration;
|
|
4250
|
+
export type AnyJsSvelteLegacyConstDeclarator = JsBogus | JsVariableDeclarator;
|
|
4238
4251
|
export type AnyJsSwitchClause = JsCaseClause | JsDefaultClause;
|
|
4239
4252
|
export type AnyJsTemplateElement = JsTemplateChunkElement | JsTemplateElement;
|
|
4240
4253
|
export type AnyJsVueGenericTypeParameters = JsBogus | TsTypeParameterList;
|
|
@@ -4517,6 +4530,7 @@ export interface JsNodeByKind {
|
|
|
4517
4530
|
readonly JS_STRING_LITERAL_EXPRESSION: JsStringLiteralExpression;
|
|
4518
4531
|
readonly JS_SUPER_EXPRESSION: JsSuperExpression;
|
|
4519
4532
|
readonly JS_SVELTE_DECLARATION_ROOT: JsSvelteDeclarationRoot;
|
|
4533
|
+
readonly JS_SVELTE_LEGACY_CONST_ROOT: JsSvelteLegacyConstRoot;
|
|
4520
4534
|
readonly JS_SVELTE_SNIPPET_ROOT: JsSvelteSnippetRoot;
|
|
4521
4535
|
readonly JS_SWITCH_STATEMENT: JsSwitchStatement;
|
|
4522
4536
|
readonly JS_TEMPLATE_CHUNK_ELEMENT: JsTemplateChunkElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biomejs/runtime",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.7",
|
|
4
4
|
"description": "JavaScript APIs for Biome JS plugins",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test:types": "tsc --project tsconfig.json"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "7.0.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@biomejs/biome": "^2.6.
|
|
37
|
+
"@biomejs/biome": "^2.6.7"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"provenance": true
|
package/plugin.d.ts
CHANGED
|
@@ -14,24 +14,43 @@ export * from "./js_ast";
|
|
|
14
14
|
export * from "./semantic";
|
|
15
15
|
|
|
16
16
|
declare const queriedNode: unique symbol;
|
|
17
|
+
declare const queryContext: unique symbol;
|
|
17
18
|
declare const nativeMutation: unique symbol;
|
|
18
19
|
declare const nodeKindSet: unique symbol;
|
|
19
20
|
declare const tokenKindSet: unique symbol;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* A query
|
|
23
|
+
* A query created with {@link ast} or {@link grit}.
|
|
23
24
|
*
|
|
24
25
|
* `N` is the union of the node types matched by the query; it only exists at
|
|
25
26
|
* the type level, to infer the argument type of {@link Rule#run}.
|
|
26
27
|
*/
|
|
27
|
-
interface Query<N extends JsAstNode
|
|
28
|
-
readonly type:
|
|
29
|
-
readonly kinds: readonly (keyof JsNodeByKind)[];
|
|
28
|
+
interface Query<N extends JsAstNode | JsAstToken, C> {
|
|
29
|
+
readonly type: "ast" | "grit";
|
|
30
30
|
readonly [queriedNode]?: N;
|
|
31
|
+
readonly [queryContext]?: C;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export
|
|
34
|
-
|
|
34
|
+
export interface AstQuery<N extends JsAstNode, C = RuleContext>
|
|
35
|
+
extends Query<N, C> {
|
|
36
|
+
readonly type: "ast";
|
|
37
|
+
readonly kinds: readonly (keyof JsNodeByKind)[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A query matching the nodes and tokens selected by a GritQL pattern, created
|
|
42
|
+
* with {@link grit}.
|
|
43
|
+
*/
|
|
44
|
+
export interface GritQuery<C = RuleContext> extends Query<JsAstElement, C> {
|
|
45
|
+
readonly type: "grit";
|
|
46
|
+
readonly pattern: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A Grit query created with `semantic: true`, whose `run` receives a semantic
|
|
51
|
+
* model.
|
|
52
|
+
*/
|
|
53
|
+
export type SemanticGritQuery = GritQuery<SemanticRuleContext>;
|
|
35
54
|
|
|
36
55
|
/** File information supplied to each invocation of a rule. */
|
|
37
56
|
export interface RuleContext {
|
|
@@ -47,11 +66,6 @@ export interface SemanticRuleContext extends RuleContext {
|
|
|
47
66
|
readonly model: SemanticModel;
|
|
48
67
|
}
|
|
49
68
|
|
|
50
|
-
type ContextByQuery = {
|
|
51
|
-
ast: RuleContext;
|
|
52
|
-
semantic: SemanticRuleContext;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
69
|
/** JavaScript or TypeScript parsing settings for the analyzed source. */
|
|
56
70
|
export interface JsFileSource {
|
|
57
71
|
readonly language:
|
|
@@ -94,17 +108,14 @@ export type JsEmbeddingKind =
|
|
|
94
108
|
* A lint rule, created with {@link defineRule} and exported from the plugin
|
|
95
109
|
* with `export const`. The name of the export is used as the rule name.
|
|
96
110
|
*/
|
|
97
|
-
export interface Rule<
|
|
98
|
-
N extends JsAstNode,
|
|
99
|
-
K extends keyof ContextByQuery = "ast",
|
|
100
|
-
> {
|
|
111
|
+
export interface Rule<N extends JsAstElement, C = RuleContext> {
|
|
101
112
|
/**
|
|
102
113
|
* The query selecting the nodes the rule runs on.
|
|
103
114
|
*/
|
|
104
|
-
readonly query: Query<N,
|
|
115
|
+
readonly query: Query<N, C>;
|
|
105
116
|
|
|
106
117
|
/**
|
|
107
|
-
* Called with every node matching the query.
|
|
118
|
+
* Called with every node, or token for Grit queries, matching the query.
|
|
108
119
|
* `context` information is read-only
|
|
109
120
|
*
|
|
110
121
|
* For example, inspect declarations only in TypeScript sources:
|
|
@@ -118,23 +129,18 @@ export interface Rule<
|
|
|
118
129
|
* });
|
|
119
130
|
* ```
|
|
120
131
|
*/
|
|
121
|
-
readonly run: (node: NoInfer<N>, context: NoInfer<
|
|
132
|
+
readonly run: (node: NoInfer<N>, context: NoInfer<C>) => void;
|
|
122
133
|
}
|
|
123
134
|
|
|
124
135
|
/**
|
|
125
136
|
* Creates a query matching every node of the given syntax kinds.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
...kinds: K
|
|
129
|
-
): AstQuery<JsNodeByKind[K[number]]>;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Matches nodes by their syntax kinds and provides a semantic model in `context`.
|
|
137
|
+
*
|
|
138
|
+
* Pass `{ semantic: true }` to provide a semantic model in `context`.
|
|
133
139
|
*
|
|
134
140
|
* For example, inspect every read of a declared binding:
|
|
135
141
|
* ```ts
|
|
136
142
|
* export const inspectReads = defineRule({
|
|
137
|
-
* query:
|
|
143
|
+
* query: ast("JS_IDENTIFIER_BINDING", { semantic: true }),
|
|
138
144
|
* run(node, context) {
|
|
139
145
|
* const binding = context.model.asBinding(node);
|
|
140
146
|
* for (const reference of binding?.allReads() ?? []) {
|
|
@@ -144,18 +150,58 @@ export function ast<K extends readonly (keyof JsNodeByKind)[]>(
|
|
|
144
150
|
* });
|
|
145
151
|
* ```
|
|
146
152
|
*/
|
|
147
|
-
export function
|
|
153
|
+
export function ast<K extends readonly (keyof JsNodeByKind)[]>(
|
|
148
154
|
...kinds: K
|
|
149
|
-
):
|
|
155
|
+
): AstQuery<JsNodeByKind[K[number]]>;
|
|
156
|
+
export function ast<K extends readonly (keyof JsNodeByKind)[]>(
|
|
157
|
+
...kinds: [...K, { semantic: true }]
|
|
158
|
+
): AstQuery<JsNodeByKind[K[number]], SemanticRuleContext>;
|
|
159
|
+
export function ast<K extends readonly (keyof JsNodeByKind)[]>(
|
|
160
|
+
...kinds: [...K, { semantic?: false }]
|
|
161
|
+
): AstQuery<JsNodeByKind[K[number]]>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Creates a query matching the nodes selected by a GritQL pattern.
|
|
165
|
+
*
|
|
166
|
+
* The pattern runs against the analyzed file and `run` is called once for each
|
|
167
|
+
* match. When the pattern matches a list, such as several sibling statements,
|
|
168
|
+
* `run` is called for each node in the list. Patterns may also match leaf
|
|
169
|
+
* tokens, in which case `run` receives a token.
|
|
170
|
+
*
|
|
171
|
+
* The pattern cannot contain a rewrite. Report diagnostics from `run`
|
|
172
|
+
* instead. When the pattern matches a token, `run` receives a token and
|
|
173
|
+
* diagnostics can be reported on its `parent` node.
|
|
174
|
+
*
|
|
175
|
+
* Pass `{ semantic: true }` to provide a semantic model in `context`.
|
|
176
|
+
*
|
|
177
|
+
* For example, inspect console calls without a fixed list of syntax kinds:
|
|
178
|
+
* ```ts
|
|
179
|
+
* export const noConsole = defineRule({
|
|
180
|
+
* query: grit("`console.log($args)`"),
|
|
181
|
+
* run(element) {
|
|
182
|
+
* if (element.kind !== "JS_CALL_EXPRESSION") return;
|
|
183
|
+
* registerDiagnostic(element, "warning", "Unexpected console.log.");
|
|
184
|
+
* },
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export function grit(pattern: string): GritQuery;
|
|
189
|
+
export function grit(
|
|
190
|
+
pattern: string,
|
|
191
|
+
options: { semantic: true },
|
|
192
|
+
): SemanticGritQuery;
|
|
193
|
+
export function grit(
|
|
194
|
+
pattern: string,
|
|
195
|
+
options?: { semantic?: false },
|
|
196
|
+
): GritQuery;
|
|
150
197
|
|
|
151
198
|
/**
|
|
152
199
|
* Defines a lint rule. Export the returned rule with `export const` to
|
|
153
200
|
* register it to the analyzer.
|
|
154
201
|
*/
|
|
155
|
-
export function defineRule<
|
|
156
|
-
N
|
|
157
|
-
|
|
158
|
-
>(rule: Rule<N, K>): Rule<N, K>;
|
|
202
|
+
export function defineRule<N extends JsAstElement, C = RuleContext>(
|
|
203
|
+
rule: Rule<N, C>,
|
|
204
|
+
): Rule<N, C>;
|
|
159
205
|
|
|
160
206
|
/**
|
|
161
207
|
* Collects replacements and removals for one code fix without changing the
|
package/semantic.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export interface TextRange {
|
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* Bindings and references in one analyzed source snapshot.
|
|
70
|
-
* Access it through `context.model` in a rule using `semantic
|
|
70
|
+
* Access it through `context.model` in a rule using `ast(..., { semantic: true })`.
|
|
71
71
|
*
|
|
72
72
|
* Node arguments must belong to this model's source. Saved models and handles
|
|
73
73
|
* retain their original source; prepared code fixes do not update the model.
|
|
@@ -79,7 +79,7 @@ export interface SemanticModel {
|
|
|
79
79
|
* Resolves an identifier use to the binding it refers to, respecting shadowing.
|
|
80
80
|
* Returns `undefined` for configured globals and unresolved references.
|
|
81
81
|
*
|
|
82
|
-
* In a rule querying `
|
|
82
|
+
* In a rule querying `ast("JS_REFERENCE_IDENTIFIER", { semantic: true })`, highlight the
|
|
83
83
|
* declaration of the referenced name:
|
|
84
84
|
* ```ts
|
|
85
85
|
* const binding = context.model.binding(node);
|
|
@@ -93,7 +93,7 @@ export interface SemanticModel {
|
|
|
93
93
|
* Looks up the binding introduced by a declaration's identifier node.
|
|
94
94
|
* Returns `undefined` when the model does not track that declaration.
|
|
95
95
|
*
|
|
96
|
-
* In a rule querying `
|
|
96
|
+
* In a rule querying `ast("JS_IDENTIFIER_BINDING", { semantic: true })`, report how many
|
|
97
97
|
* references resolve to the declaration:
|
|
98
98
|
* ```ts
|
|
99
99
|
* const binding = context.model.asBinding(node);
|
|
@@ -185,7 +185,7 @@ export interface SemanticModel {
|
|
|
185
185
|
* Returns the scope a declaration's identifier was hoisted to, if the model
|
|
186
186
|
* records one. This can differ from the scope containing its source text.
|
|
187
187
|
*
|
|
188
|
-
* In a rule querying `
|
|
188
|
+
* In a rule querying `ast("JS_IDENTIFIER_BINDING", { semantic: true })`, inspect hoisting:
|
|
189
189
|
* ```ts
|
|
190
190
|
* const scope = context.model.scopeHoistedTo(node);
|
|
191
191
|
* if (scope) {
|
|
@@ -222,7 +222,7 @@ export interface SemanticModel {
|
|
|
222
222
|
* Returns whether an identifier use resolves to a configured global.
|
|
223
223
|
* Returns `false` for local bindings and unresolved references.
|
|
224
224
|
*
|
|
225
|
-
* In a rule querying `
|
|
225
|
+
* In a rule querying `ast("JS_REFERENCE_IDENTIFIER", { semantic: true })`, distinguish
|
|
226
226
|
* configured globals from other identifier uses:
|
|
227
227
|
* ```ts
|
|
228
228
|
* if (context.model.isGlobalReference(node)) {
|
|
@@ -235,7 +235,7 @@ export interface SemanticModel {
|
|
|
235
235
|
* Returns whether an identifier use has no local binding or configured global.
|
|
236
236
|
* A reference to a declaration later in the source can still resolve.
|
|
237
237
|
*
|
|
238
|
-
* In a rule querying `
|
|
238
|
+
* In a rule querying `ast("JS_REFERENCE_IDENTIFIER", { semantic: true })`, report names the
|
|
239
239
|
* model cannot resolve:
|
|
240
240
|
* ```ts
|
|
241
241
|
* if (context.model.isUnresolvedReference(node)) {
|
|
@@ -248,7 +248,7 @@ export interface SemanticModel {
|
|
|
248
248
|
* Returns whether a declaration is imported, or a reference resolves to an
|
|
249
249
|
* imported declaration. Returns `false` when a reference has no local binding.
|
|
250
250
|
*
|
|
251
|
-
* In a rule querying `
|
|
251
|
+
* In a rule querying `ast("JS_REFERENCE_IDENTIFIER", { semantic: true })`, highlight uses
|
|
252
252
|
* of imported names:
|
|
253
253
|
* ```ts
|
|
254
254
|
* if (context.model.isImported(node)) {
|
|
@@ -261,7 +261,7 @@ export interface SemanticModel {
|
|
|
261
261
|
* Returns whether a declaration is exported, or a reference resolves to an
|
|
262
262
|
* exported declaration. Returns `false` when a reference has no local binding.
|
|
263
263
|
*
|
|
264
|
-
* In a rule querying `
|
|
264
|
+
* In a rule querying `ast("JS_IDENTIFIER_BINDING", { semantic: true })`, highlight exported
|
|
265
265
|
* declarations:
|
|
266
266
|
* ```ts
|
|
267
267
|
* if (context.model.isExported(node)) {
|