corsa-oxlint 0.10.0 → 0.12.0

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/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # corsa-oxlint
1
+ # corsa oxlint
2
2
 
3
- `corsa-oxlint` is a self-hosted type-aware framework for building Oxlint JS
4
- plugins with real type information powered by `tsgo`.
3
+ `corsa oxlint` is a self-hosted type-aware framework for building Oxlint JS
4
+ plugins with real type information powered by Corsa.
5
5
 
6
6
  > [!WARNING]
7
7
  > This package is still an early WIP.
8
8
  > The core direction is stable, but the API surface will keep moving while
9
- > `typescript-go`, Oxlint's JS plugin APIs, and the surrounding benchmarks are
9
+ > Corsa upstream, Oxlint's JS plugin APIs, and the surrounding benchmarks are
10
10
  > still evolving.
11
11
 
12
12
  ## What It Does
13
13
 
14
- - exposes `OxlintUtils.RuleCreator()` and `getParserServices()` backed by `tsgo`
14
+ - exposes `OxlintUtils.RuleCreator()` and `getParserServices()` backed by Corsa
15
15
  - exposes compatibility namespaces such as `ESLintUtils`, `TSESLint`, `TSESTree`, and `TSUtils`
16
16
  - keeps a compact self-hosted helper surface with no extra lint-framework dependency
17
17
  - binds Rust-implemented hot paths into JS through `napi-rs`
@@ -26,7 +26,7 @@ custom rules in plain JS/TS.
26
26
  ## Configuration
27
27
 
28
28
  Oxlint does not expose arbitrary parser options at runtime, so
29
- `corsa-oxlint` reads its type-aware settings from `settings.typescriptOxlint`.
29
+ `corsa oxlint` reads its type-aware settings from `settings.typescriptOxlint`.
30
30
 
31
31
  ```ts
32
32
  import { OxlintUtils } from "corsa-oxlint";
@@ -80,7 +80,7 @@ export default [
80
80
  parserOptions: {
81
81
  project: ["./tsconfig.json"],
82
82
  tsconfigRootDir: import.meta.dirname,
83
- tsgo: {
83
+ corsa: {
84
84
  executable: "./.cache/tsgo",
85
85
  mode: "msgpack",
86
86
  requestTimeoutMs: 30000,
@@ -94,7 +94,7 @@ export default [
94
94
 
95
95
  ## Native Rules
96
96
 
97
- `corsa-oxlint/rules` exports the TS-native rule set and plugin surface.
97
+ `corsa oxlint` exports the TS-native rule set and plugin surface via `corsa-oxlint/rules`.
98
98
  Rule parity is tracked against upstream `tsgolint/internal/rules`, but the
99
99
  runtime implementation lives entirely in this package.
100
100
 
@@ -128,7 +128,7 @@ General-purpose built-in rules can be implemented as Rust rules and still ship
128
128
  as Oxlint JS plugin rules. The bridge is:
129
129
 
130
130
  1. Oxlint visits the ESTree node in JS.
131
- 2. `corsa-oxlint` collects compact node facts and type texts.
131
+ 2. `corsa oxlint` collects compact node facts and type texts.
132
132
  3. `@corsa-bind/napi` calls `corsa::lint::RustLintRule`.
133
133
  4. Rust returns Oxlint-shaped diagnostics, suggestions, and fixes.
134
134
  5. The JS rule reports them through `context.report()`.
package/dist/checker.js CHANGED
@@ -27,6 +27,7 @@ function createProgram(context) {
27
27
  function createTypeChecker(context) {
28
28
  return {
29
29
  getTypeAtLocation(node) {
30
+ if (node.type === "NewExpression") return typeOfNewExpression(node, this);
30
31
  const lookupNode = nodeForTypeLookup(node);
31
32
  return sessionForContext(context).session.getTypeAtPosition(filenameFor(context, lookupNode), toPosition(lookupNode), sourceTextFor(context, lookupNode));
32
33
  },
@@ -37,6 +38,18 @@ function createTypeChecker(context) {
37
38
  const lookupNode = nodeForTypeLookup(node);
38
39
  return sessionForContext(context).session.getSymbolAtPosition(filenameFor(context, lookupNode), toPosition(lookupNode), sourceTextFor(context, lookupNode));
39
40
  },
41
+ getSymbol(symbol) {
42
+ return sessionForContext(context).session.getSymbol(symbol);
43
+ },
44
+ getSymbolById(id) {
45
+ return sessionForContext(context).session.getSymbol(id);
46
+ },
47
+ getNode(node) {
48
+ return sessionForContext(context).session.getNode(node);
49
+ },
50
+ getNodeById(id) {
51
+ return sessionForContext(context).session.getNode(id);
52
+ },
40
53
  getTypeOfSymbol(symbol) {
41
54
  return sessionForContext(context).session.getTypeOfSymbol(symbol);
42
55
  },
@@ -68,19 +81,76 @@ function createTypeChecker(context) {
68
81
  return sessionForContext(context).session.getBaseTypes(type);
69
82
  },
70
83
  getImplementedTypes(node) {
84
+ if ("pos" in node) return implementedTypesFromTsgoNode(context, node, this);
71
85
  return implementedClauseNodes(node).map((clause) => {
72
86
  const expression = implementedClauseChildNode(clause, "expression") ?? clause;
73
87
  const symbol = this.getSymbolAtLocation(expression) ?? this.getSymbolAtLocation(clause);
74
88
  return symbol ? this.getDeclaredTypeOfSymbol(symbol) ?? this.getTypeOfSymbol(symbol) : this.getTypeAtLocation(expression) ?? this.getTypeAtLocation(clause);
75
89
  }).filter((type) => type !== void 0);
76
90
  },
91
+ getImplementedTypesOfType(type) {
92
+ return sessionForContext(context).session.getBaseTypes(type);
93
+ },
77
94
  getTypeArguments(type) {
78
95
  return sessionForContext(context).session.getTypeArguments(type);
96
+ },
97
+ getTypesOfType(type) {
98
+ return sessionForContext(context).session.getTypesOfType(type);
99
+ },
100
+ getTargetOfType(type) {
101
+ return sessionForContext(context).session.getTargetOfType(type);
102
+ },
103
+ getTypeParametersOfType(type) {
104
+ return sessionForContext(context).session.getTypeParametersOfType(type);
105
+ },
106
+ getOuterTypeParametersOfType(type) {
107
+ return sessionForContext(context).session.getOuterTypeParametersOfType(type);
108
+ },
109
+ getLocalTypeParametersOfType(type) {
110
+ return sessionForContext(context).session.getLocalTypeParametersOfType(type);
111
+ },
112
+ getObjectTypeOfType(type) {
113
+ return sessionForContext(context).session.getObjectTypeOfType(type);
114
+ },
115
+ getIndexTypeOfType(type) {
116
+ return sessionForContext(context).session.getIndexTypeOfType(type);
117
+ },
118
+ getCheckTypeOfType(type) {
119
+ return sessionForContext(context).session.getCheckTypeOfType(type);
120
+ },
121
+ getExtendsTypeOfType(type) {
122
+ return sessionForContext(context).session.getExtendsTypeOfType(type);
123
+ },
124
+ getBaseTypeOfType(type) {
125
+ return sessionForContext(context).session.getBaseTypeOfType(type);
126
+ },
127
+ getConstraintOfType(type) {
128
+ return sessionForContext(context).session.getConstraintOfType(type);
129
+ },
130
+ isUnionType(type) {
131
+ return (type.flags & typeFlags.union) !== 0;
132
+ },
133
+ isIntersectionType(type) {
134
+ return (type.flags & typeFlags.intersection) !== 0;
79
135
  }
80
136
  };
81
137
  }
138
+ const typeFlags = {
139
+ union: 1 << 27,
140
+ intersection: 1 << 28
141
+ };
82
142
  function sourceTextFor(context, node) {
83
- return filenameFor(context, node) === context.filename ? context.sourceCode.text : void 0;
143
+ const normalizedFileName = filenameFor(context, node).toLowerCase();
144
+ const normalizedContextFilename = context.filename.toLowerCase();
145
+ return normalizedFileName === normalizedContextFilename || normalizedFileName.endsWith(normalizedContextFilename) || normalizedContextFilename.endsWith(normalizedFileName) ? context.sourceCode.text : void 0;
146
+ }
147
+ function typeOfNewExpression(node, checker) {
148
+ const callee = childNode(node, "callee");
149
+ if (!callee) return;
150
+ const calleeType = checker.getTypeAtLocation(callee);
151
+ if (!calleeType) return;
152
+ const constructSignature = checker.getSignaturesOfType(calleeType, 1)[0];
153
+ return constructSignature ? checker.getReturnTypeOfSignature(constructSignature) ?? calleeType : calleeType;
84
154
  }
85
155
  function nodeForTypeLookup(node) {
86
156
  if ("pos" in node) return node;
@@ -105,6 +175,94 @@ function implementedClauseChildNode(node, key) {
105
175
  const value = node[key];
106
176
  if (isNode(value)) return value;
107
177
  }
178
+ function implementedTypesFromTsgoNode(context, node, checker) {
179
+ const symbol = checker.getSymbolAtLocation(node);
180
+ if (symbol) {
181
+ const declaredType = checker.getDeclaredTypeOfSymbol(symbol) ?? checker.getTypeOfSymbol(symbol);
182
+ if (declaredType) {
183
+ const implemented = checker.getImplementedTypesOfType(declaredType);
184
+ if (implemented.length > 0) return implemented;
185
+ }
186
+ }
187
+ const sourceText = sourceTextFor(context, node);
188
+ if (sourceText) {
189
+ const classText = sourceText.slice(node.pos, node.end);
190
+ const bodyOpen = classText.indexOf("{");
191
+ const headerText = bodyOpen >= 0 ? classText.slice(0, bodyOpen) : classText;
192
+ const implementsIndex = headerText.indexOf("implements");
193
+ if (implementsIndex >= 0) {
194
+ const clauseText = headerText.slice(implementsIndex + 10);
195
+ return splitTopLevelRanges(clauseText, ",").map((range) => {
196
+ const raw = clauseText.slice(range.start, range.end);
197
+ const leading = raw.search(/\S/);
198
+ if (leading < 0) return;
199
+ const trailing = raw.match(/\s*$/)?.[0].length ?? 0;
200
+ const pos = node.pos + implementsIndex + 10 + range.start + leading;
201
+ const end = node.pos + implementsIndex + 10 + range.end - trailing;
202
+ const lookupNode = {
203
+ fileName: node.fileName,
204
+ pos,
205
+ end,
206
+ range: [pos, end]
207
+ };
208
+ const symbol = checker.getSymbolAtLocation(lookupNode);
209
+ return symbol ? checker.getDeclaredTypeOfSymbol(symbol) ?? checker.getTypeOfSymbol(symbol) : checker.getTypeAtLocation(lookupNode);
210
+ }).filter((type) => type !== void 0);
211
+ }
212
+ }
213
+ const type = checker.getTypeAtLocation(node);
214
+ return type ? checker.getImplementedTypesOfType(type) : [];
215
+ }
216
+ function splitTopLevelRanges(text, delimiter) {
217
+ const ranges = [];
218
+ const scanner = createScanner();
219
+ let start = 0;
220
+ let angleDepth = 0;
221
+ let parenDepth = 0;
222
+ let bracketDepth = 0;
223
+ let braceDepth = 0;
224
+ for (let index = 0; index < text.length; index += 1) {
225
+ const char = text[index];
226
+ if (scanner.inQuote(char)) continue;
227
+ if (char === "<") angleDepth += 1;
228
+ else if (char === ">") angleDepth = Math.max(0, angleDepth - 1);
229
+ else if (char === "(") parenDepth += 1;
230
+ else if (char === ")") parenDepth = Math.max(0, parenDepth - 1);
231
+ else if (char === "[") bracketDepth += 1;
232
+ else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
233
+ else if (char === "{") braceDepth += 1;
234
+ else if (char === "}") braceDepth = Math.max(0, braceDepth - 1);
235
+ else if (char === delimiter && angleDepth === 0 && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
236
+ ranges.push({
237
+ start,
238
+ end: index
239
+ });
240
+ start = index + 1;
241
+ }
242
+ }
243
+ ranges.push({
244
+ start,
245
+ end: text.length
246
+ });
247
+ return ranges;
248
+ }
249
+ function createScanner() {
250
+ let quote;
251
+ let escaped = false;
252
+ return { inQuote(char) {
253
+ if (quote) {
254
+ if (escaped) escaped = false;
255
+ else if (char === "\\") escaped = true;
256
+ else if (char === quote) quote = void 0;
257
+ return true;
258
+ }
259
+ if (char === "\"" || char === "'" || char === "`") {
260
+ quote = char;
261
+ return true;
262
+ }
263
+ return false;
264
+ } };
265
+ }
108
266
  function isNode(value) {
109
267
  return typeof value === "object" && value !== null && "type" in value && "range" in value;
110
268
  }
