Skip to content

Commit

Permalink
feat: generate names that make more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Oct 25, 2023
1 parent a82f19a commit dc9b7df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
22 changes: 21 additions & 1 deletion dist/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion src/tasks/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,27 @@ function buildFilesSection(files: string[]): string {
return header + "\n\n" + body;
}

function buildSectionName(name: string): string {
switch (name) {
case "dependencies":
case "devDependencies":
case "optionalPeerDependencies":
case "exports":
case "types":
return `Unused ${name}`;
case "unresolved":
return "Unresolved imports";
case "binaries":
return "Unlisted binaries";
case "unlisted":
return "Unlisted dependencies";
case "duplicates":
return "Duplicates";
default:
throw new Error(`Unknown name: ${name}`);
}
}

/**
* Build a section where the result is a collection of strings
*/
Expand All @@ -188,7 +209,7 @@ function buildArraySection(name: string, rawResults: Record<string, string[]>):
totalUnused += results.length;
tableBody.push([fileName, results.map((result) => `\`${result}\``).join("<br/>")]);
}
const sectionHeader = `### Unused ${name.toLocaleLowerCase()} (${totalUnused})`;
const sectionHeader = `### ${buildSectionName(name)}} (${totalUnused})`;

return processSectionToMessage(sectionHeader, tableHeader, tableBody);
}
Expand Down

0 comments on commit dc9b7df

Please sign in to comment.