Skip to content

Instantly share code, notes, and snippets.

@orjan
Created May 10, 2023 13:06

Revisions

  1. orjan created this gist May 10, 2023.
    50 changes: 50 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    import file from "./result.json" assert { type: "json" };

    const entries = file.entries.map(entry => {
    //const children = Array.from(extractChildren(entry.children));
    const children = entry.children.map(child => child.name);
    return {
    name: entry.name,
    children: children,
    errors: evaluateErrors(entry.name, children)
    };
    });

    function evaluateErrors(name, children) {
    const errors = [];

    const module = /src\/modules\/([a-z\-]+)/.exec(name)?.[1] ?? null;
    let child;
    for (child of children) {
    if (module && child.startsWith("/src/modules/") && child.endsWith(".vue") && !child.startsWith("/src/modules/"+module+"/")) {
    errors.push(child);
    }

    }

    return errors;
    }

    function extractChildren(children) {
    const stack = [...children];
    const result = new Set();

    let current;
    while (current = stack.pop()) {
    stack.push(...current.children);
    result.add(current.name);
    }

    return result;
    }

    const errorComponents = entries.filter(entry => entry.errors.length > 0);

    for (let error of errorComponents) {
    console.log(error.name);
    for (let e of error.errors) {
    console.log(" - ", e);
    }

    console.log();
    }