@@ -1 +1 @@
1
- {"version":3,"file":"checker.js","names":[],"sources":["../ts/checker.ts"],"sourcesContent":["import type { Node } from \"@oxlint/plugins\";\n\nimport { createNodeMaps, toPosition } from \"./node_map\";\nimport { sessionForContext } from \"./registry\";\nimport type {\n ContextWithParserOptions,\n TsgoNode,\n TsgoProgramShape,\n TsgoSignature,\n TsgoSymbol,\n TsgoType,\n TsgoTypeCheckerShape,\n} from \"./types\";\n\nexport function createProgram(\n context: ContextWithParserOptions,\n): TsgoProgramShape & { readonly nodeMaps: ReturnType<typeof createNodeMaps> } {\n const nodeMaps = createNodeMaps(context);\n return {\n nodeMaps,\n getCompilerOptions() {\n return sessionForContext(context).session.getCompilerOptions();\n },\n getCurrentDirectory() {\n return sessionForContext(context).project.rootDir;\n },\n getRootFileNames() {\n return sessionForContext(context).session.getRootFileNames();\n },\n getSourceFile(fileName = context.filename) {\n return { fileName, text: context.sourceCode.text };\n },\n getTypeChecker() {\n return createTypeChecker(context);\n },\n };\n}\n\nexport function createTypeChecker(context: ContextWithParserOptions): TsgoTypeCheckerShape {\n return {\n getTypeAtLocation(node) {\n const lookupNode = nodeForTypeLookup(node);\n return sessionForContext(context).session.getTypeAtPosition(\n filenameFor(context, lookupNode),\n toPosition(lookupNode),\n sourceTextFor(context, lookupNode),\n );\n },\n getContextualType(node) {\n return this.getTypeAtLocation(node);\n },\n getSymbolAtLocation(node) {\n const lookupNode = nodeForTypeLookup(node);\n return sessionForContext(context).session.getSymbolAtPosition(\n filenameFor(context, lookupNode),\n toPosition(lookupNode),\n sourceTextFor(context, lookupNode),\n );\n },\n getTypeOfSymbol(symbol) {\n return sessionForContext(context).session.getTypeOfSymbol(symbol);\n },\n getDeclaredTypeOfSymbol(symbol) {\n return sessionForContext(context).session.getDeclaredTypeOfSymbol(symbol);\n },\n getTypeOfSymbolAtLocation(symbol, node) {\n return this.getTypeAtLocation(node) ?? this.getTypeOfSymbol(symbol);\n },\n typeToString(type, enclosingDeclaration, flags) {\n void enclosingDeclaration;\n return sessionForContext(context).session.typeToString(type, flags);\n },\n getBaseTypeOfLiteralType(type) {\n return sessionForContext(context).session.getBaseTypeOfLiteralType(type);\n },\n getPropertiesOfType(type) {\n return sessionForContext(context).session.getPropertiesOfType(type);\n },\n getSignaturesOfType(type, kind) {\n return sessionForContext(context).session.getSignaturesOfType(type, kind);\n },\n getReturnTypeOfSignature(signature) {\n return sessionForContext(context).session.getReturnTypeOfSignature(signature);\n },\n getTypePredicateOfSignature(signature) {\n return sessionForContext(context).session.getTypePredicateOfSignature(signature);\n },\n getBaseTypes(type) {\n return sessionForContext(context).session.getBaseTypes(type);\n },\n getImplementedTypes(node) {\n return implementedClauseNodes(node)\n .map((clause) => {\n const expression = implementedClauseChildNode(clause, \"expression\") ?? clause;\n const symbol = this.getSymbolAtLocation(expression) ?? this.getSymbolAtLocation(clause);\n return symbol\n ? (this.getDeclaredTypeOfSymbol(symbol) ?? this.getTypeOfSymbol(symbol))\n : (this.getTypeAtLocation(expression) ?? this.getTypeAtLocation(clause));\n })\n .filter((type): type is TsgoType => type !== undefined);\n },\n getTypeArguments(type) {\n return sessionForContext(context).session.getTypeArguments(type);\n },\n };\n}\n\nfunction sourceTextFor(\n context: ContextWithParserOptions,\n node: Node | TsgoNode | TsgoType | TsgoSymbol | TsgoSignature,\n): string | undefined {\n return filenameFor(context, node) === context.filename ? context.sourceCode.text : undefined;\n}\n\nfunction nodeForTypeLookup(node: Node | TsgoNode): Node | TsgoNode {\n if (\"pos\" in node) {\n return node;\n }\n switch ((node as { readonly type?: string }).type) {\n case \"ClassDeclaration\":\n case \"ClassExpression\":\n return childNode(node, \"id\") ?? node;\n case \"TSPropertySignature\":\n return childNode(node, \"key\") ?? node;\n default:\n return node;\n }\n}\n\nfunction childNode(node: Node, key: string): Node | undefined {\n const value = (node as unknown as Record<string, unknown>)[key];\n if (isNode(value)) {\n return value;\n }\n return undefined;\n}\n\nfunction implementedClauseNodes(node: Node | TsgoNode): readonly Node[] {\n if (\"pos\" in node) {\n return [];\n }\n const clauses = (node as unknown as { readonly implements?: unknown }).implements;\n if (!Array.isArray(clauses)) {\n return [];\n }\n return clauses.filter(isNode);\n}\n\nfunction implementedClauseChildNode(node: Node, key: string): Node | undefined {\n const value = (node as unknown as Record<string, unknown>)[key];\n if (isNode(value)) {\n return value;\n }\n return undefined;\n}\n\nfunction isNode(value: unknown): value is Node {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"range\" in value;\n}\n\nfunction filenameFor(\n context: ContextWithParserOptions,\n node: Node | TsgoNode | TsgoType | TsgoSymbol | TsgoSignature,\n): string {\n if (\"fileName\" in node) {\n return node.fileName;\n }\n return context.filename;\n}\n"],"mappings":";;;AAcA,SAAgB,cACd,SAC6E;CAE7E,OAAO;EACL,UAFe,eAAe,QAEtB;EACR,qBAAqB;GACnB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,oBAAoB;;EAEhE,sBAAsB;GACpB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ;;EAE5C,mBAAmB;GACjB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,kBAAkB;;EAE9D,cAAc,WAAW,QAAQ,UAAU;GACzC,OAAO;IAAE;IAAU,MAAM,QAAQ,WAAW;IAAM;;EAEpD,iBAAiB;GACf,OAAO,kBAAkB,QAAQ;;EAEpC;;AAGH,SAAgB,kBAAkB,SAAyD;CACzF,OAAO;EACL,kBAAkB,MAAM;GACtB,M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
+ {"version":3,"file":"checker.js","names":[],"sources":["../ts/checker.ts"],"sourcesContent":["import type { Node } from \"@oxlint/plugins\";\n\nimport { createNodeMaps, toPosition } from \"./node_map\";\nimport { sessionForContext } from \"./registry\";\nimport type {\n ContextWithParserOptions,\n TsgoNode,\n TsgoProgramShape,\n TsgoSignature,\n TsgoSymbol,\n TsgoType,\n TsgoTypeCheckerShape,\n} from \"./types\";\n\nexport function createProgram(\n context: ContextWithParserOptions,\n): TsgoProgramShape & { readonly nodeMaps: ReturnType<typeof createNodeMaps> } {\n const nodeMaps = createNodeMaps(context);\n return {\n nodeMaps,\n getCompilerOptions() {\n return sessionForContext(context).session.getCompilerOptions();\n },\n getCurrentDirectory() {\n return sessionForContext(context).project.rootDir;\n },\n getRootFileNames() {\n return sessionForContext(context).session.getRootFileNames();\n },\n getSourceFile(fileName = context.filename) {\n return { fileName, text: context.sourceCode.text };\n },\n getTypeChecker() {\n return createTypeChecker(context);\n },\n };\n}\n\nexport function createTypeChecker(context: ContextWithParserOptions): TsgoTypeCheckerShape {\n return {\n getTypeAtLocation(node) {\n if ((node as { readonly type?: string }).type === \"NewExpression\") {\n return typeOfNewExpression(node as Node, this);\n }\n const lookupNode = nodeForTypeLookup(node);\n return sessionForContext(context).session.getTypeAtPosition(\n filenameFor(context, lookupNode),\n toPosition(lookupNode),\n sourceTextFor(context, lookupNode),\n );\n },\n getContextualType(node) {\n return this.getTypeAtLocation(node);\n },\n getSymbolAtLocation(node) {\n const lookupNode = nodeForTypeLookup(node);\n return sessionForContext(context).session.getSymbolAtPosition(\n filenameFor(context, lookupNode),\n toPosition(lookupNode),\n sourceTextFor(context, lookupNode),\n );\n },\n getSymbol(symbol) {\n return sessionForContext(context).session.getSymbol(symbol);\n },\n getSymbolById(id) {\n return sessionForContext(context).session.getSymbol(id);\n },\n getNode(node) {\n return sessionForContext(context).session.getNode(node);\n },\n getNodeById(id) {\n return sessionForContext(context).session.getNode(id);\n },\n getTypeOfSymbol(symbol) {\n return sessionForContext(context).session.getTypeOfSymbol(symbol);\n },\n getDeclaredTypeOfSymbol(symbol) {\n return sessionForContext(context).session.getDeclaredTypeOfSymbol(symbol);\n },\n getTypeOfSymbolAtLocation(symbol, node) {\n return this.getTypeAtLocation(node) ?? this.getTypeOfSymbol(symbol);\n },\n typeToString(type, enclosingDeclaration, flags) {\n void enclosingDeclaration;\n return sessionForContext(context).session.typeToString(type, flags);\n },\n getBaseTypeOfLiteralType(type) {\n return sessionForContext(context).session.getBaseTypeOfLiteralType(type);\n },\n getPropertiesOfType(type) {\n return sessionForContext(context).session.getPropertiesOfType(type);\n },\n getSignaturesOfType(type, kind) {\n return sessionForContext(context).session.getSignaturesOfType(type, kind);\n },\n getReturnTypeOfSignature(signature) {\n return sessionForContext(context).session.getReturnTypeOfSignature(signature);\n },\n getTypePredicateOfSignature(signature) {\n return sessionForContext(context).session.getTypePredicateOfSignature(signature);\n },\n getBaseTypes(type) {\n return sessionForContext(context).session.getBaseTypes(type);\n },\n getImplementedTypes(node) {\n if (\"pos\" in node) {\n return implementedTypesFromTsgoNode(context, node, this);\n }\n return implementedClauseNodes(node)\n .map((clause) => {\n const expression = implementedClauseChildNode(clause, \"expression\") ?? clause;\n const symbol = this.getSymbolAtLocation(expression) ?? this.getSymbolAtLocation(clause);\n return symbol\n ? (this.getDeclaredTypeOfSymbol(symbol) ?? this.getTypeOfSymbol(symbol))\n : (this.getTypeAtLocation(expression) ?? this.getTypeAtLocation(clause));\n })\n .filter((type): type is TsgoType => type !== undefined);\n },\n getImplementedTypesOfType(type) {\n return sessionForContext(context).session.getBaseTypes(type);\n },\n getTypeArguments(type) {\n return sessionForContext(context).session.getTypeArguments(type);\n },\n getTypesOfType(type) {\n return sessionForContext(context).session.getTypesOfType(type);\n },\n getTargetOfType(type) {\n return sessionForContext(context).session.getTargetOfType(type);\n },\n getTypeParametersOfType(type) {\n return sessionForContext(context).session.getTypeParametersOfType(type);\n },\n getOuterTypeParametersOfType(type) {\n return sessionForContext(context).session.getOuterTypeParametersOfType(type);\n },\n getLocalTypeParametersOfType(type) {\n return sessionForContext(context).session.getLocalTypeParametersOfType(type);\n },\n getObjectTypeOfType(type) {\n return sessionForContext(context).session.getObjectTypeOfType(type);\n },\n getIndexTypeOfType(type) {\n return sessionForContext(context).session.getIndexTypeOfType(type);\n },\n getCheckTypeOfType(type) {\n return sessionForContext(context).session.getCheckTypeOfType(type);\n },\n getExtendsTypeOfType(type) {\n return sessionForContext(context).session.getExtendsTypeOfType(type);\n },\n getBaseTypeOfType(type) {\n return sessionForContext(context).session.getBaseTypeOfType(type);\n },\n getConstraintOfType(type) {\n return sessionForContext(context).session.getConstraintOfType(type);\n },\n isUnionType(type) {\n return (type.flags & typeFlags.union) !== 0;\n },\n isIntersectionType(type) {\n return (type.flags & typeFlags.intersection) !== 0;\n },\n };\n}\n\nconst typeFlags = {\n union: 1 << 27,\n intersection: 1 << 28,\n} as const;\n\nfunction sourceTextFor(\n context: ContextWithParserOptions,\n node: Node | TsgoNode | TsgoType | TsgoSymbol | TsgoSignature,\n): string | undefined {\n const fileName = filenameFor(context, node);\n const normalizedFileName = fileName.toLowerCase();\n const normalizedContextFilename = context.filename.toLowerCase();\n return normalizedFileName === normalizedContextFilename ||\n normalizedFileName.endsWith(normalizedContextFilename) ||\n normalizedContextFilename.endsWith(normalizedFileName)\n ? context.sourceCode.text\n : undefined;\n}\n\nfunction typeOfNewExpression(node: Node, checker: TsgoTypeCheckerShape): TsgoType | undefined {\n const callee = childNode(node, \"callee\");\n if (!callee) {\n return undefined;\n }\n const calleeType = checker.getTypeAtLocation(callee);\n if (!calleeType) {\n return undefined;\n }\n const constructSignature = checker.getSignaturesOfType(calleeType, 1)[0];\n return constructSignature\n ? (checker.getReturnTypeOfSignature(constructSignature) ?? calleeType)\n : calleeType;\n}\n\nfunction nodeForTypeLookup(node: Node | TsgoNode): Node | TsgoNode {\n if (\"pos\" in node) {\n return node;\n }\n switch ((node as { readonly type?: string }).type) {\n case \"ClassDeclaration\":\n case \"ClassExpression\":\n return childNode(node, \"id\") ?? node;\n case \"TSPropertySignature\":\n return childNode(node, \"key\") ?? node;\n default:\n return node;\n }\n}\n\nfunction childNode(node: Node, key: string): Node | undefined {\n const value = (node as unknown as Record<string, unknown>)[key];\n if (isNode(value)) {\n return value;\n }\n return undefined;\n}\n\nfunction implementedClauseNodes(node: Node | TsgoNode): readonly Node[] {\n if (\"pos\" in node) {\n return [];\n }\n const clauses = (node as unknown as { readonly implements?: unknown }).implements;\n if (!Array.isArray(clauses)) {\n return [];\n }\n return clauses.filter(isNode);\n}\n\nfunction implementedClauseChildNode(node: Node, key: string): Node | undefined {\n const value = (node as unknown as Record<string, unknown>)[key];\n if (isNode(value)) {\n return value;\n }\n return undefined;\n}\n\nfunction implementedTypesFromTsgoNode(\n context: ContextWithParserOptions,\n node: TsgoNode,\n checker: TsgoTypeCheckerShape,\n): readonly TsgoType[] {\n const symbol = checker.getSymbolAtLocation(node);\n if (symbol) {\n const declaredType = checker.getDeclaredTypeOfSymbol(symbol) ?? checker.getTypeOfSymbol(symbol);\n if (declaredType) {\n const implemented = checker.getImplementedTypesOfType(declaredType);\n if (implemented.length > 0) {\n return implemented;\n }\n }\n }\n const sourceText = sourceTextFor(context, node);\n if (sourceText) {\n const classText = sourceText.slice(node.pos, node.end);\n const bodyOpen = classText.indexOf(\"{\");\n const headerText = bodyOpen >= 0 ? classText.slice(0, bodyOpen) : classText;\n const implementsIndex = headerText.indexOf(\"implements\");\n if (implementsIndex >= 0) {\n const clauseText = headerText.slice(implementsIndex + \"implements\".length);\n const implemented = splitTopLevelRanges(clauseText, \",\")\n .map((range) => {\n const raw = clauseText.slice(range.start, range.end);\n const leading = raw.search(/\\S/);\n if (leading < 0) {\n return undefined;\n }\n const trailing = raw.match(/\\s*$/)?.[0].length ?? 0;\n const pos = node.pos + implementsIndex + \"implements\".length + range.start + leading;\n const end = node.pos + implementsIndex + \"implements\".length + range.end - trailing;\n const lookupNode: TsgoNode = {\n fileName: node.fileName,\n pos,\n end,\n range: [pos, end] as const,\n };\n const symbol = checker.getSymbolAtLocation(lookupNode);\n return symbol\n ? (checker.getDeclaredTypeOfSymbol(symbol) ?? checker.getTypeOfSymbol(symbol))\n : checker.getTypeAtLocation(lookupNode);\n })\n .filter((type): type is TsgoType => type !== undefined);\n return implemented;\n }\n }\n const type = checker.getTypeAtLocation(node);\n return type ? checker.getImplementedTypesOfType(type) : [];\n}\n\nfunction splitTopLevelRanges(\n text: string,\n delimiter: string,\n): readonly { readonly start: number; readonly end: number }[] {\n const ranges: { start: number; end: number }[] = [];\n const scanner = createScanner();\n let start = 0;\n let angleDepth = 0;\n let parenDepth = 0;\n let bracketDepth = 0;\n let braceDepth = 0;\n for (let index = 0; index < text.length; index += 1) {\n const char = text[index];\n if (scanner.inQuote(char)) {\n continue;\n }\n if (char === \"<\") angleDepth += 1;\n else if (char === \">\") angleDepth = Math.max(0, angleDepth - 1);\n else if (char === \"(\") parenDepth += 1;\n else if (char === \")\") parenDepth = Math.max(0, parenDepth - 1);\n else if (char === \"[\") bracketDepth += 1;\n else if (char === \"]\") bracketDepth = Math.max(0, bracketDepth - 1);\n else if (char === \"{\") braceDepth += 1;\n else if (char === \"}\") braceDepth = Math.max(0, braceDepth - 1);\n else if (\n char === delimiter &&\n angleDepth === 0 &&\n parenDepth === 0 &&\n bracketDepth === 0 &&\n braceDepth === 0\n ) {\n ranges.push({ start, end: index });\n start = index + 1;\n }\n }\n ranges.push({ start, end: text.length });\n return ranges;\n}\n\nfunction createScanner(): {\n inQuote(char: string): boolean;\n} {\n let quote: string | undefined;\n let escaped = false;\n return {\n inQuote(char) {\n if (quote) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (char === quote) {\n quote = undefined;\n }\n return true;\n }\n if (char === '\"' || char === \"'\" || char === \"`\") {\n quote = char;\n return true;\n }\n return false;\n },\n };\n}\n\nfunction isNode(value: unknown): value is Node {\n return typeof value === \"object\" && value !== null && \"type\" in value && \"range\" in value;\n}\n\nfunction filenameFor(\n context: ContextWithParserOptions,\n node: Node | TsgoNode | TsgoType | TsgoSymbol | TsgoSignature,\n): string {\n if (\"fileName\" in node) {\n return node.fileName;\n }\n return context.filename;\n}\n"],"mappings":";;;AAcA,SAAgB,cACd,SAC6E;CAE7E,OAAO;EACL,UAFe,eAAe,QAEtB;EACR,qBAAqB;GACnB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,oBAAoB;;EAEhE,sBAAsB;GACpB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ;;EAE5C,mBAAmB;GACjB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,kBAAkB;;EAE9D,cAAc,WAAW,QAAQ,UAAU;GACzC,OAAO;IAAE;IAAU,MAAM,QAAQ,WAAW;IAAM;;EAEpD,iBAAiB;GACf,OAAO,kBAAkB,QAAQ;;EAEpC;;AAGH,SAAgB,kBAAkB,SAAyD;CACzF,OAAO;EACL,kBAAkB,MAAM;GACtB,IAAK,KAAoC,SAAS,iBAChD,OAAO,oBAAoB,MAAc,KAAK;GAEhD,MAAM,aAAa,kBAAkB,KAAK;GAC1C,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,kBACxC,YAAY,SAAS,WAAW,EAChC,WAAW,WAAW,EACtB,cAAc,SAAS,WAAW,CACnC;;EAEH,kBAAkB,MAAM;GACtB,OAAO,KAAK,kBAAkB,KAAK;;EAErC,oBAAoB,MAAM;GACxB,MAAM,aAAa,kBAAkB,KAAK;GAC1C,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,oBACxC,YAAY,SAAS,WAAW,EAChC,WAAW,WAAW,EACtB,cAAc,SAAS,WAAW,CACnC;;EAEH,UAAU,QAAQ;GAChB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,UAAU,OAAO;;EAE7D,cAAc,IAAI;GAChB,OAAO,kBAAkB,QAAQ,CAAC,QAAQ,UAAU,GAAG;;EAEzD,QAAQ,MAAM;GACZ,OAAO,kBAAkB,QAAQ,CAAC,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,KAAK;CAEd,OAAO,QAAQ"}
package/dist/context.d.ts CHANGED
@@ -8,7 +8,7 @@ declare function resolveProjectConfig(context: ContextWithParserOptions): Resolv
8
8
  * Resolves the type-aware parser options visible to a rule.
9
9
  *
10
10
  * Oxlint exposes a fixed `context.languageOptions.parserOptions` object at
11
- * runtime, so `corsa-oxlint` stores its richer configuration under
11
+ * runtime, so `corsa oxlint` stores its richer configuration under
12
12
  * `settings.typescriptOxlint` and rehydrates the rule-facing parser options
13
13
  * shape from there.
14
14
  *
package/dist/context.js CHANGED
@@ -23,7 +23,7 @@ function resolveProjectConfig(context) {
23
23
  const rootDir = resolve(parserOptions.tsconfigRootDir ?? context.cwd);
24
24
  const runtime = resolveRuntimeOptions(rootDir, parserOptions);
25
25
  const configPath = resolveExplicitProject(rootDir, parserOptions) ?? discoverTsconfig(filename, rootDir) ?? resolveDefaultProject(rootDir, filename, parserOptions.projectService);
26
- if (!configPath) throw new Error(`corsa-oxlint could not resolve a tsconfig for ${filename}`);
26
+ if (!configPath) throw new Error(`corsa oxlint could not resolve a tsconfig for ${filename}`);
27
27
  return {
28
28
  filename,
29
29
  rootDir,
@@ -35,7 +35,7 @@ function resolveProjectConfig(context) {
35
35
  * Resolves the type-aware parser options visible to a rule.
36
36
  *
37
37
  * Oxlint exposes a fixed `context.languageOptions.parserOptions` object at
38
- * runtime, so `corsa-oxlint` stores its richer configuration under
38
+ * runtime, so `corsa oxlint` stores its richer configuration under
39
39
  * `settings.typescriptOxlint` and rehydrates the rule-facing parser options
40
40
  * shape from there.
41
41
  *
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../ts/context.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type {\n ContextWithParserOptions,\n ProjectServiceOptions,\n ResolvedProjectConfig,\n ResolvedRuntimeOptions,\n TypeAwareParserOptions,\n TypescriptOxlintSettings,\n} from \"./types\";\n\nconst DEFAULT_CACHE_LIFETIME_MS = 250;\nconst DEFAULT_PROJECT_PATTERNS = [\"*.ts\", \"*.tsx\", \"*.js\", \"*.jsx\"];\nconst DEFAULT_TS_CONFIG = {\n compilerOptions: {\n module: \"esnext\",\n target: \"es2022\",\n strict: true,\n },\n};\n\nexport function defaultCorsaExecutable(rootDir: string, platform = process.platform): string {\n return resolve(rootDir, platform === \"win32\" ? \".cache/tsgo.exe\" : \".cache/tsgo\");\n}\n\nexport const defaultTsgoExecutable = defaultCorsaExecutable;\n\nexport function resolveProjectConfig(context: ContextWithParserOptions): ResolvedProjectConfig {\n const filename = resolve(context.filename);\n const parserOptions = resolveTypeAwareParserOptions(context);\n const rootDir = resolve(parserOptions.tsconfigRootDir ?? context.cwd);\n const runtime = resolveRuntimeOptions(rootDir, parserOptions);\n const configPath =\n resolveExplicitProject(rootDir, parserOptions) ??\n discoverTsconfig(filename, rootDir) ??\n resolveDefaultProject(rootDir, filename, parserOptions.projectService);\n if (!configPath) {\n throw new Error(`corsa-oxlint could not resolve a tsconfig for ${filename}`);\n }\n return { filename, rootDir, configPath, runtime };\n}\n\n/**\n * Resolves the type-aware parser options visible to a rule.\n *\n * Oxlint exposes a fixed `context.languageOptions.parserOptions` object at\n * runtime, so `corsa-oxlint` stores its richer configuration under\n * `settings.typescriptOxlint` and rehydrates the rule-facing parser options\n * shape from there.\n *\n * @example\n * ```ts\n * const parserOptions = resolveTypeAwareParserOptions(context);\n * parserOptions.corsa?.mode;\n * ```\n */\nexport function resolveTypeAwareParserOptions(\n context: ContextWithParserOptions,\n): TypeAwareParserOptions {\n return mergeTypeAwareParserOptions(\n resolveSettingsParserOptions(context.settings?.typescriptOxlint),\n mergeTypeAwareParserOptions(context.parserOptions, context.languageOptions?.parserOptions),\n );\n}\n\nfunction resolveRuntimeOptions(\n rootDir: string,\n parserOptions: TypeAwareParserOptions,\n): ResolvedRuntimeOptions {\n const runtime = parserOptions.corsa ?? parserOptions.tsgo;\n return {\n executable: resolve(\n runtime?.executable ??\n process.env.CORSA_EXECUTABLE ??\n process.env.TSGO_EXECUTABLE ??\n defaultCorsaExecutable(rootDir),\n ),\n cwd: resolve(runtime?.cwd ?? rootDir),\n mode: runtime?.mode ?? \"msgpack\",\n cacheLifetimeMs: runtime?.cacheLifetimeMs ?? DEFAULT_CACHE_LIFETIME_MS,\n };\n}\n\nfunction resolveExplicitProject(\n rootDir: string,\n parserOptions: TypeAwareParserOptions,\n): string | undefined {\n const projects = asArray(parserOptions.project).map((project) => {\n return resolve(rootDir, project);\n });\n return projects.find(existsSync);\n}\n\nfunction discoverTsconfig(filename: string, rootDir: string): string | undefined {\n let current = dirname(filename);\n const boundary = resolve(rootDir);\n while (current.startsWith(boundary)) {\n const candidate = resolve(current, \"tsconfig.json\");\n if (existsSync(candidate)) {\n return candidate;\n }\n const parent = dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n return undefined;\n}\n\nfunction resolveDefaultProject(\n rootDir: string,\n filename: string,\n projectService: boolean | ProjectServiceOptions | undefined,\n): string | undefined {\n if (!projectService) {\n return undefined;\n }\n if (projectService !== true && projectService.defaultProject) {\n return resolve(rootDir, projectService.defaultProject);\n }\n if (!matchesDefaultProject(filename, projectService as true | ProjectServiceOptions)) {\n return undefined;\n }\n const id = Buffer.from(filename).toString(\"hex\").slice(0, 24);\n const cacheDir = resolve(rootDir, \".cache/typescript_oxlint/default\");\n const configPath = resolve(cacheDir, `${id}.tsconfig.json`);\n if (!existsSync(configPath)) {\n mkdirSync(cacheDir, { recursive: true });\n writeFileSync(\n configPath,\n JSON.stringify(\n {\n ...DEFAULT_TS_CONFIG,\n files: [filename],\n },\n null,\n 2,\n ),\n );\n }\n return configPath;\n}\n\nfunction matchesDefaultProject(\n filename: string,\n projectService: true | ProjectServiceOptions,\n): boolean {\n const patterns =\n (projectService === true ? undefined : projectService.allowDefaultProject) ??\n DEFAULT_PROJECT_PATTERNS;\n return patterns.some((pattern: string) => globMatch(filename, pattern));\n}\n\nfunction globMatch(value: string, pattern: string): boolean {\n const escaped = pattern.replaceAll(\".\", \"\\\\.\").replaceAll(\"*\", \".*\");\n return new RegExp(`${escaped}$`).test(value);\n}\n\nfunction asArray(value: string | string[] | undefined): string[] {\n return value ? (Array.isArray(value) ? value : [value]) : [];\n}\n\nfunction resolveSettingsParserOptions(\n settings: TypescriptOxlintSettings | undefined,\n): TypeAwareParserOptions {\n if (!settings) {\n return {};\n }\n const { parserOptions, ...inline } = settings;\n return mergeTypeAwareParserOptions(inline, parserOptions);\n}\n\nexport function mergeTypeAwareParserOptions(\n base: TypeAwareParserOptions | undefined,\n override: TypeAwareParserOptions | undefined,\n): TypeAwareParserOptions {\n if (!base) {\n return normalizeTypeAwareParserOptions(override ?? {});\n }\n if (!override) {\n return normalizeTypeAwareParserOptions(base);\n }\n const runtime = {\n ...(base.corsa ?? base.tsgo),\n ...(override.corsa ?? override.tsgo),\n };\n return {\n ...base,\n ...override,\n project: override.project ?? base.project,\n projectService: mergeProjectService(base.projectService, override.projectService),\n tsconfigRootDir: override.tsconfigRootDir ?? base.tsconfigRootDir,\n ...(Object.keys(runtime).length > 0 ? { corsa: runtime, tsgo: runtime } : {}),\n };\n}\n\nfunction normalizeTypeAwareParserOptions(options: TypeAwareParserOptions): TypeAwareParserOptions {\n const runtime = options.corsa ?? options.tsgo;\n if (!runtime) {\n return options;\n }\n return {\n ...options,\n corsa: runtime,\n tsgo: runtime,\n };\n}\n\nfunction mergeProjectService(\n base: boolean | ProjectServiceOptions | undefined,\n override: boolean | ProjectServiceOptions | undefined,\n): boolean | ProjectServiceOptions | undefined {\n if (override === undefined) {\n return base;\n }\n if (typeof override === \"boolean\") {\n return override;\n }\n if (base === undefined || typeof base === \"boolean\") {\n return override;\n }\n return {\n ...base,\n ...override,\n allowDefaultProject: override.allowDefaultProject ?? base.allowDefaultProject,\n defaultProject: override.defaultProject ?? base.defaultProject,\n };\n}\n"],"mappings":";;;AAYA,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;CAAC;CAAQ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,MAAM,EAAE,eAAe,GAAG,WAAW;CACrC,OAAO,4BAA4B,QAAQ,cAAc;;AAG3D,SAAgB,4BACd,MACA,UACwB;CACxB,IAAI,CAAC,MACH,OAAO,gCAAgC,YAAY,EAAE,CAAC;CAExD,IAAI,CAAC,UACH,OAAO,gCAAgC,KAAK;CAE9C,MAAM,UAAU;EACd,GAAI,KAAK,SAAS,KAAK;EACvB,GAAI,SAAS,SAAS,SAAS;EAChC;CACD,OAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS,SAAS,WAAW,KAAK;EAClC,gBAAgB,oBAAoB,KAAK,gBAAgB,SAAS,eAAe;EACjF,iBAAiB,SAAS,mBAAmB,KAAK;EAClD,GAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI;GAAE,OAAO;GAAS,MAAM;GAAS,GAAG,EAAE;EAC7E;;AAGH,SAAS,gCAAgC,SAAyD;CAChG,MAAM,UAAU,QAAQ,SAAS,QAAQ;CACzC,IAAI,CAAC,SACH,OAAO;CAET,OAAO;EACL,GAAG;EACH,OAAO;EACP,MAAM;EACP;;AAGH,SAAS,oBACP,MACA,UAC6C;CAC7C,IAAI,aAAa,KAAA,GACf,OAAO;CAET,IAAI,OAAO,aAAa,WACtB,OAAO;CAET,IAAI,SAAS,KAAA,KAAa,OAAO,SAAS,WACxC,OAAO;CAET,OAAO;EACL,GAAG;EACH,GAAG;EACH,qBAAqB,SAAS,uBAAuB,KAAK;EAC1D,gBAAgB,SAAS,kBAAkB,KAAK;EACjD"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../ts/context.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type {\n ContextWithParserOptions,\n ProjectServiceOptions,\n ResolvedProjectConfig,\n ResolvedRuntimeOptions,\n TypeAwareParserOptions,\n TypescriptOxlintSettings,\n} from \"./types\";\n\nconst DEFAULT_CACHE_LIFETIME_MS = 250;\nconst DEFAULT_PROJECT_PATTERNS = [\"*.ts\", \"*.tsx\", \"*.js\", \"*.jsx\"];\nconst DEFAULT_TS_CONFIG = {\n compilerOptions: {\n module: \"esnext\",\n target: \"es2022\",\n strict: true,\n },\n};\n\nexport function defaultCorsaExecutable(rootDir: string, platform = process.platform): string {\n return resolve(rootDir, platform === \"win32\" ? \".cache/tsgo.exe\" : \".cache/tsgo\");\n}\n\nexport const defaultTsgoExecutable = defaultCorsaExecutable;\n\nexport function resolveProjectConfig(context: ContextWithParserOptions): ResolvedProjectConfig {\n const filename = resolve(context.filename);\n const parserOptions = resolveTypeAwareParserOptions(context);\n const rootDir = resolve(parserOptions.tsconfigRootDir ?? context.cwd);\n const runtime = resolveRuntimeOptions(rootDir, parserOptions);\n const configPath =\n resolveExplicitProject(rootDir, parserOptions) ??\n discoverTsconfig(filename, rootDir) ??\n resolveDefaultProject(rootDir, filename, parserOptions.projectService);\n if (!configPath) {\n throw new Error(`corsa oxlint could not resolve a tsconfig for ${filename}`);\n }\n return { filename, rootDir, configPath, runtime };\n}\n\n/**\n * Resolves the type-aware parser options visible to a rule.\n *\n * Oxlint exposes a fixed `context.languageOptions.parserOptions` object at\n * runtime, so `corsa oxlint` stores its richer configuration under\n * `settings.typescriptOxlint` and rehydrates the rule-facing parser options\n * shape from there.\n *\n * @example\n * ```ts\n * const parserOptions = resolveTypeAwareParserOptions(context);\n * parserOptions.corsa?.mode;\n * ```\n */\nexport function resolveTypeAwareParserOptions(\n context: ContextWithParserOptions,\n): TypeAwareParserOptions {\n return mergeTypeAwareParserOptions(\n resolveSettingsParserOptions(context.settings?.typescriptOxlint),\n mergeTypeAwareParserOptions(context.parserOptions, context.languageOptions?.parserOptions),\n );\n}\n\nfunction resolveRuntimeOptions(\n rootDir: string,\n parserOptions: TypeAwareParserOptions,\n): ResolvedRuntimeOptions {\n const runtime = parserOptions.corsa ?? parserOptions.tsgo;\n return {\n executable: resolve(\n runtime?.executable ??\n process.env.CORSA_EXECUTABLE ??\n process.env.TSGO_EXECUTABLE ??\n defaultCorsaExecutable(rootDir),\n ),\n cwd: resolve(runtime?.cwd ?? rootDir),\n mode: runtime?.mode ?? \"msgpack\",\n cacheLifetimeMs: runtime?.cacheLifetimeMs ?? DEFAULT_CACHE_LIFETIME_MS,\n };\n}\n\nfunction resolveExplicitProject(\n rootDir: string,\n parserOptions: TypeAwareParserOptions,\n): string | undefined {\n const projects = asArray(parserOptions.project).map((project) => {\n return resolve(rootDir, project);\n });\n return projects.find(existsSync);\n}\n\nfunction discoverTsconfig(filename: string, rootDir: string): string | undefined {\n let current = dirname(filename);\n const boundary = resolve(rootDir);\n while (current.startsWith(boundary)) {\n const candidate = resolve(current, \"tsconfig.json\");\n if (existsSync(candidate)) {\n return candidate;\n }\n const parent = dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n return undefined;\n}\n\nfunction resolveDefaultProject(\n rootDir: string,\n filename: string,\n projectService: boolean | ProjectServiceOptions | undefined,\n): string | undefined {\n if (!projectService) {\n return undefined;\n }\n if (projectService !== true && projectService.defaultProject) {\n return resolve(rootDir, projectService.defaultProject);\n }\n if (!matchesDefaultProject(filename, projectService as true | ProjectServiceOptions)) {\n return undefined;\n }\n const id = Buffer.from(filename).toString(\"hex\").slice(0, 24);\n const cacheDir = resolve(rootDir, \".cache/typescript_oxlint/default\");\n const configPath = resolve(cacheDir, `${id}.tsconfig.json`);\n if (!existsSync(configPath)) {\n mkdirSync(cacheDir, { recursive: true });\n writeFileSync(\n configPath,\n JSON.stringify(\n {\n ...DEFAULT_TS_CONFIG,\n files: [filename],\n },\n null,\n 2,\n ),\n );\n }\n return configPath;\n}\n\nfunction matchesDefaultProject(\n filename: string,\n projectService: true | ProjectServiceOptions,\n): boolean {\n const patterns =\n (projectService === true ? undefined : projectService.allowDefaultProject) ??\n DEFAULT_PROJECT_PATTERNS;\n return patterns.some((pattern: string) => globMatch(filename, pattern));\n}\n\nfunction globMatch(value: string, pattern: string): boolean {\n const escaped = pattern.replaceAll(\".\", \"\\\\.\").replaceAll(\"*\", \".*\");\n return new RegExp(`${escaped}$`).test(value);\n}\n\nfunction asArray(value: string | string[] | undefined): string[] {\n return value ? (Array.isArray(value) ? value : [value]) : [];\n}\n\nfunction resolveSettingsParserOptions(\n settings: TypescriptOxlintSettings | undefined,\n): TypeAwareParserOptions {\n if (!settings) {\n return {};\n }\n const { parserOptions, ...inline } = settings;\n return mergeTypeAwareParserOptions(inline, parserOptions);\n}\n\nexport function mergeTypeAwareParserOptions(\n base: TypeAwareParserOptions | undefined,\n override: TypeAwareParserOptions | undefined,\n): TypeAwareParserOptions {\n if (!base) {\n return normalizeTypeAwareParserOptions(override ?? {});\n }\n if (!override) {\n return normalizeTypeAwareParserOptions(base);\n }\n const runtime = {\n ...(base.corsa ?? base.tsgo),\n ...(override.corsa ?? override.tsgo),\n };\n return {\n ...base,\n ...override,\n project: override.project ?? base.project,\n projectService: mergeProjectService(base.projectService, override.projectService),\n tsconfigRootDir: override.tsconfigRootDir ?? base.tsconfigRootDir,\n ...(Object.keys(runtime).length > 0 ? { corsa: runtime, tsgo: runtime } : {}),\n };\n}\n\nfunction normalizeTypeAwareParserOptions(options: TypeAwareParserOptions): TypeAwareParserOptions {\n const runtime = options.corsa ?? options.tsgo;\n if (!runtime) {\n return options;\n }\n return {\n ...options,\n corsa: runtime,\n tsgo: runtime,\n };\n}\n\nfunction mergeProjectService(\n base: boolean | ProjectServiceOptions | undefined,\n override: boolean | ProjectServiceOptions | undefined,\n): boolean | ProjectServiceOptions | undefined {\n if (override === undefined) {\n return base;\n }\n if (typeof override === \"boolean\") {\n return override;\n }\n if (base === undefined || typeof base === \"boolean\") {\n return override;\n }\n return {\n ...base,\n ...override,\n allowDefaultProject: override.allowDefaultProject ?? base.allowDefaultProject,\n defaultProject: override.defaultProject ?? base.defaultProject,\n };\n}\n"],"mappings":";;;AAYA,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;CAAC;CAAQ;CAAS;CAAQ;CAAQ;AACnE,MAAM,oBAAoB,EAC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BAA4B,QAAQ,cAAc;;AAG3D,SAAgB,4BACd,MACA,UACwB;CACxB,IAAI,CAAC,MACH,OAAO,gCAAgC,YAAY,EAAE,CAAC;CAExD,IAAI,CAAC,UACH,OAAO,gCAAgC,KAAK;CAE9C,MAAM,UAAU;EACd,GAAI,KAAK,SAAS,KAAK;EACvB,GAAI,SAAS,SAAS,SAAS;EAChC;CACD,OAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS,SAAS,WAAW,KAAK;EAClC,gBAAgB,oBAAoB,KAAK,gBAAgB,SAAS,eAAe;EACjF,iBAAiB,SAAS,mBAAmB,KAAK;EAClD,GAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI;GAAE,OAAO;GAAS,MAAM;GAAS,GAAG,EAAE;EAC7E;;AAGH,SAAS,gCAAgC,SAAyD;CAChG,MAAM,UAAU,QAAQ,SAAS,QAAQ;CACzC,IAAI,CAAC,SACH,OAAO;CAET,OAAO;EACL,GAAG;EACH,OAAO;EACP,MAAM;EACP;;AAGH,SAAS,oBACP,MACA,UAC6C;CAC7C,IAAI,aAAa,KAAA,GACf,OAAO;CAET,IAAI,OAAO,aAAa,WACtB,OAAO;CAET,IAAI,SAAS,KAAA,KAAa,OAAO,SAAS,WACxC,OAAO;CAET,OAAO;EACL,GAAG;EACH,GAAG;EACH,qBAAqB,SAAS,uBAAuB,KAAK;EAC1D,gBAAgB,SAAS,kBAAkB,KAAK;EACjD"}
package/dist/node_map.js CHANGED
@@ -20,7 +20,7 @@ function createNodeMaps(context) {
20
20
  tsNodeToESTreeNodeMap: {
21
21
  get(node) {
22
22
  const value = tsgoToEstree.get(node);
23
- if (!value) throw new Error("corsa-oxlint could not map tsgo node back to ESTree");
23
+ if (!value) throw new Error("corsa oxlint could not map Corsa node back to ESTree");
24
24
  return value;
25
25
  },
26
26
  has(node) {
@@ -43,7 +43,7 @@ function createTsgoNode(fileName, node) {
43
43
  }
44
44
  function assertRange(node) {
45
45
  const range = node.range;
46
- if (!range) throw new Error("corsa-oxlint requires ESTree nodes with range data");
46
+ if (!range) throw new Error("corsa oxlint requires ESTree nodes with range data");
47
47
  return range;
48
48
  }
49
49
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"node_map.js","names":[],"sources":["../ts/node_map.ts"],"sourcesContent":["import type { Node } from \"@oxlint/plugins\";\n\nimport type { ContextWithParserOptions, TsgoNode } from \"./types\";\n\nconst estreeToTsgo = new WeakMap<object, TsgoNode>();\nconst tsgoToEstree = new WeakMap<object, Node>();\n\nexport function createNodeMaps(context: ContextWithParserOptions): {\n esTreeNodeToTSNodeMap: {\n get(node: Node): TsgoNode;\n has(node: Node): boolean;\n };\n tsNodeToESTreeNodeMap: {\n get(node: TsgoNode): Node;\n has(node: TsgoNode): boolean;\n };\n} {\n return {\n esTreeNodeToTSNodeMap: {\n get(node) {\n let current = estreeToTsgo.get(node);\n if (!current) {\n current = createTsgoNode(context.filename, node);\n estreeToTsgo.set(node, current);\n tsgoToEstree.set(current, node);\n }\n return current;\n },\n has(node) {\n return estreeToTsgo.has(node);\n },\n },\n tsNodeToESTreeNodeMap: {\n get(node) {\n const value = tsgoToEstree.get(node);\n if (!value) {\n throw new Error(\"corsa-oxlint could not map tsgo node back to ESTree\");\n }\n return value;\n },\n has(node) {\n return tsgoToEstree.has(node);\n },\n },\n };\n}\n\nexport function toPosition(node: Node | TsgoNode): number {\n return \"pos\" in node ? node.pos : assertRange(node)[0];\n}\n\nfunction createTsgoNode(fileName: string, node: Node): TsgoNode {\n const [pos, end] = assertRange(node);\n return {\n fileName,\n pos,\n end,\n range: [pos, end],\n };\n}\n\nfunction assertRange(node: Node): readonly [number, number] {\n const range = (node as Node & { range?: readonly [number, number] }).range;\n if (!range) {\n throw new Error(\"corsa-oxlint requires ESTree nodes with range data\");\n }\n return range;\n}\n"],"mappings":";AAIA,MAAM,+BAAe,IAAI,SAA2B;AACpD,MAAM,+BAAe,IAAI,SAAuB;AAEhD,SAAgB,eAAe,SAS7B;CACA,OAAO;EACL,uBAAuB;GACrB,IAAI,MAAM;IACR,IAAI,UAAU,aAAa,IAAI,KAAK;IACpC,IAAI,CAAC,SAAS;KACZ,UAAU,eAAe,QAAQ,UAAU,KAAK;KAChD,aAAa,IAAI,MAAM,QAAQ;KAC/B,aAAa,IAAI,SAAS,KAAK;;IAEjC,OAAO;;GAET,IAAI,MAAM;IACR,OAAO,aAAa,IAAI,KAAK;;GAEhC;EACD,uBAAuB;GACrB,IAAI,MAAM;IACR,MAAM,QAAQ,aAAa,IAAI,KAAK;IACpC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,sDAAsD;IAExE,OAAO;;GAET,IAAI,MAAM;IACR,OAAO,aAAa,IAAI,KAAK;;GAEhC;EACF;;AAGH,SAAgB,WAAW,MAA+B;CACxD,OAAO,SAAS,OAAO,KAAK,MAAM,YAAY,KAAK,CAAC;;AAGtD,SAAS,eAAe,UAAkB,MAAsB;CAC9D,MAAM,CAAC,KAAK,OAAO,YAAY,KAAK;CACpC,OAAO;EACL;EACA;EACA;EACA,OAAO,CAAC,KAAK,IAAI;EAClB;;AAGH,SAAS,YAAY,MAAuC;CAC1D,MAAM,QAAS,KAAsD;CACrE,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,qDAAqD;CAEvE,OAAO"}
1
+ {"version":3,"file":"node_map.js","names":[],"sources":["../ts/node_map.ts"],"sourcesContent":["import type { Node } from \"@oxlint/plugins\";\n\nimport type { ContextWithParserOptions, TsgoNode } from \"./types\";\n\nconst estreeToTsgo = new WeakMap<object, TsgoNode>();\nconst tsgoToEstree = new WeakMap<object, Node>();\n\nexport function createNodeMaps(context: ContextWithParserOptions): {\n esTreeNodeToTSNodeMap: {\n get(node: Node): TsgoNode;\n has(node: Node): boolean;\n };\n tsNodeToESTreeNodeMap: {\n get(node: TsgoNode): Node;\n has(node: TsgoNode): boolean;\n };\n} {\n return {\n esTreeNodeToTSNodeMap: {\n get(node) {\n let current = estreeToTsgo.get(node);\n if (!current) {\n current = createTsgoNode(context.filename, node);\n estreeToTsgo.set(node, current);\n tsgoToEstree.set(current, node);\n }\n return current;\n },\n has(node) {\n return estreeToTsgo.has(node);\n },\n },\n tsNodeToESTreeNodeMap: {\n get(node) {\n const value = tsgoToEstree.get(node);\n if (!value) {\n throw new Error(\"corsa oxlint could not map Corsa node back to ESTree\");\n }\n return value;\n },\n has(node) {\n return tsgoToEstree.has(node);\n },\n },\n };\n}\n\nexport function toPosition(node: Node | TsgoNode): number {\n return \"pos\" in node ? node.pos : assertRange(node)[0];\n}\n\nfunction createTsgoNode(fileName: string, node: Node): TsgoNode {\n const [pos, end] = assertRange(node);\n return {\n fileName,\n pos,\n end,\n range: [pos, end],\n };\n}\n\nfunction assertRange(node: Node): readonly [number, number] {\n const range = (node as Node & { range?: readonly [number, number] }).range;\n if (!range) {\n throw new Error(\"corsa oxlint requires ESTree nodes with range data\");\n }\n return range;\n}\n"],"mappings":";AAIA,MAAM,+BAAe,IAAI,SAA2B;AACpD,MAAM,+BAAe,IAAI,SAAuB;AAEhD,SAAgB,eAAe,SAS7B;CACA,OAAO;EACL,uBAAuB;GACrB,IAAI,MAAM;IACR,IAAI,UAAU,aAAa,IAAI,KAAK;IACpC,IAAI,CAAC,SAAS;KACZ,UAAU,eAAe,QAAQ,UAAU,KAAK;KAChD,aAAa,IAAI,MAAM,QAAQ;KAC/B,aAAa,IAAI,SAAS,KAAK;;IAEjC,OAAO;;GAET,IAAI,MAAM;IACR,OAAO,aAAa,IAAI,KAAK;;GAEhC;EACD,uBAAuB;GACrB,IAAI,MAAM;IACR,MAAM,QAAQ,aAAa,IAAI,KAAK;IACpC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,uDAAuD;IAEzE,OAAO;;GAET,IAAI,MAAM;IACR,OAAO,aAAa,IAAI,KAAK;;GAEhC;EACF;;AAGH,SAAgB,WAAW,MAA+B;CACxD,OAAO,SAAS,OAAO,KAAK,MAAM,YAAY,KAAK,CAAC;;AAGtD,SAAS,eAAe,UAAkB,MAAsB;CAC9D,MAAM,CAAC,KAAK,OAAO,YAAY,KAAK;CACpC,OAAO;EACL;EACA;EACA;EACA,OAAO,CAAC,KAAK,IAAI;EAClB;;AAGH,SAAS,YAAY,MAAuC;CAC1D,MAAM,QAAS,KAAsD;CACrE,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,qDAAqD;CAEvE,OAAO"}
@@ -23,7 +23,7 @@ type RuleCreatorCreatedRule<TRule extends RuleCreatorRule> = Omit<TRule, "defaul
23
23
  } & Rule & Record<string, unknown>;
24
24
  type RuleCreatorFactory = <TRule extends RuleCreatorRule>(rule: TRule) => RuleCreatorCreatedRule<TRule>;
25
25
  /**
26
- * Self-hosted type-aware utilities for Oxlint rules backed by tsgo.
26
+ * Self-hosted type-aware utilities for Oxlint rules backed by Corsa.
27
27
  */
28
28
  declare const OxlintUtils: Readonly<{
29
29
  RuleCreator(urlCreator: (ruleName: string) => string): RuleCreatorFactory;
@@ -2,7 +2,7 @@ import { getParserServices } from "./parser_services.js";
2
2
  import { decorateRule } from "./plugin.js";
3
3
  //#region src/bindings/nodejs/typescript_oxlint/ts/oxlint_utils.ts
4
4
  /**
5
- * Self-hosted type-aware utilities for Oxlint rules backed by tsgo.
5
+ * Self-hosted type-aware utilities for Oxlint rules backed by Corsa.
6
6
  */
7
7
  const OxlintUtils = Object.freeze({
8
8
  RuleCreator(urlCreator) {
@@ -1 +1 @@
1
- {"version":3,"file":"oxlint_utils.js","names":[],"sources":["../ts/oxlint_utils.ts"],"sourcesContent":["import type { Rule, RuleMeta, Visitor } from \"@oxlint/plugins\";\n\nimport { getParserServices } from \"./parser_services\";\nimport { decorateRule } from \"./plugin\";\nimport type { ContextWithParserOptions } from \"./types\";\n\nexport type RuleCreatorRule<\n TOptions extends readonly unknown[] = readonly unknown[],\n TMessageIds extends string = string,\n> = {\n readonly name: string;\n readonly meta: RuleMeta & {\n readonly messages?: Record<TMessageIds, string>;\n };\n readonly defaultOptions?: TOptions;\n readonly create: (context: ContextWithParserOptions) => Visitor;\n};\n\nexport type RuleCreatorCreatedRule<TRule extends RuleCreatorRule> = Omit<\n TRule,\n \"defaultOptions\" | \"meta\"\n> & {\n readonly defaultOptions: TRule extends { readonly defaultOptions: infer TOptions }\n ? TOptions\n : readonly [];\n readonly meta: TRule[\"meta\"] & {\n readonly docs: NonNullable<TRule[\"meta\"][\"docs\"]> & {\n readonly url: string;\n };\n };\n} & Rule &\n Record<string, unknown>;\n\nexport type RuleCreatorFactory = <TRule extends RuleCreatorRule>(\n rule: TRule,\n) => RuleCreatorCreatedRule<TRule>;\n\n/**\n * Self-hosted type-aware utilities for Oxlint rules backed by tsgo.\n */\nexport const OxlintUtils = Object.freeze({\n RuleCreator(urlCreator: (ruleName: string) => string): RuleCreatorFactory {\n return ((rule) => {\n const docs = rule.meta?.docs;\n return decorateRule({\n ...rule,\n meta: {\n ...rule.meta,\n docs: {\n ...docs,\n url: urlCreator(rule.name),\n },\n },\n defaultOptions: rule.defaultOptions ?? [],\n } as unknown as Rule) as RuleCreatorCreatedRule<typeof rule>;\n }) as RuleCreatorFactory;\n },\n getParserServices(context: ContextWithParserOptions, allowWithoutFullTypeInformation = false) {\n return getParserServices(context, allowWithoutFullTypeInformation);\n },\n});\n\nexport const NullThrowsReasons = Object.freeze({\n MissingParent: \"Expected node to have a parent.\",\n MissingToken: (token: string, thing: string) => `Expected to find a ${token} for the ${thing}.`,\n});\n\nexport const RuleCreator = Object.assign(OxlintUtils.RuleCreator, {\n withoutDocs<TRule extends Omit<RuleCreatorRule, \"name\">>(\n rule: TRule,\n ): Omit<TRule, \"defaultOptions\"> &\n Rule & {\n readonly defaultOptions: TRule extends { readonly defaultOptions: infer TOptions }\n ? TOptions\n : readonly [];\n } {\n return decorateRule({\n ...rule,\n defaultOptions: rule.defaultOptions ?? [],\n } as unknown as Rule) as never;\n },\n});\nexport { getParserServices } from \"./parser_services\";\n\nexport function applyDefault<User extends readonly unknown[], Defaults extends readonly unknown[]>(\n defaultOptions: Defaults,\n userOptions: User | null | undefined,\n): readonly unknown[] {\n const options = structuredClone(defaultOptions) as unknown as unknown[];\n if (userOptions == null) {\n return options;\n }\n options.forEach((option, index) => {\n if (userOptions[index] === undefined) {\n return;\n }\n const userOption = userOptions[index];\n options[index] =\n isObjectNotArray(option) && isObjectNotArray(userOption)\n ? deepMerge(option, userOption)\n : userOption;\n });\n return options;\n}\n\nexport function deepMerge<T>(base: T, override: unknown): T {\n if (isObject(base) && isObject(override)) {\n return Object.fromEntries(\n [...new Set([...Object.keys(base), ...Object.keys(override)])].map((key) => [\n key,\n key in base && key in override\n ? deepMerge((base as any)[key], (override as any)[key])\n : key in base\n ? (base as any)[key]\n : (override as any)[key],\n ]),\n ) as T;\n }\n return (override === undefined ? base : override) as T;\n}\n\nexport function nullThrows<T>(\n value: T | null | undefined,\n message = \"Expected value to be present\",\n): T {\n if (value == null) {\n throw new Error(`Non-null Assertion Failed: ${message}`);\n }\n return value;\n}\n\nexport function isObjectNotArray(value: unknown): value is Record<string, unknown> {\n return isObject(value);\n}\n\nexport const ESLintUtils = Object.freeze({\n NullThrowsReasons,\n RuleCreator,\n applyDefault,\n deepMerge,\n getParserServices,\n isObjectNotArray,\n nullThrows,\n});\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";;;;;;AAwCA,MAAa,cAAc,OAAO,OAAO;CACvC,YAAY,YAA8D;EACxE,SAAS,SAAS;GAChB,MAAM,OAAO,KAAK,MAAM;GACxB,OAAO,aAAa;IAClB,GAAG;IACH,MAAM;KACJ,GAAG,KAAK;KACR,MAAM;MACJ,GAAG;MACH,KAAK,WAAW,KAAK,KAAK;MAC3B;KACF;IACD,gBAAgB,KAAK,kBAAkB,EAAE;IAC1C,CAAoB;;;CAGzB,kBAAkB,SAAmC,kCAAkC,OAAO;EAC5F,OAAO,kBAAkB,SAAS,gCAAgC;;CAErE,CAAC;AAEF,MAAa,oBAAoB,OAAO,OAAO;CAC7C,eAAe;CACf,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ils.js","names":[],"sources":["../ts/oxlint_utils.ts"],"sourcesContent":["import type { Rule, RuleMeta, Visitor } from \"@oxlint/plugins\";\n\nimport { getParserServices } from \"./parser_services\";\nimport { decorateRule } from \"./plugin\";\nimport type { ContextWithParserOptions } from \"./types\";\n\nexport type RuleCreatorRule<\n TOptions extends readonly unknown[] = readonly unknown[],\n TMessageIds extends string = string,\n> = {\n readonly name: string;\n readonly meta: RuleMeta & {\n readonly messages?: Record<TMessageIds, string>;\n };\n readonly defaultOptions?: TOptions;\n readonly create: (context: ContextWithParserOptions) => Visitor;\n};\n\nexport type RuleCreatorCreatedRule<TRule extends RuleCreatorRule> = Omit<\n TRule,\n \"defaultOptions\" | \"meta\"\n> & {\n readonly defaultOptions: TRule extends { readonly defaultOptions: infer TOptions }\n ? TOptions\n : readonly [];\n readonly meta: TRule[\"meta\"] & {\n readonly docs: NonNullable<TRule[\"meta\"][\"docs\"]> & {\n readonly url: string;\n };\n };\n} & Rule &\n Record<string, unknown>;\n\nexport type RuleCreatorFactory = <TRule extends RuleCreatorRule>(\n rule: TRule,\n) => RuleCreatorCreatedRule<TRule>;\n\n/**\n * Self-hosted type-aware utilities for Oxlint rules backed by Corsa.\n */\nexport const OxlintUtils = Object.freeze({\n RuleCreator(urlCreator: (ruleName: string) => string): RuleCreatorFactory {\n return ((rule) => {\n const docs = rule.meta?.docs;\n return decorateRule({\n ...rule,\n meta: {\n ...rule.meta,\n docs: {\n ...docs,\n url: urlCreator(rule.name),\n },\n },\n defaultOptions: rule.defaultOptions ?? [],\n } as unknown as Rule) as RuleCreatorCreatedRule<typeof rule>;\n }) as RuleCreatorFactory;\n },\n getParserServices(context: ContextWithParserOptions, allowWithoutFullTypeInformation = false) {\n return getParserServices(context, allowWithoutFullTypeInformation);\n },\n});\n\nexport const NullThrowsReasons = Object.freeze({\n MissingParent: \"Expected node to have a parent.\",\n MissingToken: (token: string, thing: string) => `Expected to find a ${token} for the ${thing}.`,\n});\n\nexport const RuleCreator = Object.assign(OxlintUtils.RuleCreator, {\n withoutDocs<TRule extends Omit<RuleCreatorRule, \"name\">>(\n rule: TRule,\n ): Omit<TRule, \"defaultOptions\"> &\n Rule & {\n readonly defaultOptions: TRule extends { readonly defaultOptions: infer TOptions }\n ? TOptions\n : readonly [];\n } {\n return decorateRule({\n ...rule,\n defaultOptions: rule.defaultOptions ?? [],\n } as unknown as Rule) as never;\n },\n});\nexport { getParserServices } from \"./parser_services\";\n\nexport function applyDefault<User extends readonly unknown[], Defaults extends readonly unknown[]>(\n defaultOptions: Defaults,\n userOptions: User | null | undefined,\n): readonly unknown[] {\n const options = structuredClone(defaultOptions) as unknown as unknown[];\n if (userOptions == null) {\n return options;\n }\n options.forEach((option, index) => {\n if (userOptions[index] === undefined) {\n return;\n }\n const userOption = userOptions[index];\n options[index] =\n isObjectNotArray(option) && isObjectNotArray(userOption)\n ? deepMerge(option, userOption)\n : userOption;\n });\n return options;\n}\n\nexport function deepMerge<T>(base: T, override: unknown): T {\n if (isObject(base) && isObject(override)) {\n return Object.fromEntries(\n [...new Set([...Object.keys(base), ...Object.keys(override)])].map((key) => [\n key,\n key in base && key in override\n ? deepMerge((base as any)[key], (override as any)[key])\n : key in base\n ? (base as any)[key]\n : (override as any)[key],\n ]),\n ) as T;\n }\n return (override === undefined ? base : override) as T;\n}\n\nexport function nullThrows<T>(\n value: T | null | undefined,\n message = \"Expected value to be present\",\n): T {\n if (value == null) {\n throw new Error(`Non-null Assertion Failed: ${message}`);\n }\n return value;\n}\n\nexport function isObjectNotArray(value: unknown): value is Record<string, unknown> {\n return isObject(value);\n}\n\nexport const ESLintUtils = Object.freeze({\n NullThrowsReasons,\n RuleCreator,\n applyDefault,\n deepMerge,\n getParserServices,\n isObjectNotArray,\n nullThrows,\n});\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";;;;;;AAwCA,MAAa,cAAc,OAAO,OAAO;CACvC,YAAY,YAA8D;EACxE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G1C,SAAgB,WACd,OACA,UAAU,gCACP;CACH,IAAI,SAAS,MACX,MAAM,IAAI,MAAM,8BAA8B,UAAU;CAE1D,OAAO;;AAGT,SAAgB,iBAAiB,OAAkD;CACjF,OAAO,SAAS,MAAM;;AAGxB,MAAa,cAAc,OAAO,OAAO;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM"}
@@ -2,7 +2,7 @@ import { ContextWithParserOptions, ParserServices } from "./types.js";
2
2
 
3
3
  //#region src/bindings/nodejs/typescript_oxlint/ts/parser_services.d.ts
4
4
  /**
5
- * Returns type-aware parser services backed by tsgo.
5
+ * Returns type-aware parser services backed by Corsa.
6
6
  *
7
7
  * @example
8
8
  * ```ts
@@ -1,9 +1,10 @@
1
1
  import { createNodeMaps } from "./node_map.js";
2
+ import { resolveTypeAwareParserOptions } from "./context.js";
2
3
  import { createProgram, createTypeChecker } from "./checker.js";
3
4
  //#region src/bindings/nodejs/typescript_oxlint/ts/parser_services.ts
4
5
  const parserServices = /* @__PURE__ */ new WeakMap();
5
6
  /**
6
- * Returns type-aware parser services backed by tsgo.
7
+ * Returns type-aware parser services backed by Corsa.
7
8
  *
8
9
  * @example
9
10
  * ```ts
@@ -14,6 +15,12 @@ const parserServices = /* @__PURE__ */ new WeakMap();
14
15
  function getParserServices(context, allowWithoutFullTypeInformation = false) {
15
16
  const current = parserServices.get(context);
16
17
  if (current) return current;
18
+ const parserOptions = resolveTypeAwareParserOptions(context);
19
+ if (!parserOptions.corsa && !parserOptions.tsgo && hasEslintParserServices(context.parserServices)) {
20
+ const services = createEslintParserServices(context);
21
+ parserServices.set(context, services);
22
+ return services;
23
+ }
17
24
  try {
18
25
  const maps = createNodeMaps(context);
19
26
  const services = {
@@ -42,6 +49,27 @@ function getParserServices(context, allowWithoutFullTypeInformation = false) {
42
49
  return fallback;
43
50
  }
44
51
  }
52
+ function createEslintParserServices(context) {
53
+ const parserServices = context.parserServices;
54
+ const checker = parserServices.program.getTypeChecker();
55
+ return {
56
+ program: parserServices.program,
57
+ esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,
58
+ tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,
59
+ hasFullTypeInformation: true,
60
+ getTypeAtLocation(node) {
61
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
62
+ return tsNode ? checker.getTypeAtLocation(tsNode) : void 0;
63
+ },
64
+ getSymbolAtLocation(node) {
65
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
66
+ return tsNode ? checker.getSymbolAtLocation(tsNode) : void 0;
67
+ }
68
+ };
69
+ }
70
+ function hasEslintParserServices(value) {
71
+ return Boolean(value && typeof value === "object" && "program" in value && "esTreeNodeToTSNodeMap" in value && "tsNodeToESTreeNodeMap" in value);
72
+ }
45
73
  //#endregion
46
74
  export { getParserServices };
47
75
 
@@ -1 +1 @@
1
- {"version":3,"file":"parser_services.js","names":[],"sources":["../ts/parser_services.ts"],"sourcesContent":["import { createProgram, createTypeChecker } from \"./checker\";\nimport { createNodeMaps } from \"./node_map\";\nimport type {\n ContextWithParserOptions,\n ParserServices,\n ParserServicesWithTypeInformation,\n} from \"./types\";\n\nconst parserServices = new WeakMap<object, ParserServices>();\n\n/**\n * Returns type-aware parser services backed by tsgo.\n *\n * @example\n * ```ts\n * const services = getParserServices(context);\n * const checker = services.program.getTypeChecker();\n * ```\n */\nexport function getParserServices(\n context: ContextWithParserOptions,\n allowWithoutFullTypeInformation = false,\n): ParserServices {\n const current = parserServices.get(context);\n if (current) {\n return current;\n }\n try {\n const maps = createNodeMaps(context);\n const program = createProgram(context);\n const services: ParserServicesWithTypeInformation = {\n program,\n ...maps,\n hasFullTypeInformation: true,\n getTypeAtLocation(node) {\n return createTypeChecker(context).getTypeAtLocation(node);\n },\n getSymbolAtLocation(node) {\n return createTypeChecker(context).getSymbolAtLocation(node);\n },\n };\n parserServices.set(context, services);\n return services;\n } catch (error) {\n if (!allowWithoutFullTypeInformation) {\n throw error;\n }\n const fallback: ParserServices = {\n program: createProgram(context),\n ...createNodeMaps(context),\n hasFullTypeInformation: false,\n getTypeAtLocation() {\n return undefined;\n },\n getSymbolAtLocation() {\n return undefined;\n },\n };\n parserServices.set(context, fallback);\n return fallback;\n }\n}\n"],"mappings":";;;AAQA,MAAM,iCAAiB,IAAI,SAAiC;;;;;;;;;;AAW5D,SAAgB,kBACd,SACA,kCAAkC,OAClB;CAChB,MAAM,UAAU,eAAe,IAAI,QAAQ;CAC3C,IAAI,SACF,OAAO;CAET,IAAI;EACF,MAAM,OAAO,eAAe,QAAQ;EAEpC,MAAM,WAA8C;GAClD,SAFc,cAAc,QAErB;GACP,GAAG;GACH,wBAAwB;GACxB,kBAAkB,MAAM;IACtB,OAAO,kBAAkB,QAAQ,CAAC,kBAAkB,KAAK;;GAE3D,oBAAoB,MAAM;IACxB,OAAO,kBAAkB,QAAQ,CAAC,oBAAoB,KAAK;;GAE9D;EACD,eAAe,IAAI,SAAS,SAAS;EACrC,OAAO;UACA,OAAO;EACd,IAAI,CAAC,iCACH,MAAM;EAER,MAAM,WAA2B;GAC/B,SAAS,cAAc,QAAQ;GAC/B,GAAG,eAAe,QAAQ;GAC1B,wBAAwB;GACxB,oBAAoB;GAGpB,sBAAsB;GAGvB;EACD,eAAe,IAAI,SAAS,SAAS;EACrC,OAAO"}
1
+ {"version":3,"file":"parser_services.js","names":[],"sources":["../ts/parser_services.ts"],"sourcesContent":["import { createProgram, createTypeChecker } from \"./checker\";\nimport { resolveTypeAwareParserOptions } from \"./context\";\nimport { createNodeMaps } from \"./node_map\";\nimport type {\n ContextWithParserOptions,\n ParserServices,\n ParserServicesWithTypeInformation,\n} from \"./types\";\n\nconst parserServices = new WeakMap<object, ParserServices>();\n\n/**\n * Returns type-aware parser services backed by Corsa.\n *\n * @example\n * ```ts\n * const services = getParserServices(context);\n * const checker = services.program.getTypeChecker();\n * ```\n */\nexport function getParserServices(\n context: ContextWithParserOptions,\n allowWithoutFullTypeInformation = false,\n): ParserServices {\n const current = parserServices.get(context);\n if (current) {\n return current;\n }\n const parserOptions = resolveTypeAwareParserOptions(context);\n if (\n !parserOptions.corsa &&\n !parserOptions.tsgo &&\n hasEslintParserServices(context.parserServices)\n ) {\n const services = createEslintParserServices(context);\n parserServices.set(context, services);\n return services;\n }\n try {\n const maps = createNodeMaps(context);\n const program = createProgram(context);\n const services: ParserServicesWithTypeInformation = {\n program,\n ...maps,\n hasFullTypeInformation: true,\n getTypeAtLocation(node) {\n return createTypeChecker(context).getTypeAtLocation(node);\n },\n getSymbolAtLocation(node) {\n return createTypeChecker(context).getSymbolAtLocation(node);\n },\n };\n parserServices.set(context, services);\n return services;\n } catch (error) {\n if (!allowWithoutFullTypeInformation) {\n throw error;\n }\n const fallback: ParserServices = {\n program: createProgram(context),\n ...createNodeMaps(context),\n hasFullTypeInformation: false,\n getTypeAtLocation() {\n return undefined;\n },\n getSymbolAtLocation() {\n return undefined;\n },\n };\n parserServices.set(context, fallback);\n return fallback;\n }\n}\n\nfunction createEslintParserServices(\n context: ContextWithParserOptions,\n): ParserServicesWithTypeInformation {\n const parserServices = context.parserServices!;\n const checker = parserServices.program.getTypeChecker();\n return {\n program: parserServices.program,\n esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,\n tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,\n hasFullTypeInformation: true,\n getTypeAtLocation(node) {\n const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);\n return tsNode ? checker.getTypeAtLocation(tsNode) : undefined;\n },\n getSymbolAtLocation(node) {\n const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);\n return tsNode ? checker.getSymbolAtLocation(tsNode) : undefined;\n },\n };\n}\n\nfunction hasEslintParserServices(\n value: ContextWithParserOptions[\"parserServices\"],\n): value is ParserServices {\n return Boolean(\n value &&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AG,KAAA;;EAEtD,oBAAoB,MAAM;GACxB,MAAM,SAAS,eAAe,sBAAsB,IAAI,KAAK;GAC7D,OAAO,SAAS,QAAQ,oBAAoB,OAAO,GAAG,KAAA;;EAEzD;;AAGH,SAAS,wBACP,OACyB;CACzB,OAAO,QACL,SACA,OAAO,UAAU,YACjB,aAAa,SACb,2BAA2B,SAC3B,2BAA2B,MAC5B"}
@@ -44,21 +44,24 @@ var RuleTester = class {
44
44
  this.#inner = new RuleTester$1(config);
45
45
  }
46
46
  run(ruleName, rule, tests) {
47
- const workspace = mkdtempSync(join(tmpdir(), "corsa-oxlint-"));
48
- registerCleanup(workspace);
49
47
  const transformed = {
50
- valid: tests.valid.map((test) => prepareTestCase(workspace, test, this.#config)),
51
- invalid: tests.invalid.map((test) => prepareTestCase(workspace, test, this.#config))
48
+ valid: tests.valid.map((test, index) => prepareTestCase(createWorkspace(), test, this.#config, "valid", index)),
49
+ invalid: tests.invalid.map((test, index) => prepareTestCase(createWorkspace(), test, this.#config, "invalid", index))
52
50
  };
53
51
  this.#inner.run(ruleName, decorateRule(rule), transformed);
54
52
  }
55
53
  };
56
- function prepareTestCase(workspace, test, config) {
54
+ function createWorkspace() {
55
+ const workspace = mkdtempSync(join(tmpdir(), "corsa-oxlint-"));
56
+ registerCleanup(workspace);
57
+ return workspace;
58
+ }
59
+ function prepareTestCase(workspace, test, config, group, index) {
57
60
  if (typeof test === "string") {
58
- writeFixture(resolve(workspace, "fixture.ts"), test);
61
+ writeFixture(resolve(workspace, `${group}-${index}.ts`), test);
59
62
  return test;
60
63
  }
61
- const filename = resolve(workspace, test.filename ?? "fixture.ts");
64
+ const filename = resolve(workspace, test.filename ?? `${group}-${index}.ts`);
62
65
  writeFixture(filename, test.code);
63
66
  const testerConfig = config;
64
67
  const baseSettings = testerConfig?.settings?.typescriptOxlint;