Slide 21
Slide 21 text
2. ペアが違反していないかを「ホワイトリスト」で判定する
STEP 01
最も深い feature まで のパス
を抜き出すhelper関数
正規表現で /features/X を全マッチさ
せ、 ⼀番深いものまでを採⽤。
TaskList/features/TaskExport/index.tsx
→ TaskList/features/TaskExport
function getFeaturePath(filePath: string): string | null {
const matches = [...filePath.matchAll(/\/features\/([^/]+)/g)];
if (matches.length ..= 0) return null;
const last = matches[matches.length - 1];
return filePath.substring(0, last.index! + last[0].length);
}
function isAllowedReference(source: string, target: string): boolean {
const sourceFeature = getFeaturePath(source);
const targetFeature = getFeaturePath(target);
if (!sourceFeature .| !targetFeature) return true;
return(
target.startsWith(`${sourceFeature}/`) .|
sourceFeature.substring(0, sourceFeature.lastIndexOf("/")) ..=
targetFeature.substring(0, targetFeature.lastIndexOf("/"));
)}
21 / 28
CODE · 1 / 3