apartFromItsCycle

tcmts.cli.lint.apartFromItsCycle · #5mpz3v3k · term · runs anywhere

Findings that come from linting a definition apart from the ones stored with it. Definitions that refer to each other are one module where they run, but each is linted as tcm view shows it, the others imported: assigning to one (a let they share) isn't assigning to an import, and an import only assigned to isn't unused.

export function apartFromItsCycle(
  issue: { rule: string; message: string; start: number },
  text: string,
  mates: Set<string>,
): boolean {
  if (!mates.size) return false;
  const name = /^[\w$]+/.exec(text.slice(issue.start))?.[0];
  if (!name || !mates.has(name)) return false;
  return (
    /no-import-assign/.test(issue.rule) ||
    (/no-unused-vars/.test(issue.rule) && /imported but never used/.test(issue.message))
  );
}

used by