Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(icheck-ts): improve circular import reporting #136

Open
hi-ogawa opened this issue Sep 13, 2023 · 0 comments
Open

feat(icheck-ts): improve circular import reporting #136

hi-ogawa opened this issue Sep 13, 2023 · 0 comments

Comments

@hi-ogawa
Copy link
Owner

Current, cyclic deps reporting includes many duplicate "import edge".
Also, the printed order is pretty random, some sort of sensible sorting is wished.
I worried that checking all edges in all cycles might be too expensive (probably O(n^2)), but maybe still worth it.

// group/sort by initial cyclic edge
const edgeWithKeys = circularResult.backEdges.map((e) => ({
edge: e,
key: JSON.stringify([e[0], e[1].source.name]),
}));
const groups = groupBy(
sortBy(edgeWithKeys, (e) => e.key),
(e) => e.key
);
const uniqEdges = [...groups.values()].map((group) => group[0].edge);
for (const edge of uniqEdges) {
const formatted = formatCircularImportError(
edge,
circularResult.parentMap
);
formatted.lines.forEach((line, i) => {
const prefix = i > 0 ? " ".repeat(i - 1) + " -> " : "";
console.log(prefix + line);
});
}
process.exitCode = 1;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant