mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { readFile, stat } from "node:fs/promises";
|
|
import { resolve } from "node:path";
|
|
import { RuleTester } from "oxlint/plugins-dev";
|
|
import rule from "../../scripts/lint/rules/typed-resource-refusal.mjs";
|
|
|
|
RuleTester.describe = describe;
|
|
RuleTester.it = it;
|
|
|
|
const construct = (options: string) =>
|
|
`new AnalysisResourceConstraintError("op", "memory", "reason", null${options});`;
|
|
|
|
new RuleTester({ languageOptions: { parserOptions: { lang: "ts" } } }).run(
|
|
"typed-resource-refusal",
|
|
rule,
|
|
{
|
|
valid: [
|
|
{
|
|
code: construct(""),
|
|
filename: resolve("src/model/ModelArtifactProvider.ts"),
|
|
},
|
|
construct(', fixedAllowanceOptions("The allowance", "count")'),
|
|
construct(
|
|
', { cause, ...fixedAllowanceOptions("The allowance", "count") }',
|
|
),
|
|
construct(", { limit: analysisSettingLimit(setting, value, source) }"),
|
|
construct(', { remediationAction: "Raise the setting." }'),
|
|
construct(", { retryable: true, measuredExhaustion: true }"),
|
|
construct(", recovery"),
|
|
'new AnalysisInputError("op", { cause });',
|
|
],
|
|
invalid: [
|
|
{
|
|
code: construct("") + construct(""),
|
|
filename: resolve("src/model/ModelArtifactProvider.ts"),
|
|
errors: [{ messageId: "untyped" }, { messageId: "untyped" }],
|
|
},
|
|
{
|
|
code: "const value = 1;",
|
|
filename: resolve("src/model/ModelArtifactProvider.ts"),
|
|
errors: [{ messageId: "stale", data: { allowed: "1", actual: "0" } }],
|
|
},
|
|
{ code: construct(""), errors: [{ messageId: "untyped" }] },
|
|
{ code: construct(", { cause }"), errors: [{ messageId: "untyped" }] },
|
|
{
|
|
code: construct(", { retryable: false, diagnostics: {} }"),
|
|
errors: [{ messageId: "untyped" }],
|
|
},
|
|
],
|
|
},
|
|
);
|
|
|
|
it("keeps the untyped-refusal baseline to existing source files", async () => {
|
|
const baseline = JSON.parse(
|
|
await readFile(
|
|
"scripts/lint/rules/typed-resource-refusal-baseline.json",
|
|
"utf8",
|
|
),
|
|
) as Record<string, number>;
|
|
for (const [file, count] of Object.entries(baseline)) {
|
|
expect(file).toMatch(/^src\/.+\.ts$/u);
|
|
expect(count).toBeGreaterThan(0);
|
|
// The rule checks counts in files lint visits. A removed file gets no visit.
|
|
expect((await stat(file)).isFile(), file).toBe(true);
|
|
}
|
|
});
|