Skip to content

getImpactSet

Returns the files that reference a given file, covering both direct and transitive references. Internally it walks the graph’s reverse edges with BFS, and the target file itself is excluded from the result.

Before changing or deleting a document, you often want to know which other documents will be affected. getImpactSet answers “if I change this file, which places do I need to review?” with a flat list.

If you need to distinguish direct from transitive references, use classifyImpact instead.

function getImpactSet(
graph: ContextGraph,
filePath: string,
): string[];
ParameterTypeRequiredDescription
graphContextGraphThe graph built by buildContextGraph.
filePathstringThe path of the file whose impact set you want to compute. It must match a key in graph.nodes.

Returns string[]. The array contains every file path that references filePath directly or transitively, sorted alphabetically. filePath itself is not included. If the file does not appear in the graph or is not referenced by anyone, an empty array is returned.

import { buildContextGraph, getImpactSet, loadDocuments } from "@contextlint/core";
const documents = loadDocuments(["docs/**/*.md"]);
const graph = buildContextGraph(documents);
const affected = getImpactSet(graph, "docs/architecture.md");
if (affected.length === 0) {
console.log("No files are affected");
} else {
console.log(`${affected.length} files are affected:`);
for (const file of affected) {
console.log(` - ${file}`);
}
}