mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-23 02:45:38 -06:00
chore: enforce type evidence lint rules
This commit is contained in:
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
type OxlintConfig = {
|
||||
ignorePatterns?: string[];
|
||||
jsPlugins?: string[];
|
||||
overrides?: Array<{
|
||||
excludeFiles?: string[];
|
||||
files?: string[];
|
||||
@@ -147,6 +148,7 @@ describe("oxlint config", () => {
|
||||
"docs/_layouts/",
|
||||
".agents/skills/autoreview/tests/fixtures/**",
|
||||
"test/fixtures/oxlint-boundary-guards/**",
|
||||
"test/fixtures/oxlint-type-evidence/**",
|
||||
"**/a2ui.bundle.js",
|
||||
"extensions/diffs/assets/viewer-runtime.js",
|
||||
"extensions/diffs-language-pack/assets/viewer-runtime.js",
|
||||
@@ -291,6 +293,18 @@ describe("oxlint config", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("enables the repository type-evidence plugin", () => {
|
||||
const config = readJson(".oxlintrc.json") as OxlintConfig;
|
||||
|
||||
expect(config.jsPlugins).toContain("./scripts/oxlint-type-evidence.mjs");
|
||||
expect(config.rules?.["openclaw-type-evidence/no-unknown-type-aliases"]).toBe("error");
|
||||
expect(config.rules?.["openclaw-type-evidence/no-widen-then-assert"]).toBe("error");
|
||||
expect(config.overrides).toContainEqual({
|
||||
files: ["**/*.d.ts"],
|
||||
rules: { "openclaw-type-evidence/no-unknown-type-aliases": "off" },
|
||||
});
|
||||
});
|
||||
|
||||
it("enables clean zero-baseline lint rules", () => {
|
||||
const config = readJson(".oxlintrc.json") as OxlintConfig;
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const FIXTURES = "test/fixtures/oxlint-type-evidence";
|
||||
const cases = [
|
||||
{
|
||||
rule: "openclaw-type-evidence/no-unknown-type-aliases",
|
||||
violation: `${FIXTURES}/no-unknown-type-aliases-violation.ts`,
|
||||
violations: 3,
|
||||
},
|
||||
{
|
||||
rule: "openclaw-type-evidence/no-widen-then-assert",
|
||||
violation: `${FIXTURES}/no-widen-then-assert-violation.ts`,
|
||||
violations: 2,
|
||||
},
|
||||
];
|
||||
|
||||
function runRule(target: string) {
|
||||
return spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
"scripts/run-oxlint.mjs",
|
||||
"--openclaw-focused-config",
|
||||
"--config",
|
||||
"config/oxlint/type-evidence.json",
|
||||
target,
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
}
|
||||
|
||||
describe("oxlint type-evidence rules", () => {
|
||||
it.each(cases)("reports the intended $rule flows", (testCase) => {
|
||||
const violation = runRule(testCase.violation);
|
||||
const output = `${violation.stdout}${violation.stderr}`;
|
||||
expect(violation.status).toBe(1);
|
||||
expect(output.split(`${testCase.rule.replace("/", "(")})`)).toHaveLength(
|
||||
testCase.violations + 1,
|
||||
);
|
||||
});
|
||||
|
||||
it("allows explicit unknown boundaries and preserved type evidence", () => {
|
||||
const result = runRule(`${FIXTURES}/valid.ts`);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
expect(`${result.stdout}${result.stderr}`).not.toContain("openclaw-type-evidence");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user