corsa-oxlint 0.13.0 → 0.14.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 +9 -9
- package/dist/ast_utils.js +1 -1
- package/dist/checker.d.ts +4 -4
- package/dist/checker.js +3 -3
- package/dist/checker.js.map +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +1 -1
- package/dist/context.d.ts +3 -4
- package/dist/context.js +13 -18
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/json_schema.js +1 -1
- package/dist/node_map.d.ts +6 -6
- package/dist/node_map.js +11 -11
- package/dist/node_map.js.map +1 -1
- package/dist/oxlint_compat.js +1 -1
- package/dist/oxlint_utils.d.ts +1 -1
- package/dist/oxlint_utils.js +1 -1
- package/dist/parser_services.d.ts +1 -1
- package/dist/parser_services.js +2 -3
- package/dist/parser_services.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +1 -1
- package/dist/registry.d.ts +3 -3
- package/dist/registry.js +3 -3
- package/dist/registry.js.map +1 -1
- package/dist/rule_tester.d.ts +2 -2
- package/dist/rule_tester.js +7 -7
- package/dist/rule_tester.js.map +1 -1
- package/dist/rules/ast.d.ts +1 -1
- package/dist/rules/ast.js +1 -1
- package/dist/rules/await_thenable.d.ts +1 -1
- package/dist/rules/await_thenable.js +1 -1
- package/dist/rules/index.d.ts +4 -4
- package/dist/rules/index.js +8 -8
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/native_bridge.d.ts +1 -1
- package/dist/rules/native_bridge.js +1 -1
- package/dist/rules/native_bridge.js.map +1 -1
- package/dist/rules/no_array_delete.d.ts +1 -1
- package/dist/rules/no_array_delete.js +1 -1
- package/dist/rules/no_base_to_string.d.ts +1 -1
- package/dist/rules/no_base_to_string.js +1 -1
- package/dist/rules/no_floating_promises.d.ts +1 -1
- package/dist/rules/no_floating_promises.js +1 -1
- package/dist/rules/no_for_in_array.d.ts +1 -1
- package/dist/rules/no_for_in_array.js +1 -1
- package/dist/rules/no_implied_eval.d.ts +1 -1
- package/dist/rules/no_implied_eval.js +1 -1
- package/dist/rules/no_meaningless_void_operator.d.ts +1 -1
- package/dist/rules/no_meaningless_void_operator.js +1 -1
- package/dist/rules/no_mixed_enums.d.ts +1 -1
- package/dist/rules/no_mixed_enums.js +1 -1
- package/dist/rules/no_unsafe_assignment.d.ts +1 -1
- package/dist/rules/no_unsafe_assignment.js +1 -1
- package/dist/rules/no_unsafe_call.d.ts +1 -1
- package/dist/rules/no_unsafe_call.js +1 -1
- package/dist/rules/no_unsafe_member_access.d.ts +1 -1
- package/dist/rules/no_unsafe_member_access.js +1 -1
- package/dist/rules/no_unsafe_return.d.ts +1 -1
- package/dist/rules/no_unsafe_return.js +1 -1
- package/dist/rules/no_unsafe_type_assertion.d.ts +1 -1
- package/dist/rules/no_unsafe_type_assertion.js +1 -1
- package/dist/rules/no_unsafe_unary_minus.d.ts +1 -1
- package/dist/rules/no_unsafe_unary_minus.js +1 -1
- package/dist/rules/only_throw_error.d.ts +1 -1
- package/dist/rules/only_throw_error.js +1 -1
- package/dist/rules/pending_parity.d.ts +1 -1
- package/dist/rules/pending_parity.js +1 -1
- package/dist/rules/prefer_find.d.ts +1 -1
- package/dist/rules/prefer_find.js +1 -1
- package/dist/rules/prefer_includes.d.ts +1 -1
- package/dist/rules/prefer_includes.js +1 -1
- package/dist/rules/prefer_promise_reject_errors.d.ts +1 -1
- package/dist/rules/prefer_promise_reject_errors.js +1 -1
- package/dist/rules/prefer_reduce_type_parameter.d.ts +1 -1
- package/dist/rules/prefer_reduce_type_parameter.js +1 -1
- package/dist/rules/prefer_regexp_exec.d.ts +1 -1
- package/dist/rules/prefer_regexp_exec.js +1 -1
- package/dist/rules/prefer_string_starts_ends_with.d.ts +1 -1
- package/dist/rules/prefer_string_starts_ends_with.js +1 -1
- package/dist/rules/require_array_sort_compare.d.ts +1 -1
- package/dist/rules/require_array_sort_compare.js +1 -1
- package/dist/rules/restrict_plus_operands.d.ts +1 -1
- package/dist/rules/restrict_plus_operands.js +1 -1
- package/dist/rules/restrict_template_expressions.d.ts +1 -1
- package/dist/rules/restrict_template_expressions.js +1 -1
- package/dist/rules/rule_creator.d.ts +1 -1
- package/dist/rules/rule_creator.js +2 -2
- package/dist/rules/rule_creator.js.map +1 -1
- package/dist/rules/type_utils.d.ts +6 -6
- package/dist/rules/type_utils.js +1 -1
- package/dist/rules/type_utils.js.map +1 -1
- package/dist/rules/use_unknown_in_catch_callback_variable.d.ts +1 -1
- package/dist/rules/use_unknown_in_catch_callback_variable.js +1 -1
- package/dist/session.d.ts +29 -29
- package/dist/session.js +5 -5
- package/dist/session.js.map +1 -1
- package/dist/ts_eslint.d.ts +1 -1
- package/dist/ts_eslint.js +1 -1
- package/dist/ts_utils.js +1 -1
- package/dist/types.d.ts +53 -63
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -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.
|
|
29
|
+
`corsa oxlint` reads its type-aware settings from `settings.corsaOxlint`.
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import { OxlintUtils } from "corsa-oxlint";
|
|
@@ -76,12 +76,12 @@ export const noStringPlusNumber = createRule({
|
|
|
76
76
|
export default [
|
|
77
77
|
{
|
|
78
78
|
settings: {
|
|
79
|
-
|
|
79
|
+
corsaOxlint: {
|
|
80
80
|
parserOptions: {
|
|
81
81
|
project: ["./tsconfig.json"],
|
|
82
82
|
tsconfigRootDir: import.meta.dirname,
|
|
83
83
|
corsa: {
|
|
84
|
-
executable: "./.cache/
|
|
84
|
+
executable: "./.cache/corsa",
|
|
85
85
|
mode: "msgpack",
|
|
86
86
|
requestTimeoutMs: 30000,
|
|
87
87
|
},
|
|
@@ -99,12 +99,12 @@ Rule parity is tracked against upstream `tsgolint/internal/rules`, but the
|
|
|
99
99
|
runtime implementation lives entirely in this package.
|
|
100
100
|
|
|
101
101
|
```ts
|
|
102
|
-
import {
|
|
102
|
+
import { corsaOxlintPlugin } from "corsa-oxlint/rules";
|
|
103
103
|
|
|
104
104
|
export default [
|
|
105
105
|
{
|
|
106
106
|
plugins: {
|
|
107
|
-
typescript:
|
|
107
|
+
typescript: corsaOxlintPlugin,
|
|
108
108
|
},
|
|
109
109
|
rules: {
|
|
110
110
|
"typescript/no-floating-promises": "error",
|
|
@@ -155,13 +155,13 @@ such as `printNode` disabled by default.
|
|
|
155
155
|
|
|
156
156
|
```bash
|
|
157
157
|
vp install
|
|
158
|
-
vp run -w
|
|
158
|
+
vp run -w build_corsa_oxlint
|
|
159
159
|
vp fmt
|
|
160
160
|
vp lint
|
|
161
161
|
vp check
|
|
162
|
-
vp test run --config ./vite.config.ts src/bindings/nodejs/
|
|
163
|
-
vp test bench --config ./vite.config.ts bench/src/
|
|
164
|
-
vp test bench --config ./vite.config.ts bench/src/
|
|
162
|
+
vp test run --config ./vite.config.ts src/bindings/nodejs/corsa_oxlint/ts/**/*.test.ts
|
|
163
|
+
vp test bench --config ./vite.config.ts bench/src/corsa_oxlint.bench.ts
|
|
164
|
+
vp test bench --config ./vite.config.ts bench/src/corsa_oxlint_rules.bench.ts
|
|
165
165
|
vp run -w bench_tooling_compare
|
|
166
166
|
```
|
|
167
167
|
|
package/dist/ast_utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
//#region src/bindings/nodejs/
|
|
2
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/ast_utils.ts
|
|
3
3
|
var ast_utils_exports = /* @__PURE__ */ __exportAll({
|
|
4
4
|
ASTUtils: () => ASTUtils,
|
|
5
5
|
LINEBREAK_MATCHER: () => LINEBREAK_MATCHER,
|
package/dist/checker.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ContextWithParserOptions,
|
|
1
|
+
import { ContextWithParserOptions, CorsaProgramShape, CorsaTypeCheckerShape } from "./types.js";
|
|
2
2
|
import { createNodeMaps } from "./node_map.js";
|
|
3
3
|
|
|
4
|
-
//#region src/bindings/nodejs/
|
|
5
|
-
declare function createProgram(context: ContextWithParserOptions):
|
|
4
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/checker.d.ts
|
|
5
|
+
declare function createProgram(context: ContextWithParserOptions): CorsaProgramShape & {
|
|
6
6
|
readonly nodeMaps: ReturnType<typeof createNodeMaps>;
|
|
7
7
|
};
|
|
8
|
-
declare function createTypeChecker(context: ContextWithParserOptions):
|
|
8
|
+
declare function createTypeChecker(context: ContextWithParserOptions): CorsaTypeCheckerShape;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { createProgram, createTypeChecker };
|
|
11
11
|
//# sourceMappingURL=checker.d.ts.map
|
package/dist/checker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createNodeMaps, toPosition } from "./node_map.js";
|
|
2
2
|
import { sessionForContext } from "./registry.js";
|
|
3
|
-
//#region src/bindings/nodejs/
|
|
3
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/checker.ts
|
|
4
4
|
function createProgram(context) {
|
|
5
5
|
return {
|
|
6
6
|
nodeMaps: createNodeMaps(context),
|
|
@@ -81,7 +81,7 @@ function createTypeChecker(context) {
|
|
|
81
81
|
return sessionForContext(context).session.getBaseTypes(type);
|
|
82
82
|
},
|
|
83
83
|
getImplementedTypes(node) {
|
|
84
|
-
if ("pos" in node) return
|
|
84
|
+
if ("pos" in node) return implementedTypesFromCorsaNode(context, node, this);
|
|
85
85
|
return implementedClauseNodes(node).map((clause) => {
|
|
86
86
|
const expression = implementedClauseChildNode(clause, "expression") ?? clause;
|
|
87
87
|
const symbol = this.getSymbolAtLocation(expression) ?? this.getSymbolAtLocation(clause);
|
|
@@ -175,7 +175,7 @@ function implementedClauseChildNode(node, key) {
|
|
|
175
175
|
const value = node[key];
|
|
176
176
|
if (isNode(value)) return value;
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function implementedTypesFromCorsaNode(context, node, checker) {
|
|
179
179
|
const symbol = checker.getSymbolAtLocation(node);
|
|
180
180
|
if (symbol) {
|
|
181
181
|
const declaredType = checker.getDeclaredTypeOfSymbol(symbol) ?? checker.getTypeOfSymbol(symbol);
|
package/dist/checker.js.map
CHANGED
|
@@ -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 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,oB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,MAAM;EACZ,IAAI,OAAO;GACT,IAAI,SACF,UAAU;QACL,IAAI,SAAS,MAClB,UAAU;QACL,IAAI,SAAS,OAClB,QAAQ,KAAA;GAEV,OAAO;;EAET,IAAI,SAAS,QAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ;GACR,OAAO;;EAET,OAAO;IAEV;;AAGH,SAAS,OAAO,OAA+B;CAC7C,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,SAAS,WAAW;;AAGtF,SAAS,YACP,SACA,MACQ;CACR,IAAI,cAAc,MAChB,OAAO,KAAK;CAEd,OAAO,QAAQ"}
|
|
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 CorsaNode,\n CorsaProgramShape,\n CorsaSignature,\n CorsaSymbol,\n CorsaType,\n CorsaTypeCheckerShape,\n} from \"./types\";\n\nexport function createProgram(\n context: ContextWithParserOptions,\n): CorsaProgramShape & { 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): CorsaTypeCheckerShape {\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 implementedTypesFromCorsaNode(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 CorsaType => 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 | CorsaNode | CorsaType | CorsaSymbol | CorsaSignature,\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: CorsaTypeCheckerShape): CorsaType | 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 | CorsaNode): Node | CorsaNode {\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 | CorsaNode): 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 implementedTypesFromCorsaNode(\n context: ContextWithParserOptions,\n node: CorsaNode,\n checker: CorsaTypeCheckerShape,\n): readonly CorsaType[] {\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: CorsaNode = {\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 CorsaType => 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 | CorsaNode | CorsaType | CorsaSymbol | CorsaSignature,\n): string {\n if (\"fileName\" in node) {\n return node.fileName;\n }\n return context.filename;\n}\n"],"mappings":";;;AAcA,SAAgB,cACd,SAC8E;CAE9E,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,SAA0D;CAC1F,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;GACt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CACJ,IAAI,UAAU;CACd,OAAO,EACL,QAAQ,MAAM;EACZ,IAAI,OAAO;GACT,IAAI,SACF,UAAU;QACL,IAAI,SAAS,MAClB,UAAU;QACL,IAAI,SAAS,OAClB,QAAQ,KAAA;GAEV,OAAO;;EAET,IAAI,SAAS,QAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ;GACR,OAAO;;EAET,OAAO;IAEV;;AAGH,SAAS,OAAO,OAA+B;CAC7C,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,SAAS,WAAW;;AAGtF,SAAS,YACP,SACA,MACQ;CACR,IAAI,cAAc,MAChB,OAAO,KAAK;CAEd,OAAO,QAAQ"}
|
package/dist/compat.d.ts
CHANGED
package/dist/compat.js
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ContextWithParserOptions, ResolvedProjectConfig, TypeAwareParserOptions } from "./types.js";
|
|
2
2
|
|
|
3
|
-
//#region src/bindings/nodejs/
|
|
3
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/context.d.ts
|
|
4
4
|
declare function defaultCorsaExecutable(rootDir: string, platform?: NodeJS.Platform): string;
|
|
5
|
-
declare const defaultTsgoExecutable: typeof defaultCorsaExecutable;
|
|
6
5
|
declare function resolveProjectConfig(context: ContextWithParserOptions): ResolvedProjectConfig;
|
|
7
6
|
/**
|
|
8
7
|
* Resolves the type-aware parser options visible to a rule.
|
|
9
8
|
*
|
|
10
9
|
* Oxlint exposes a fixed `context.languageOptions.parserOptions` object at
|
|
11
10
|
* runtime, so `corsa oxlint` stores its richer configuration under
|
|
12
|
-
* `settings.
|
|
11
|
+
* `settings.corsaOxlint` and rehydrates the rule-facing parser options
|
|
13
12
|
* shape from there.
|
|
14
13
|
*
|
|
15
14
|
* @example
|
|
@@ -21,5 +20,5 @@ declare function resolveProjectConfig(context: ContextWithParserOptions): Resolv
|
|
|
21
20
|
declare function resolveTypeAwareParserOptions(context: ContextWithParserOptions): TypeAwareParserOptions;
|
|
22
21
|
declare function mergeTypeAwareParserOptions(base: TypeAwareParserOptions | undefined, override: TypeAwareParserOptions | undefined): TypeAwareParserOptions;
|
|
23
22
|
//#endregion
|
|
24
|
-
export { defaultCorsaExecutable,
|
|
23
|
+
export { defaultCorsaExecutable, mergeTypeAwareParserOptions, resolveProjectConfig, resolveTypeAwareParserOptions };
|
|
25
24
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
-
//#region src/bindings/nodejs/
|
|
3
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/context.ts
|
|
4
4
|
const DEFAULT_CACHE_LIFETIME_MS = 250;
|
|
5
5
|
const DEFAULT_PROJECT_PATTERNS = [
|
|
6
6
|
"*.ts",
|
|
@@ -14,9 +14,8 @@ const DEFAULT_TS_CONFIG = { compilerOptions: {
|
|
|
14
14
|
strict: true
|
|
15
15
|
} };
|
|
16
16
|
function defaultCorsaExecutable(rootDir, platform = process.platform) {
|
|
17
|
-
return resolve(rootDir, platform === "win32" ? ".cache/
|
|
17
|
+
return resolve(rootDir, platform === "win32" ? ".cache/corsa.exe" : ".cache/corsa");
|
|
18
18
|
}
|
|
19
|
-
const defaultTsgoExecutable = defaultCorsaExecutable;
|
|
20
19
|
function resolveProjectConfig(context) {
|
|
21
20
|
const filename = resolve(context.filename);
|
|
22
21
|
const parserOptions = resolveTypeAwareParserOptions(context);
|
|
@@ -36,7 +35,7 @@ function resolveProjectConfig(context) {
|
|
|
36
35
|
*
|
|
37
36
|
* Oxlint exposes a fixed `context.languageOptions.parserOptions` object at
|
|
38
37
|
* runtime, so `corsa oxlint` stores its richer configuration under
|
|
39
|
-
* `settings.
|
|
38
|
+
* `settings.corsaOxlint` and rehydrates the rule-facing parser options
|
|
40
39
|
* shape from there.
|
|
41
40
|
*
|
|
42
41
|
* @example
|
|
@@ -46,12 +45,12 @@ function resolveProjectConfig(context) {
|
|
|
46
45
|
* ```
|
|
47
46
|
*/
|
|
48
47
|
function resolveTypeAwareParserOptions(context) {
|
|
49
|
-
return mergeTypeAwareParserOptions(resolveSettingsParserOptions(context.settings?.
|
|
48
|
+
return mergeTypeAwareParserOptions(resolveSettingsParserOptions(context.settings?.corsaOxlint), mergeTypeAwareParserOptions(context.parserOptions, context.languageOptions?.parserOptions));
|
|
50
49
|
}
|
|
51
50
|
function resolveRuntimeOptions(rootDir, parserOptions) {
|
|
52
|
-
const runtime = parserOptions.corsa
|
|
51
|
+
const runtime = parserOptions.corsa;
|
|
53
52
|
return {
|
|
54
|
-
executable: resolve(runtime?.executable ?? process.env.CORSA_EXECUTABLE ??
|
|
53
|
+
executable: resolve(runtime?.executable ?? process.env.CORSA_EXECUTABLE ?? defaultCorsaExecutable(rootDir)),
|
|
55
54
|
cwd: resolve(runtime?.cwd ?? rootDir),
|
|
56
55
|
mode: runtime?.mode ?? "msgpack",
|
|
57
56
|
cacheLifetimeMs: runtime?.cacheLifetimeMs ?? DEFAULT_CACHE_LIFETIME_MS
|
|
@@ -78,7 +77,7 @@ function resolveDefaultProject(rootDir, filename, projectService) {
|
|
|
78
77
|
if (projectService !== true && projectService.defaultProject) return resolve(rootDir, projectService.defaultProject);
|
|
79
78
|
if (!matchesDefaultProject(filename, projectService)) return;
|
|
80
79
|
const id = Buffer.from(filename).toString("hex").slice(0, 24);
|
|
81
|
-
const cacheDir = resolve(rootDir, ".cache/
|
|
80
|
+
const cacheDir = resolve(rootDir, ".cache/corsa_oxlint/default");
|
|
82
81
|
const configPath = resolve(cacheDir, `${id}.tsconfig.json`);
|
|
83
82
|
if (!existsSync(configPath)) {
|
|
84
83
|
mkdirSync(cacheDir, { recursive: true });
|
|
@@ -108,8 +107,8 @@ function mergeTypeAwareParserOptions(base, override) {
|
|
|
108
107
|
if (!base) return normalizeTypeAwareParserOptions(override ?? {});
|
|
109
108
|
if (!override) return normalizeTypeAwareParserOptions(base);
|
|
110
109
|
const runtime = {
|
|
111
|
-
...base.corsa
|
|
112
|
-
...override.corsa
|
|
110
|
+
...base.corsa,
|
|
111
|
+
...override.corsa
|
|
113
112
|
};
|
|
114
113
|
return {
|
|
115
114
|
...base,
|
|
@@ -117,19 +116,15 @@ function mergeTypeAwareParserOptions(base, override) {
|
|
|
117
116
|
project: override.project ?? base.project,
|
|
118
117
|
projectService: mergeProjectService(base.projectService, override.projectService),
|
|
119
118
|
tsconfigRootDir: override.tsconfigRootDir ?? base.tsconfigRootDir,
|
|
120
|
-
...Object.keys(runtime).length > 0 ? {
|
|
121
|
-
corsa: runtime,
|
|
122
|
-
tsgo: runtime
|
|
123
|
-
} : {}
|
|
119
|
+
...Object.keys(runtime).length > 0 ? { corsa: runtime } : {}
|
|
124
120
|
};
|
|
125
121
|
}
|
|
126
122
|
function normalizeTypeAwareParserOptions(options) {
|
|
127
|
-
const runtime = options.corsa
|
|
123
|
+
const runtime = options.corsa;
|
|
128
124
|
if (!runtime) return options;
|
|
129
125
|
return {
|
|
130
126
|
...options,
|
|
131
|
-
corsa: runtime
|
|
132
|
-
tsgo: runtime
|
|
127
|
+
corsa: runtime
|
|
133
128
|
};
|
|
134
129
|
}
|
|
135
130
|
function mergeProjectService(base, override) {
|
|
@@ -144,6 +139,6 @@ function mergeProjectService(base, override) {
|
|
|
144
139
|
};
|
|
145
140
|
}
|
|
146
141
|
//#endregion
|
|
147
|
-
export { defaultCorsaExecutable,
|
|
142
|
+
export { defaultCorsaExecutable, mergeTypeAwareParserOptions, resolveProjectConfig, resolveTypeAwareParserOptions };
|
|
148
143
|
|
|
149
144
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -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 allowDefault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/D,OAAO,QAAS,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM,GAAI,EAAE;;AAG9D,SAAS,6BACP,UACwB;CACxB,IAAI,CAAC,UACH,OAAO,EAAE;CAEX,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 CorsaOxlintSettings,\n ProjectServiceOptions,\n ResolvedProjectConfig,\n ResolvedRuntimeOptions,\n TypeAwareParserOptions,\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/corsa.exe\" : \".cache/corsa\");\n}\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.corsaOxlint` 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?.corsaOxlint),\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;\n return {\n executable: resolve(\n runtime?.executable ?? process.env.CORSA_EXECUTABLE ?? 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/corsa_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: CorsaOxlintSettings | 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,\n ...override.corsa,\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 } : {}),\n };\n}\n\nfunction normalizeTypeAwareParserOptions(options: TypeAwareParserOptions): TypeAwareParserOptions {\n const runtime = options.corsa;\n if (!runtime) {\n return options;\n }\n return {\n ...options,\n corsa: 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,EACx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;CACxB,IAAI,CAAC,MACH,OAAO,gCAAgC,YAAY,EAAE,CAAC;CAExD,IAAI,CAAC,UACH,OAAO,gCAAgC,KAAK;CAE9C,MAAM,UAAU;EACd,GAAG,KAAK;EACR,GAAG,SAAS;EACb;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,EAAE,OAAO,SAAS,GAAG,EAAE;EAC9D;;AAGH,SAAS,gCAAgC,SAAyD;CAChG,MAAM,UAAU,QAAQ;CACxB,IAAI,CAAC,SACH,OAAO;CAET,OAAO;EACL,GAAG;EACH,OAAO;EACR;;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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ast_utils_d_exports } from "./ast_utils.js";
|
|
2
|
-
import { ContextWithParserOptions, CorsaNode, CorsaProgramShape, CorsaRuntimeOptions, CorsaSignature, CorsaSymbol, CorsaType, CorsaTypeCheckerShape, ParserServices, ParserServicesWithTypeInformation, ProjectServiceOptions,
|
|
2
|
+
import { ContextWithParserOptions, CorsaNode, CorsaOxlintSettings, CorsaProgramShape, CorsaRuntimeOptions, CorsaSignature, CorsaSymbol, CorsaType, CorsaTypeCheckerShape, ParserServices, ParserServicesWithTypeInformation, ProjectServiceOptions, TypeAwareParserOptions } from "./types.js";
|
|
3
3
|
import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from "./compat.js";
|
|
4
4
|
import { json_schema_d_exports } from "./json_schema.js";
|
|
5
5
|
import { oxlintCompat, oxlint_compat_d_exports } from "./oxlint_compat.js";
|
|
@@ -11,4 +11,4 @@ import { compatPlugin, definePlugin, defineRule } from "./plugin.js";
|
|
|
11
11
|
import { RuleTester } from "./rule_tester.js";
|
|
12
12
|
import { TSESLint } from "./ts_eslint.js";
|
|
13
13
|
import { index_d_exports } from "./rules/index.js";
|
|
14
|
-
export { ast_utils_d_exports as ASTUtils, AST_NODE_TYPES, AST_TOKEN_TYPES, type ContextWithParserOptions, type CorsaNode, type CorsaProgramShape, type CorsaRuntimeOptions, type CorsaSignature, type CorsaSymbol, type CorsaType, type CorsaTypeCheckerShape, ESLintUtils, json_schema_d_exports as JSONSchema, oxlint_compat_d_exports as OxlintCompat, OxlintUtils, type ParserServices, type ParserServicesWithTypeInformation, type ProjectServiceOptions, RuleCreator, RuleTester, TSESLint, TSESTree, ts_utils_d_exports as TSUtils, type
|
|
14
|
+
export { ast_utils_d_exports as ASTUtils, AST_NODE_TYPES, AST_TOKEN_TYPES, type ContextWithParserOptions, type CorsaNode, type CorsaOxlintSettings, type CorsaProgramShape, type CorsaRuntimeOptions, type CorsaSignature, type CorsaSymbol, type CorsaType, type CorsaTypeCheckerShape, ESLintUtils, json_schema_d_exports as JSONSchema, oxlint_compat_d_exports as OxlintCompat, OxlintUtils, type ParserServices, type ParserServicesWithTypeInformation, type ProjectServiceOptions, RuleCreator, RuleTester, TSESLint, TSESTree, ts_utils_d_exports as TSUtils, type TypeAwareParserOptions, utils_d_exports as Utils, compatPlugin, definePlugin, defineRule, getParserServices, oxlintCompat, index_d_exports as rules };
|
package/dist/json_schema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
//#region src/bindings/nodejs/
|
|
2
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/json_schema.ts
|
|
3
3
|
var json_schema_exports = /* @__PURE__ */ __exportAll({
|
|
4
4
|
JSONSchema: () => JSONSchema,
|
|
5
5
|
tupleSchema: () => tupleSchema
|
package/dist/node_map.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ContextWithParserOptions,
|
|
1
|
+
import { ContextWithParserOptions, CorsaNode } from "./types.js";
|
|
2
2
|
import { Node } from "@oxlint/plugins";
|
|
3
3
|
|
|
4
|
-
//#region src/bindings/nodejs/
|
|
4
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/node_map.d.ts
|
|
5
5
|
declare function createNodeMaps(context: ContextWithParserOptions): {
|
|
6
6
|
esTreeNodeToTSNodeMap: {
|
|
7
|
-
get(node: Node):
|
|
7
|
+
get(node: Node): CorsaNode;
|
|
8
8
|
has(node: Node): boolean;
|
|
9
9
|
};
|
|
10
10
|
tsNodeToESTreeNodeMap: {
|
|
11
|
-
get(node:
|
|
12
|
-
has(node:
|
|
11
|
+
get(node: CorsaNode): Node;
|
|
12
|
+
has(node: CorsaNode): boolean;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
declare function toPosition(node: Node |
|
|
15
|
+
declare function toPosition(node: Node | CorsaNode): number;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { createNodeMaps, toPosition };
|
|
18
18
|
//# sourceMappingURL=node_map.d.ts.map
|
package/dist/node_map.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
//#region src/bindings/nodejs/
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/node_map.ts
|
|
2
|
+
const estreeToCorsa = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
const corsaToEstree = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
function createNodeMaps(context) {
|
|
5
5
|
return {
|
|
6
6
|
esTreeNodeToTSNodeMap: {
|
|
7
7
|
get(node) {
|
|
8
|
-
let current =
|
|
8
|
+
let current = estreeToCorsa.get(node);
|
|
9
9
|
if (!current) {
|
|
10
|
-
current =
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
current = createCorsaNode(context.filename, node);
|
|
11
|
+
estreeToCorsa.set(node, current);
|
|
12
|
+
corsaToEstree.set(current, node);
|
|
13
13
|
}
|
|
14
14
|
return current;
|
|
15
15
|
},
|
|
16
16
|
has(node) {
|
|
17
|
-
return
|
|
17
|
+
return estreeToCorsa.has(node);
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
tsNodeToESTreeNodeMap: {
|
|
21
21
|
get(node) {
|
|
22
|
-
const value =
|
|
22
|
+
const value = corsaToEstree.get(node);
|
|
23
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) {
|
|
27
|
-
return
|
|
27
|
+
return corsaToEstree.has(node);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
};
|
|
@@ -32,7 +32,7 @@ function createNodeMaps(context) {
|
|
|
32
32
|
function toPosition(node) {
|
|
33
33
|
return "pos" in node ? node.pos : assertRange(node)[0];
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function createCorsaNode(fileName, node) {
|
|
36
36
|
const [pos, end] = assertRange(node);
|
|
37
37
|
return {
|
|
38
38
|
fileName,
|
package/dist/node_map.js.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"node_map.js","names":[],"sources":["../ts/node_map.ts"],"sourcesContent":["import type { Node } from \"@oxlint/plugins\";\n\nimport type { ContextWithParserOptions, CorsaNode } from \"./types\";\n\nconst estreeToCorsa = new WeakMap<object, CorsaNode>();\nconst corsaToEstree = new WeakMap<object, Node>();\n\nexport function createNodeMaps(context: ContextWithParserOptions): {\n esTreeNodeToTSNodeMap: {\n get(node: Node): CorsaNode;\n has(node: Node): boolean;\n };\n tsNodeToESTreeNodeMap: {\n get(node: CorsaNode): Node;\n has(node: CorsaNode): boolean;\n };\n} {\n return {\n esTreeNodeToTSNodeMap: {\n get(node) {\n let current = estreeToCorsa.get(node);\n if (!current) {\n current = createCorsaNode(context.filename, node);\n estreeToCorsa.set(node, current);\n corsaToEstree.set(current, node);\n }\n return current;\n },\n has(node) {\n return estreeToCorsa.has(node);\n },\n },\n tsNodeToESTreeNodeMap: {\n get(node) {\n const value = corsaToEstree.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 corsaToEstree.has(node);\n },\n },\n };\n}\n\nexport function toPosition(node: Node | CorsaNode): number {\n return \"pos\" in node ? node.pos : assertRange(node)[0];\n}\n\nfunction createCorsaNode(fileName: string, node: Node): CorsaNode {\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,gCAAgB,IAAI,SAA4B;AACtD,MAAM,gCAAgB,IAAI,SAAuB;AAEjD,SAAgB,eAAe,SAS7B;CACA,OAAO;EACL,uBAAuB;GACrB,IAAI,MAAM;IACR,IAAI,UAAU,cAAc,IAAI,KAAK;IACrC,IAAI,CAAC,SAAS;KACZ,UAAU,gBAAgB,QAAQ,UAAU,KAAK;KACjD,cAAc,IAAI,MAAM,QAAQ;KAChC,cAAc,IAAI,SAAS,KAAK;;IAElC,OAAO;;GAET,IAAI,MAAM;IACR,OAAO,cAAc,IAAI,KAAK;;GAEjC;EACD,uBAAuB;GACrB,IAAI,MAAM;IACR,MAAM,QAAQ,cAAc,IAAI,KAAK;IACrC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,uDAAuD;IAEzE,OAAO;;GAET,IAAI,MAAM;IACR,OAAO,cAAc,IAAI,KAAK;;GAEjC;EACF;;AAGH,SAAgB,WAAW,MAAgC;CACzD,OAAO,SAAS,OAAO,KAAK,MAAM,YAAY,KAAK,CAAC;;AAGtD,SAAS,gBAAgB,UAAkB,MAAuB;CAChE,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"}
|
package/dist/oxlint_compat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
//#region src/bindings/nodejs/
|
|
2
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/oxlint_compat.ts
|
|
3
3
|
var oxlint_compat_exports = /* @__PURE__ */ __exportAll({ oxlintCompat: () => oxlintCompat });
|
|
4
4
|
const oxlintCompat = Object.freeze({
|
|
5
5
|
config(...configs) {
|
package/dist/oxlint_utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ContextWithParserOptions, ParserServices } from "./types.js";
|
|
|
2
2
|
import { getParserServices } from "./parser_services.js";
|
|
3
3
|
import { Rule, RuleMeta, Visitor } from "@oxlint/plugins";
|
|
4
4
|
|
|
5
|
-
//#region src/bindings/nodejs/
|
|
5
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/oxlint_utils.d.ts
|
|
6
6
|
type RuleCreatorRule<TOptions extends readonly unknown[] = readonly unknown[], TMessageIds extends string = string> = {
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly meta: RuleMeta & {
|
package/dist/oxlint_utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getParserServices } from "./parser_services.js";
|
|
2
2
|
import { decorateRule } from "./plugin.js";
|
|
3
|
-
//#region src/bindings/nodejs/
|
|
3
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/oxlint_utils.ts
|
|
4
4
|
/**
|
|
5
5
|
* Self-hosted type-aware utilities for Oxlint rules backed by Corsa.
|
|
6
6
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContextWithParserOptions, ParserServices } from "./types.js";
|
|
2
2
|
|
|
3
|
-
//#region src/bindings/nodejs/
|
|
3
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/parser_services.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Returns type-aware parser services backed by Corsa.
|
|
6
6
|
*
|
package/dist/parser_services.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createNodeMaps } from "./node_map.js";
|
|
2
2
|
import { resolveTypeAwareParserOptions } from "./context.js";
|
|
3
3
|
import { createProgram, createTypeChecker } from "./checker.js";
|
|
4
|
-
//#region src/bindings/nodejs/
|
|
4
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/parser_services.ts
|
|
5
5
|
const parserServices = /* @__PURE__ */ new WeakMap();
|
|
6
6
|
/**
|
|
7
7
|
* Returns type-aware parser services backed by Corsa.
|
|
@@ -15,8 +15,7 @@ const parserServices = /* @__PURE__ */ new WeakMap();
|
|
|
15
15
|
function getParserServices(context, allowWithoutFullTypeInformation = false) {
|
|
16
16
|
const current = parserServices.get(context);
|
|
17
17
|
if (current) return current;
|
|
18
|
-
|
|
19
|
-
if (!parserOptions.corsa && !parserOptions.tsgo && hasEslintParserServices(context.parserServices)) {
|
|
18
|
+
if (!resolveTypeAwareParserOptions(context).corsa && hasEslintParserServices(context.parserServices)) {
|
|
20
19
|
const services = createEslintParserServices(context);
|
|
21
20
|
parserServices.set(context, services);
|
|
22
21
|
return services;
|
|
@@ -1 +1 @@
|
|
|
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 (
|
|
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 (!parserOptions.corsa && hasEslintParserServices(context.parserServices)) {\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 &&\n typeof value === \"object\" &&\n \"program\" in value &&\n \"esTreeNodeToTSNodeMap\" in value &&\n \"tsNodeToESTreeNodeMap\" in value,\n );\n}\n"],"mappings":";;;;AASA,MAAM,iCAAiB,IAAI,SAAiC;;;;;;;;;;AAW5D,SAAgB,kBACd,SACA,kCAAkC,OAClB;CAChB,MAAM,UAAU,eAAe,IAAI,QAAQ;CAC3C,IAAI,SACF,OAAO;CAGT,IAAI,CADkB,8BAA8B,QAClC,CAAC,SAAS,wBAAwB,QAAQ,eAAe,EAAE;EAC3E,MAAM,WAAW,2BAA2B,QAAQ;EACpD,eAAe,IAAI,SAAS,SAAS;EACrC,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;;;AAIX,SAAS,2BACP,SACmC;CACnC,MAAM,iBAAiB,QAAQ;CAC/B,MAAM,UAAU,eAAe,QAAQ,gBAAgB;CACvD,OAAO;EACL,SAAS,eAAe;EACxB,uBAAuB,eAAe;EACtC,uBAAuB,eAAe;EACtC,wBAAwB;EACxB,kBAAkB,MAAM;GACtB,MAAM,SAAS,eAAe,sBAAsB,IAAI,KAAK;GAC7D,OAAO,SAAS,QAAQ,kBAAkB,OAAO,GAAG,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"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin, Rule } from "@oxlint/plugins";
|
|
2
2
|
|
|
3
|
-
//#region src/bindings/nodejs/
|
|
3
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/plugin.d.ts
|
|
4
4
|
type PluginShape = Plugin;
|
|
5
5
|
type RuleShape = Rule;
|
|
6
6
|
declare function definePlugin<Plugin extends PluginShape>(plugin: Plugin): Plugin;
|
package/dist/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveTypeAwareParserOptions } from "./context.js";
|
|
2
2
|
import { getParserServices } from "./parser_services.js";
|
|
3
3
|
import * as oxlintPluginApi from "@oxlint/plugins";
|
|
4
|
-
//#region src/bindings/nodejs/
|
|
4
|
+
//#region src/bindings/nodejs/corsa_oxlint/ts/plugin.ts
|
|
5
5
|
const defineOxlintPlugin = oxlintPluginApi.definePlugin;
|
|
6
6
|
const defineOxlintRule = oxlintPluginApi.defineRule;
|
|
7
7
|
const baseCompatPlugin = Reflect.get(oxlintPluginApi, ["es", "lintCompatPlugin"].join(""));
|