Skip to content

Commit

Permalink
fix: emit markdown if both verbose mode and annotations are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Dec 6, 2023
1 parent 51548de commit 71d84d0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
7 changes: 4 additions & 3 deletions dist/index.mjs

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

30 changes: 30 additions & 0 deletions src/tasks/__snapshots__/knip.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ exports[`knip > buildMapSection > should transform a classMembers map section to
}
`;
exports[`knip > buildMapSection > should transform a classMembers map section to markdown if verbose and annotations are disabled 1`] = `
{
"annotations": [],
"sections": [
"### Unused Class Members (7)
|Filename|Class|Member|
|-|-|-|
|Qwark.ts|InsaneQwark|\`destroy\`|
|Qwark.ts|SaneQwark|\`rescue\`|
|Rivet.ts|Rivet|\`fly\`<br/>\`swim\`<br/>\`explode\`<br/>\`mutate\`<br/>\`refineGelatonium \`|",
],
}
`;
exports[`knip > buildMapSection > should transform a enumMembers map section and annotations 1`] = `
{
"annotations": [
Expand Down Expand Up @@ -448,6 +463,21 @@ exports[`knip > buildMapSection > should transform a enumMembers map section to
}
`;
exports[`knip > buildMapSection > should transform a enumMembers map section to markdown if verbose and annotations are disabled 1`] = `
{
"annotations": [],
"sections": [
"### Unused Enum Members (12)
|Filename|Enum|Member|
|-|-|-|
|DrNefarious.ts|Homeworld|\`Magmos\`<br/>\`Aquatos\`<br/>\`Leviathan \`<br/>\`TombliOutpost\`<br/>\`Zanifar \`<br/>\`NefariousSpaceStation \`<br/>\`NefariousCity\`<br/>\`CorsonV\`|
|Sigmund.ts|Membership|\`ZordoomPrison\`<br/>\`GreatClockStaff\`|
|Sigmund.ts|Residence|\`Viceron\`<br/>\`GreatClock\`|",
],
}
`;
exports[`knip > buildMarkdownSections > outputs only sections with defaults 1`] = `
[
"### Unused files (3)
Expand Down
10 changes: 10 additions & 0 deletions src/tasks/knip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ describe("knip", () => {
expect(section).toMatchSnapshot();
});

it("should transform a enumMembers map section to markdown if verbose and annotations are disabled", () => {
const section = buildMapSection("enumMembers", enumMembers, false, false);
expect(section).toMatchSnapshot();
});

it("should transform a enumMembers map section and annotations", () => {
const section = buildMapSection("enumMembers", enumMembers, true, false);
expect(section).toMatchSnapshot();
Expand All @@ -533,6 +538,11 @@ describe("knip", () => {
expect(section).toMatchSnapshot();
});

it("should transform a classMembers map section to markdown if verbose and annotations are disabled", () => {
const section = buildMapSection("classMembers", classMembers, false, false);
expect(section).toMatchSnapshot();
});

it("should transform a classMembers map section and annotations", () => {
const section = buildMapSection("classMembers", classMembers, true, false);
expect(section).toMatchSnapshot();
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export function buildMapSection(
const annotations: ItemMeta[] = [];
const resultType = name === "classMembers" ? "Class" : "Enum";
const resultMetaType = name === "classMembers" ? "class" : "enum";
const shouldBuildMarkdown = verboseEnabled || !annotationsEnabled;

for (const [filename, results] of Object.entries(rawResults)) {
for (const [definitionName, members] of Object.entries(results)) {
Expand All @@ -265,18 +266,18 @@ export function buildMapSection(
type: resultMetaType,
});
}
if (verboseEnabled) {
if (shouldBuildMarkdown) {
itemNames.push(`\`${member.name}\``);
}
}
totalUnused += members.length;
if (verboseEnabled) {
if (shouldBuildMarkdown) {
tableBody.push([filename, definitionName, itemNames.join("<br/>")]);
}
}
}

if (verboseEnabled) {
if (shouldBuildMarkdown) {
const tableHeader = ["Filename", resultType, "Member"];
const sectionHeaderName = `${resultType} Members`;
const sectionHeader = `### Unused ${sectionHeaderName} (${totalUnused})`;
Expand Down

0 comments on commit 71d84d0

Please sign in to comment.