mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 22:11:12 +00:00
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { createRuleTester } from "../support/createRuleTester.js";
|
|
import rule from "../../scripts/lint/rules/no-babel-visitor-keys.mjs";
|
|
import { lintRepositoryProject } from "../fixtures/oxlintConfiguration.js";
|
|
|
|
createRuleTester().run("no-babel-visitor-keys", rule, {
|
|
valid: [
|
|
'const text = "VISITOR_KEYS";',
|
|
"const config = { VISITOR_KEYS: 1 }; config.VISITOR_KEYS;",
|
|
'import * as types from "@babel/types"; types.isIdentifier(node);',
|
|
'import { VISITOR_KEYS } from "unrelated";',
|
|
'import * as types from "@babel/types"; function f(types: { VISITOR_KEYS: number }) { return types.VISITOR_KEYS; }',
|
|
],
|
|
invalid: [
|
|
{
|
|
code: 'import { VISITOR_KEYS as keys } from "@babel/types";',
|
|
errors: [{ messageId: "owner" }],
|
|
},
|
|
{
|
|
code: 'export { VISITOR_KEYS as keys } from "@babel/types";',
|
|
errors: [{ messageId: "owner" }],
|
|
},
|
|
{
|
|
code: 'import * as t from "@babel/types"; t.VISITOR_KEYS;',
|
|
errors: [{ messageId: "owner" }],
|
|
},
|
|
{
|
|
code: 'import * as t from "@babel/types"; t["VISITOR_KEYS"];',
|
|
errors: [{ messageId: "owner" }],
|
|
},
|
|
{
|
|
code: 'import * as t from "@babel/types"; const { VISITOR_KEYS: keys } = t;',
|
|
errors: [{ messageId: "owner" }],
|
|
},
|
|
],
|
|
});
|
|
|
|
it("limits the shared Babel child expansion exception to its owner", async () => {
|
|
const source =
|
|
'import * as t from "@babel/types"; export const keys = t.VISITOR_KEYS;\n';
|
|
const result = await lintRepositoryProject("rea-visitor-lint-", [
|
|
["src/domain/javascript/javascriptSemanticTraversal.ts", source],
|
|
["src/domain/javascript/other.ts", source],
|
|
["src/domain/javascript/other.spec.ts", source],
|
|
]);
|
|
expect(result.status, result.stderr).toBe(1);
|
|
const report = JSON.parse(result.stdout) as {
|
|
diagnostics: Array<{ filename: string; code: string }>;
|
|
};
|
|
expect(
|
|
report.diagnostics
|
|
.filter(({ code }) => code.includes("no-babel-visitor-keys"))
|
|
.map(({ filename }) => filename.replaceAll("\\", "/")),
|
|
).toEqual(["src/domain/javascript/other.ts"]);
|
|
});
|