testCycleMatesArentImportsToLint
tcmts.cli.lint.testCycleMatesArentImportsToLint · #mdhtm3oi · term
import { apartFromItsCycle } from "#codebase/tcmts/cli/lint";
export const testCycleMatesArentImportsToLint = () => {
const text =
'import { counter } from "#codebase/lib";\nexport function bump() { counter = 1; }\n';
const mates = new Set(["counter"]);
const at = (s: string) => text.indexOf(s);
const assign = {
rule: "eslint(no-import-assign)",
message: "Do not assign to imported bindings",
start: at("counter = 1"),
};
const unused = {
rule: "eslint(no-unused-vars)",
message: "Identifier 'counter' is imported but never used.",
start: at("counter }"),
};
const other = {
rule: "eslint(no-unused-vars)",
message: "Variable 'x' is declared but never used.",
start: at("bump"),
};
if (!apartFromItsCycle(assign, text, mates) || !apartFromItsCycle(unused, text, mates))
throw new Error("a cycle-mate's findings are kept");
if (apartFromItsCycle(other, text, mates)) throw new Error("another finding is dropped");
if (apartFromItsCycle(assign, text, new Set())) throw new Error("dropped with no cycle");
}
uses