콘텐츠로 이동

classifyImpact

지정한 파일의 변경으로 영향받는 파일을, 직접 참조 (1 홉)와 간접 참조 (2 홉 이상)로 분류해서 반환합니다. 직접 참조에는 참조 횟수도 부여됩니다.

getImpactSet은 평탄한 목록을 반환하기 때문에, “직접 다시 봐야 하는 파일” 과 “혹시 모르니 확인해야 할 파일” 을 구별할 수 없습니다. classifyImpact는 영향을 2단계로 나누고, 간접 참조에는 경유한 직접 파일(via)도 부여하기 때문에, 리뷰 우선순위나 경로의 가시화에 사용할 수 있습니다.

MCP의 impact-analysis 도구는 이 함수의 결과를 그대로 정렬해서 반환하고 있습니다.

function classifyImpact(
graph: ContextGraph,
filePath: string,
): {
directlyAffected: { file: string; references: number }[];
transitivelyAffected: { file: string; via: string }[];
};
파라미터타입필수설명
graphContextGraphbuildContextGraph로 구축한 그래프
filePathstring영향 범위를 조사하고자 하는 파일의 경로

객체를 반환합니다.

  • directlyAffectedfilePath를 직접 참조하고 있는 파일. references는 동일 소스 내의 참조 횟수 (동일한 파일을 여러 곳에서 링크하고 있는 경우의 합계). 파일 경로 순서로 정렬
  • transitivelyAffected — 직접은 아니지만, 간접적으로 도달하는 파일. via는 경로 상에서 가장 가까운 “직접 영향을 받은 파일”. 파일 경로 순서로 정렬
import { buildContextGraph, classifyImpact, loadDocuments } from "@contextlint/core";
const documents = loadDocuments(["docs/**/*.md"]);
const graph = buildContextGraph(documents);
const impact = classifyImpact(graph, "docs/architecture.md");
console.log(`직접 영향: ${impact.directlyAffected.length}`);
for (const item of impact.directlyAffected) {
console.log(` - ${item.file} (${item.references} 참조)`);
}
console.log(`간접 영향: ${impact.transitivelyAffected.length}`);
for (const item of impact.transitivelyAffected) {
console.log(` - ${item.file} (경유: ${item.via})`);
}