corsa-oxlint 0.1.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/LICENSE +21 -0
- package/README.md +171 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/ast_utils.d.ts +17 -0
- package/dist/ast_utils.js +21 -0
- package/dist/ast_utils.js.map +1 -0
- package/dist/checker.d.ts +11 -0
- package/dist/checker.js +80 -0
- package/dist/checker.js.map +1 -0
- package/dist/compat.d.ts +194 -0
- package/dist/compat.js +103 -0
- package/dist/compat.js.map +1 -0
- package/dist/context.d.ts +24 -0
- package/dist/context.js +134 -0
- package/dist/context.js.map +1 -0
- package/dist/eslint_utils.d.ts +19 -0
- package/dist/eslint_utils.js +48 -0
- package/dist/eslint_utils.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11 -0
- package/dist/json_schema.d.ts +11 -0
- package/dist/json_schema.js +17 -0
- package/dist/json_schema.js.map +1 -0
- package/dist/node_map.d.ts +18 -0
- package/dist/node_map.js +52 -0
- package/dist/node_map.js.map +1 -0
- package/dist/parser_services.d.ts +16 -0
- package/dist/parser_services.js +48 -0
- package/dist/parser_services.js.map +1 -0
- package/dist/plugin.d.ts +26 -0
- package/dist/plugin.js +83 -0
- package/dist/plugin.js.map +1 -0
- package/dist/registry.d.ts +12 -0
- package/dist/registry.js +35 -0
- package/dist/registry.js.map +1 -0
- package/dist/rule_tester.d.ts +37 -0
- package/dist/rule_tester.js +120 -0
- package/dist/rule_tester.js.map +1 -0
- package/dist/rules/ast.d.ts +16 -0
- package/dist/rules/ast.js +56 -0
- package/dist/rules/ast.js.map +1 -0
- package/dist/rules/await_thenable.d.ts +16 -0
- package/dist/rules/await_thenable.js +23 -0
- package/dist/rules/await_thenable.js.map +1 -0
- package/dist/rules/index.d.ts +473 -0
- package/dist/rules/index.js +120 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/no_array_delete.d.ts +16 -0
- package/dist/rules/no_array_delete.js +29 -0
- package/dist/rules/no_array_delete.js.map +1 -0
- package/dist/rules/no_base_to_string.d.ts +16 -0
- package/dist/rules/no_base_to_string.js +66 -0
- package/dist/rules/no_base_to_string.js.map +1 -0
- package/dist/rules/no_floating_promises.d.ts +16 -0
- package/dist/rules/no_floating_promises.js +42 -0
- package/dist/rules/no_floating_promises.js.map +1 -0
- package/dist/rules/no_for_in_array.d.ts +16 -0
- package/dist/rules/no_for_in_array.js +16 -0
- package/dist/rules/no_for_in_array.js.map +1 -0
- package/dist/rules/no_implied_eval.d.ts +16 -0
- package/dist/rules/no_implied_eval.js +35 -0
- package/dist/rules/no_implied_eval.js.map +1 -0
- package/dist/rules/no_mixed_enums.d.ts +16 -0
- package/dist/rules/no_mixed_enums.js +41 -0
- package/dist/rules/no_mixed_enums.js.map +1 -0
- package/dist/rules/no_unsafe_assignment.d.ts +16 -0
- package/dist/rules/no_unsafe_assignment.js +41 -0
- package/dist/rules/no_unsafe_assignment.js.map +1 -0
- package/dist/rules/no_unsafe_return.d.ts +16 -0
- package/dist/rules/no_unsafe_return.js +56 -0
- package/dist/rules/no_unsafe_return.js.map +1 -0
- package/dist/rules/no_unsafe_unary_minus.d.ts +16 -0
- package/dist/rules/no_unsafe_unary_minus.js +28 -0
- package/dist/rules/no_unsafe_unary_minus.js.map +1 -0
- package/dist/rules/only_throw_error.d.ts +16 -0
- package/dist/rules/only_throw_error.js +16 -0
- package/dist/rules/only_throw_error.js.map +1 -0
- package/dist/rules/prefer_find.d.ts +16 -0
- package/dist/rules/prefer_find.js +25 -0
- package/dist/rules/prefer_find.js.map +1 -0
- package/dist/rules/prefer_includes.d.ts +16 -0
- package/dist/rules/prefer_includes.js +21 -0
- package/dist/rules/prefer_includes.js.map +1 -0
- package/dist/rules/prefer_promise_reject_errors.d.ts +16 -0
- package/dist/rules/prefer_promise_reject_errors.js +52 -0
- package/dist/rules/prefer_promise_reject_errors.js.map +1 -0
- package/dist/rules/prefer_regexp_exec.d.ts +16 -0
- package/dist/rules/prefer_regexp_exec.js +20 -0
- package/dist/rules/prefer_regexp_exec.js.map +1 -0
- package/dist/rules/prefer_string_starts_ends_with.d.ts +16 -0
- package/dist/rules/prefer_string_starts_ends_with.js +53 -0
- package/dist/rules/prefer_string_starts_ends_with.js.map +1 -0
- package/dist/rules/require_array_sort_compare.d.ts +16 -0
- package/dist/rules/require_array_sort_compare.js +36 -0
- package/dist/rules/require_array_sort_compare.js.map +1 -0
- package/dist/rules/restrict_plus_operands.d.ts +16 -0
- package/dist/rules/restrict_plus_operands.js +62 -0
- package/dist/rules/restrict_plus_operands.js.map +1 -0
- package/dist/rules/rule_creator.d.ts +16 -0
- package/dist/rules/rule_creator.js +22 -0
- package/dist/rules/rule_creator.js.map +1 -0
- package/dist/rules/type_utils.d.ts +56 -0
- package/dist/rules/type_utils.js +102 -0
- package/dist/rules/type_utils.js.map +1 -0
- package/dist/rules/use_unknown_in_catch_callback_variable.d.ts +16 -0
- package/dist/rules/use_unknown_in_catch_callback_variable.js +19 -0
- package/dist/rules/use_unknown_in_catch_callback_variable.js.map +1 -0
- package/dist/session.d.ts +32 -0
- package/dist/session.js +179 -0
- package/dist/session.js.map +1 -0
- package/dist/ts_eslint.d.ts +22 -0
- package/dist/ts_eslint.js +30 -0
- package/dist/ts_eslint.js.map +1 -0
- package/dist/ts_estree.d.ts +2 -0
- package/dist/ts_estree.js +2 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +22 -0
- package/dist/utils.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as oxlint_plugins_dev0 from "oxlint/plugins-dev";
|
|
2
|
+
|
|
3
|
+
//#region src/bindings/nodejs/typescript_oxlint/ts/rule_tester.d.ts
|
|
4
|
+
type TesterConfig = oxlint_plugins_dev0.RuleTester.Config;
|
|
5
|
+
type TestCase = oxlint_plugins_dev0.RuleTester.ValidTestCase & Partial<oxlint_plugins_dev0.RuleTester.InvalidTestCase>;
|
|
6
|
+
type TestCases = oxlint_plugins_dev0.RuleTester.TestCases;
|
|
7
|
+
declare class RuleTester {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* A thin Oxlint `RuleTester` wrapper that injects
|
|
11
|
+
* `settings.typescriptOxlint`
|
|
12
|
+
* settings, temporary fixtures, and a default project service.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const tester = new RuleTester();
|
|
17
|
+
* tester.run("demo", rule, {
|
|
18
|
+
* valid: [{ code: "const answer = 42;" }],
|
|
19
|
+
* invalid: [],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
static get describe(): (text: string, fn: () => void) => void;
|
|
24
|
+
static set describe(value: (text: string, fn: () => void) => void);
|
|
25
|
+
static get it(): ((text: string, fn: () => void) => void) & {
|
|
26
|
+
only?: ((text: string, fn: () => void) => void) & /*elided*/any;
|
|
27
|
+
};
|
|
28
|
+
static set it(value: ((text: string, fn: () => void) => void) & {
|
|
29
|
+
only?: ((text: string, fn: () => void) => void) & /*elided*/any;
|
|
30
|
+
});
|
|
31
|
+
static only(item: string | TestCase): TestCase;
|
|
32
|
+
constructor(config?: TesterConfig);
|
|
33
|
+
run(ruleName: string, rule: Record<string, unknown>, tests: TestCases): void;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { RuleTester };
|
|
37
|
+
//# sourceMappingURL=rule_tester.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mergeTypeAwareParserOptions } from "./context.js";
|
|
2
|
+
import { decorateRule } from "./plugin.js";
|
|
3
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { RuleTester as RuleTester$1 } from "oxlint/plugins-dev";
|
|
7
|
+
//#region src/bindings/nodejs/typescript_oxlint/ts/rule_tester.ts
|
|
8
|
+
const cleanupDirs = /* @__PURE__ */ new Set();
|
|
9
|
+
let cleanupInstalled = false;
|
|
10
|
+
var RuleTester = class {
|
|
11
|
+
/**
|
|
12
|
+
* A thin Oxlint `RuleTester` wrapper that injects
|
|
13
|
+
* `settings.typescriptOxlint`
|
|
14
|
+
* settings, temporary fixtures, and a default project service.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const tester = new RuleTester();
|
|
19
|
+
* tester.run("demo", rule, {
|
|
20
|
+
* valid: [{ code: "const answer = 42;" }],
|
|
21
|
+
* invalid: [],
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
static get describe() {
|
|
26
|
+
return RuleTester$1.describe;
|
|
27
|
+
}
|
|
28
|
+
static set describe(value) {
|
|
29
|
+
RuleTester$1.describe = value;
|
|
30
|
+
}
|
|
31
|
+
static get it() {
|
|
32
|
+
return RuleTester$1.it;
|
|
33
|
+
}
|
|
34
|
+
static set it(value) {
|
|
35
|
+
RuleTester$1.it = value;
|
|
36
|
+
}
|
|
37
|
+
static only(item) {
|
|
38
|
+
return RuleTester$1.only(item);
|
|
39
|
+
}
|
|
40
|
+
#inner;
|
|
41
|
+
#config;
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.#config = config;
|
|
44
|
+
this.#inner = new RuleTester$1(config);
|
|
45
|
+
}
|
|
46
|
+
run(ruleName, rule, tests) {
|
|
47
|
+
const workspace = mkdtempSync(join(tmpdir(), "oxlint-plugin-typescript-go-"));
|
|
48
|
+
registerCleanup(workspace);
|
|
49
|
+
const transformed = {
|
|
50
|
+
valid: tests.valid.map((test) => prepareTestCase(workspace, test, this.#config)),
|
|
51
|
+
invalid: tests.invalid.map((test) => prepareTestCase(workspace, test, this.#config))
|
|
52
|
+
};
|
|
53
|
+
this.#inner.run(ruleName, decorateRule(rule), transformed);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function prepareTestCase(workspace, test, config) {
|
|
57
|
+
if (typeof test === "string") {
|
|
58
|
+
writeFixture(resolve(workspace, "fixture.ts"), test);
|
|
59
|
+
return test;
|
|
60
|
+
}
|
|
61
|
+
const filename = resolve(workspace, test.filename ?? "fixture.ts");
|
|
62
|
+
writeFixture(filename, test.code);
|
|
63
|
+
const testerConfig = config;
|
|
64
|
+
const baseSettings = testerConfig?.settings?.typescriptOxlint;
|
|
65
|
+
const caseSettings = test.settings?.typescriptOxlint;
|
|
66
|
+
const parserOptions = mergeTypeAwareParserOptions(mergeTypeAwareParserOptions(mergeTypeAwareParserOptions(mergeTypeAwareParserOptions(baseSettings, baseSettings?.parserOptions), mergeTypeAwareParserOptions(caseSettings, caseSettings?.parserOptions)), {
|
|
67
|
+
tsconfigRootDir: workspace,
|
|
68
|
+
projectService: { allowDefaultProject: [
|
|
69
|
+
"*.ts",
|
|
70
|
+
"*.tsx",
|
|
71
|
+
"*.js",
|
|
72
|
+
"*.jsx"
|
|
73
|
+
] }
|
|
74
|
+
}), mergeTypeAwareParserOptions(config?.languageOptions?.parserOptions, test.languageOptions?.parserOptions));
|
|
75
|
+
return {
|
|
76
|
+
...test,
|
|
77
|
+
filename,
|
|
78
|
+
settings: {
|
|
79
|
+
...testerConfig?.settings,
|
|
80
|
+
...test.settings,
|
|
81
|
+
typescriptOxlint: {
|
|
82
|
+
...testerConfig?.settings?.typescriptOxlint,
|
|
83
|
+
...test.settings?.typescriptOxlint,
|
|
84
|
+
parserOptions
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
languageOptions: {
|
|
88
|
+
...config?.languageOptions,
|
|
89
|
+
...test.languageOptions,
|
|
90
|
+
parserOptions: { ...parserOptions }
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function writeFixture(filename, code) {
|
|
95
|
+
mkdirSync(dirname(filename), { recursive: true });
|
|
96
|
+
writeFileSync(filename, code);
|
|
97
|
+
writeFileSync(resolve(dirname(filename), "tsconfig.json"), JSON.stringify({
|
|
98
|
+
compilerOptions: {
|
|
99
|
+
module: "esnext",
|
|
100
|
+
target: "es2022",
|
|
101
|
+
strict: true
|
|
102
|
+
},
|
|
103
|
+
include: ["**/*"]
|
|
104
|
+
}, null, 2));
|
|
105
|
+
}
|
|
106
|
+
function registerCleanup(workspace) {
|
|
107
|
+
cleanupDirs.add(workspace);
|
|
108
|
+
if (cleanupInstalled) return;
|
|
109
|
+
cleanupInstalled = true;
|
|
110
|
+
process.on("exit", () => {
|
|
111
|
+
for (const dir of cleanupDirs) rmSync(dir, {
|
|
112
|
+
force: true,
|
|
113
|
+
recursive: true
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
export { RuleTester };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=rule_tester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule_tester.js","names":["OxlintRuleTester","#inner","#config"],"sources":["../ts/rule_tester.ts"],"sourcesContent":["import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\n\nimport { RuleTester as OxlintRuleTester } from \"oxlint/plugins-dev\";\n\nimport { mergeTypeAwareParserOptions } from \"./context\";\nimport { decorateRule } from \"./plugin\";\nimport type { TypeAwareParserOptions, TypescriptOxlintSettings } from \"./types\";\n\ntype TesterConfig = import(\"oxlint/plugins-dev\").RuleTester.Config;\ntype TestCase = import(\"oxlint/plugins-dev\").RuleTester.ValidTestCase &\n Partial<import(\"oxlint/plugins-dev\").RuleTester.InvalidTestCase>;\ntype TestCases = import(\"oxlint/plugins-dev\").RuleTester.TestCases;\ntype ConfigWithSettings = TesterConfig & {\n settings?: {\n typescriptOxlint?: TypescriptOxlintSettings;\n [key: string]: unknown;\n };\n};\n\nconst cleanupDirs = new Set<string>();\nlet cleanupInstalled = false;\n\nexport class RuleTester {\n /**\n * A thin Oxlint `RuleTester` wrapper that injects\n * `settings.typescriptOxlint`\n * settings, temporary fixtures, and a default project service.\n *\n * @example\n * ```ts\n * const tester = new RuleTester();\n * tester.run(\"demo\", rule, {\n * valid: [{ code: \"const answer = 42;\" }],\n * invalid: [],\n * });\n * ```\n */\n static get describe() {\n return OxlintRuleTester.describe;\n }\n\n static set describe(value) {\n OxlintRuleTester.describe = value;\n }\n\n static get it() {\n return OxlintRuleTester.it;\n }\n\n static set it(value) {\n OxlintRuleTester.it = value;\n }\n\n static only(item: string | TestCase): TestCase {\n return OxlintRuleTester.only(item);\n }\n\n readonly #inner: OxlintRuleTester;\n readonly #config?: TesterConfig;\n\n constructor(config?: TesterConfig) {\n this.#config = config;\n this.#inner = new OxlintRuleTester(config);\n }\n\n run(ruleName: string, rule: Record<string, unknown>, tests: TestCases): void {\n const workspace = mkdtempSync(join(tmpdir(), \"oxlint-plugin-typescript-go-\"));\n registerCleanup(workspace);\n const transformed = {\n valid: tests.valid.map((test) => prepareTestCase(workspace, test, this.#config)),\n invalid: tests.invalid.map((test) => prepareTestCase(workspace, test, this.#config)),\n };\n this.#inner.run(ruleName, decorateRule(rule as never) as never, transformed as TestCases);\n }\n}\n\nfunction prepareTestCase(\n workspace: string,\n test: string | TestCase,\n config: TesterConfig | undefined,\n): string | TestCase {\n if (typeof test === \"string\") {\n const filename = resolve(workspace, \"fixture.ts\");\n writeFixture(filename, test);\n return test;\n }\n const filename = resolve(workspace, test.filename ?? \"fixture.ts\");\n writeFixture(filename, test.code);\n const testerConfig = config as ConfigWithSettings | undefined;\n const baseSettings = testerConfig?.settings?.typescriptOxlint;\n const caseSettings = (\n test.settings as {\n typescriptOxlint?: TypescriptOxlintSettings;\n }\n )?.typescriptOxlint;\n const parserOptions = mergeTypeAwareParserOptions(\n mergeTypeAwareParserOptions(\n mergeTypeAwareParserOptions(\n mergeTypeAwareParserOptions(baseSettings, baseSettings?.parserOptions),\n mergeTypeAwareParserOptions(caseSettings, caseSettings?.parserOptions),\n ),\n {\n tsconfigRootDir: workspace,\n projectService: {\n allowDefaultProject: [\"*.ts\", \"*.tsx\", \"*.js\", \"*.jsx\"],\n },\n },\n ),\n mergeTypeAwareParserOptions(\n config?.languageOptions?.parserOptions as TypeAwareParserOptions | undefined,\n test.languageOptions?.parserOptions as TypeAwareParserOptions | undefined,\n ),\n );\n return {\n ...test,\n filename,\n settings: {\n ...testerConfig?.settings,\n ...test.settings,\n typescriptOxlint: {\n ...testerConfig?.settings?.typescriptOxlint,\n ...(test.settings as { typescriptOxlint?: TypescriptOxlintSettings })?.typescriptOxlint,\n parserOptions,\n },\n } as never,\n languageOptions: {\n ...config?.languageOptions,\n ...test.languageOptions,\n parserOptions: {\n ...parserOptions,\n } as never,\n },\n };\n}\n\nfunction writeFixture(filename: string, code: string): void {\n mkdirSync(dirname(filename), { recursive: true });\n writeFileSync(filename, code);\n const configPath = resolve(dirname(filename), \"tsconfig.json\");\n writeFileSync(\n configPath,\n JSON.stringify(\n {\n compilerOptions: {\n module: \"esnext\",\n target: \"es2022\",\n strict: true,\n },\n include: [\"**/*\"],\n },\n null,\n 2,\n ),\n );\n}\n\nfunction registerCleanup(workspace: string): void {\n cleanupDirs.add(workspace);\n if (cleanupInstalled) {\n return;\n }\n cleanupInstalled = true;\n process.on(\"exit\", () => {\n for (const dir of cleanupDirs) {\n rmSync(dir, { force: true, recursive: true });\n }\n });\n}\n"],"mappings":";;;;;;;AAqBA,MAAM,8BAAc,IAAI,KAAa;AACrC,IAAI,mBAAmB;AAEvB,IAAa,aAAb,MAAwB;;;;;;;;;;;;;;;CAetB,WAAW,WAAW;AACpB,SAAOA,aAAiB;;CAG1B,WAAW,SAAS,OAAO;AACzB,eAAiB,WAAW;;CAG9B,WAAW,KAAK;AACd,SAAOA,aAAiB;;CAG1B,WAAW,GAAG,OAAO;AACnB,eAAiB,KAAK;;CAGxB,OAAO,KAAK,MAAmC;AAC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;GACF;EACF;;AAGH,SAAS,aAAa,UAAkB,MAAoB;AAC1D,WAAU,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACjD,eAAc,UAAU,KAAK;AAE7B,eADmB,QAAQ,QAAQ,SAAS,EAAE,gBAAgB,EAG5D,KAAK,UACH;EACE,iBAAiB;GACf,QAAQ;GACR,QAAQ;GACR,QAAQ;GACT;EACD,SAAS,CAAC,OAAO;EAClB,EACD,MACA,EACD,CACF;;AAGH,SAAS,gBAAgB,WAAyB;AAChD,aAAY,IAAI,UAAU;AAC1B,KAAI,iBACF;AAEF,oBAAmB;AACnB,SAAQ,GAAG,cAAc;AACvB,OAAK,MAAM,OAAO,YAChB,QAAO,KAAK;GAAE,OAAO;GAAM,WAAW;GAAM,CAAC;GAE/C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/bindings/nodejs/typescript_oxlint/ts/rules/ast.d.ts
|
|
2
|
+
declare function stripChainExpression<Node>(node: Node): Node;
|
|
3
|
+
declare function memberPropertyName(node: unknown): string | undefined;
|
|
4
|
+
declare function memberObject(node: unknown): unknown;
|
|
5
|
+
declare function calleePropertyName(node: unknown): string | undefined;
|
|
6
|
+
declare function isIdentifierNamed(node: unknown, name: string): boolean;
|
|
7
|
+
declare function isNegativeOneLiteral(node: unknown): boolean;
|
|
8
|
+
declare function isZeroLiteral(node: unknown): boolean;
|
|
9
|
+
declare function isLiteralString(node: unknown): boolean;
|
|
10
|
+
declare function isRegExpLiteral(node: unknown): boolean;
|
|
11
|
+
declare function regexFlags(node: unknown): string | undefined;
|
|
12
|
+
declare function hasUnknownTypeAnnotation(node: unknown): boolean;
|
|
13
|
+
declare function nearestFunctionAncestors(node: any, sourceCode: any): any[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { calleePropertyName, hasUnknownTypeAnnotation, isIdentifierNamed, isLiteralString, isNegativeOneLiteral, isRegExpLiteral, isZeroLiteral, memberObject, memberPropertyName, nearestFunctionAncestors, regexFlags, stripChainExpression };
|
|
16
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/bindings/nodejs/typescript_oxlint/ts/rules/ast.ts
|
|
2
|
+
function stripChainExpression(node) {
|
|
3
|
+
let current = node;
|
|
4
|
+
while (current?.type === "ChainExpression") current = current.expression;
|
|
5
|
+
return current;
|
|
6
|
+
}
|
|
7
|
+
function memberPropertyName(node) {
|
|
8
|
+
const current = stripChainExpression(node);
|
|
9
|
+
if (!current || current.type !== "MemberExpression") return;
|
|
10
|
+
if (!current.computed && current.property?.type === "Identifier") return current.property.name;
|
|
11
|
+
if (current.computed && current.property?.type === "Literal") return String(current.property.value);
|
|
12
|
+
}
|
|
13
|
+
function memberObject(node) {
|
|
14
|
+
const current = stripChainExpression(node);
|
|
15
|
+
return current?.type === "MemberExpression" ? current.object : void 0;
|
|
16
|
+
}
|
|
17
|
+
function calleePropertyName(node) {
|
|
18
|
+
const current = stripChainExpression(node);
|
|
19
|
+
return current?.type === "CallExpression" ? memberPropertyName(current.callee) : void 0;
|
|
20
|
+
}
|
|
21
|
+
function isIdentifierNamed(node, name) {
|
|
22
|
+
const current = stripChainExpression(node);
|
|
23
|
+
return current?.type === "Identifier" && current.name === name;
|
|
24
|
+
}
|
|
25
|
+
function isNegativeOneLiteral(node) {
|
|
26
|
+
const current = stripChainExpression(node);
|
|
27
|
+
if (current?.type === "Literal" && current.value === -1) return true;
|
|
28
|
+
return current?.type === "UnaryExpression" && current.operator === "-" && current.argument?.type === "Literal" && current.argument.value === 1;
|
|
29
|
+
}
|
|
30
|
+
function isZeroLiteral(node) {
|
|
31
|
+
const current = stripChainExpression(node);
|
|
32
|
+
return current?.type === "Literal" && current.value === 0;
|
|
33
|
+
}
|
|
34
|
+
function isLiteralString(node) {
|
|
35
|
+
const current = stripChainExpression(node);
|
|
36
|
+
return current?.type === "Literal" && typeof current.value === "string";
|
|
37
|
+
}
|
|
38
|
+
function isRegExpLiteral(node) {
|
|
39
|
+
const current = stripChainExpression(node);
|
|
40
|
+
return current?.type === "Literal" && current.regex !== void 0;
|
|
41
|
+
}
|
|
42
|
+
function regexFlags(node) {
|
|
43
|
+
const current = stripChainExpression(node);
|
|
44
|
+
return isRegExpLiteral(current) ? current.regex.flags : void 0;
|
|
45
|
+
}
|
|
46
|
+
function hasUnknownTypeAnnotation(node) {
|
|
47
|
+
const current = node;
|
|
48
|
+
return current?.typeAnnotation?.typeAnnotation?.type === "TSUnknownKeyword" || current?.typeAnnotation?.type === "TSUnknownKeyword";
|
|
49
|
+
}
|
|
50
|
+
function nearestFunctionAncestors(node, sourceCode) {
|
|
51
|
+
return sourceCode.getAncestors(node).toReversed().filter((ancestor) => ancestor.type?.includes("Function"));
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { calleePropertyName, hasUnknownTypeAnnotation, isIdentifierNamed, isLiteralString, isNegativeOneLiteral, isRegExpLiteral, isZeroLiteral, memberObject, memberPropertyName, nearestFunctionAncestors, regexFlags, stripChainExpression };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","names":[],"sources":["../../ts/rules/ast.ts"],"sourcesContent":["export function stripChainExpression<Node>(node: Node): Node {\n let current = node as any;\n while (current?.type === \"ChainExpression\") {\n current = current.expression;\n }\n return current as Node;\n}\n\nexport function memberPropertyName(node: unknown): string | undefined {\n const current = stripChainExpression(node as any) as any;\n if (!current || current.type !== \"MemberExpression\") {\n return undefined;\n }\n if (!current.computed && current.property?.type === \"Identifier\") {\n return current.property.name;\n }\n if (current.computed && current.property?.type === \"Literal\") {\n return String(current.property.value);\n }\n return undefined;\n}\n\nexport function memberObject(node: unknown): unknown {\n const current = stripChainExpression(node as any) as any;\n return current?.type === \"MemberExpression\" ? current.object : undefined;\n}\n\nexport function calleePropertyName(node: unknown): string | undefined {\n const current = stripChainExpression(node as any) as any;\n return current?.type === \"CallExpression\" ? memberPropertyName(current.callee) : undefined;\n}\n\nexport function isIdentifierNamed(node: unknown, name: string): boolean {\n const current = stripChainExpression(node as any) as any;\n return current?.type === \"Identifier\" && current.name === name;\n}\n\nexport function isNegativeOneLiteral(node: unknown): boolean {\n const current = stripChainExpression(node as any) as any;\n if (current?.type === \"Literal\" && current.value === -1) {\n return true;\n }\n return (\n current?.type === \"UnaryExpression\" &&\n current.operator === \"-\" &&\n current.argument?.type === \"Literal\" &&\n current.argument.value === 1\n );\n}\n\nexport function isZeroLiteral(node: unknown): boolean {\n const current = stripChainExpression(node as any) as any;\n return current?.type === \"Literal\" && current.value === 0;\n}\n\nexport function isLiteralString(node: unknown): boolean {\n const current = stripChainExpression(node as any) as any;\n return current?.type === \"Literal\" && typeof current.value === \"string\";\n}\n\nexport function isRegExpLiteral(node: unknown): boolean {\n const current = stripChainExpression(node as any) as any;\n return current?.type === \"Literal\" && current.regex !== undefined;\n}\n\nexport function regexFlags(node: unknown): string | undefined {\n const current = stripChainExpression(node as any) as any;\n return isRegExpLiteral(current) ? current.regex.flags : undefined;\n}\n\nexport function hasUnknownTypeAnnotation(node: unknown): boolean {\n const current = node as any;\n return (\n current?.typeAnnotation?.typeAnnotation?.type === \"TSUnknownKeyword\" ||\n current?.typeAnnotation?.type === \"TSUnknownKeyword\"\n );\n}\n\nexport function nearestFunctionAncestors(node: any, sourceCode: any): any[] {\n return sourceCode\n .getAncestors(node)\n .toReversed()\n .filter((ancestor: any) => ancestor.type?.includes(\"Function\"));\n}\n"],"mappings":";AAAA,SAAgB,qBAA2B,MAAkB;CAC3D,IAAI,UAAU;AACd,QAAO,SAAS,SAAS,kBACvB,WAAU,QAAQ;AAEpB,QAAO;;AAGT,SAAgB,mBAAmB,MAAmC;CACpE,MAAM,UAAU,qBAAqB,KAAY;AACjD,KAAI,CAAC,WAAW,QAAQ,SAAS,mBAC/B;AAEF,KAAI,CAAC,QAAQ,YAAY,QAAQ,UAAU,SAAS,aAClD,QAAO,QAAQ,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;;AAItC,SAAgB,yBAAyB,MAAW,YAAwB;AAC1E,QAAO,WACJ,aAAa,KAAK,CAClB,YAAY,CACZ,QAAQ,aAAkB,SAAS,MAAM,SAAS,WAAW,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/bindings/nodejs/typescript_oxlint/ts/rules/await_thenable.d.ts
|
|
2
|
+
declare const awaitThenableRule: {
|
|
3
|
+
defaultOptions: never[];
|
|
4
|
+
meta: {
|
|
5
|
+
docs: {
|
|
6
|
+
requiresTypeChecking: boolean;
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
type: "problem";
|
|
10
|
+
schema: never[];
|
|
11
|
+
};
|
|
12
|
+
create: (context: any) => Record<string, (node: any) => void>;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { awaitThenableRule };
|
|
16
|
+
//# sourceMappingURL=await_thenable.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isIdentifierNamed, memberObject, memberPropertyName, stripChainExpression } from "./ast.js";
|
|
2
|
+
import { createNativeRule } from "./rule_creator.js";
|
|
3
|
+
import { isPromiseLikeNode } from "./type_utils.js";
|
|
4
|
+
//#region src/bindings/nodejs/typescript_oxlint/ts/rules/await_thenable.ts
|
|
5
|
+
const awaitThenableRule = createNativeRule("await-thenable", {
|
|
6
|
+
docs: { description: "Disallow awaiting non-thenable values." },
|
|
7
|
+
messages: { unexpected: "Unexpected await of a non-thenable value." }
|
|
8
|
+
}, (context) => ({ AwaitExpression(node) {
|
|
9
|
+
if (!isPromiseLikeNode(context, node.argument) && !isObviouslyPromiseLike(node.argument)) context.report({
|
|
10
|
+
node,
|
|
11
|
+
messageId: "unexpected"
|
|
12
|
+
});
|
|
13
|
+
} }));
|
|
14
|
+
function isObviouslyPromiseLike(node) {
|
|
15
|
+
const current = stripChainExpression(node);
|
|
16
|
+
if (current?.type === "NewExpression" && isIdentifierNamed(current.callee, "Promise")) return true;
|
|
17
|
+
if (current?.type !== "CallExpression") return false;
|
|
18
|
+
return memberPropertyName(current.callee) === "resolve" && isIdentifierNamed(memberObject(current.callee), "Promise");
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { awaitThenableRule };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=await_thenable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"await_thenable.js","names":[],"sources":["../../ts/rules/await_thenable.ts"],"sourcesContent":["import { isIdentifierNamed, memberObject, memberPropertyName, stripChainExpression } from \"./ast\";\nimport { createNativeRule } from \"./rule_creator\";\nimport { isPromiseLikeNode } from \"./type_utils\";\n\nexport const awaitThenableRule = createNativeRule(\n \"await-thenable\",\n {\n docs: {\n description: \"Disallow awaiting non-thenable values.\",\n },\n messages: {\n unexpected: \"Unexpected await of a non-thenable value.\",\n },\n },\n (context) => ({\n AwaitExpression(node: any) {\n if (!isPromiseLikeNode(context, node.argument) && !isObviouslyPromiseLike(node.argument)) {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n }),\n);\n\nfunction isObviouslyPromiseLike(node: any): boolean {\n const current = stripChainExpression(node);\n if (current?.type === \"NewExpression\" && isIdentifierNamed(current.callee, \"Promise\")) {\n return true;\n }\n if (current?.type !== \"CallExpression\") {\n return false;\n }\n return (\n memberPropertyName(current.callee) === \"resolve\" &&\n isIdentifierNamed(memberObject(current.callee), \"Promise\")\n );\n}\n"],"mappings":";;;;AAIA,MAAa,oBAAoB,iBAC/B,kBACA;CACE,MAAM,EACJ,aAAa,0CACd;CACD,UAAU,EACR,YAAY,6CACb;CACF,GACA,aAAa,EACZ,gBAAgB,MAAW;AACzB,KAAI,CAAC,kBAAkB,SAAS,KAAK,SAAS,IAAI,CAAC,uBAAuB,KAAK,SAAS,CACtF,SAAQ,OAAO;EAAE;EAAM,WAAW;EAAc,CAAC;GAGtD,EACF;AAED,SAAS,uBAAuB,MAAoB;CAClD,MAAM,UAAU,qBAAqB,KAAK;AAC1C,KAAI,SAAS,SAAS,mBAAmB,kBAAkB,QAAQ,QAAQ,UAAU,CACnF,QAAO;AAET,KAAI,SAAS,SAAS,iBACpB,QAAO;AAET,QACE,mBAAmB,QAAQ,OAAO,KAAK,aACvC,kBAAkB,aAAa,QAAQ,OAAO,EAAE,UAAU"}
|