Skip to content

Commit 9819646

Browse files
committed
Bring back excludeCategories
1 parent eefb5ba commit 9819646

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ title: Changelog
1616
- Changed the default `sort` order to use `alphabetical-ignoring-documents`
1717
instead of `alphabetical`.
1818
- Changed default of `suppressCommentWarningsInDeclarationFiles` to `true`
19-
- Removed `excludeCategories` option which has existed for over a year, but
20-
GitHub indicates has only ever been used by one project and breaks with
21-
changes to make categories work with packages mode.
2219
- API: Constructor signatures now use the parent class name as their name
2320
(e.g. `X`, not `new X`)
2421
- API: `@group`, `@category`, `@groupDescription` and `@categoryDescription`

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ConverterComponent } from "../components.js";
2626
import type { Context } from "../context.js";
2727
import { ConverterEvents } from "../converter-events.js";
2828
import type { Converter } from "../converter.js";
29+
import { CategoryPlugin } from "./CategoryPlugin.js";
2930

3031
/**
3132
* These tags are not useful to display in the generated documentation.
@@ -137,6 +138,9 @@ export class CommentPlugin extends ConverterComponent {
137138
@Option("excludeNotDocumented")
138139
accessor excludeNotDocumented!: boolean;
139140

141+
@Option("excludeCategories")
142+
accessor excludeCategories!: string[];
143+
140144
@Option("defaultCategory")
141145
accessor defaultCategory!: string;
142146

@@ -566,6 +570,10 @@ export class CommentPlugin extends ConverterComponent {
566570
return true;
567571
}
568572

573+
if (this.excludedByCategory(reflection)) {
574+
return true;
575+
}
576+
569577
if (
570578
reflection.kindOf(
571579
ReflectionKind.ConstructorSignature |
@@ -649,6 +657,22 @@ export class CommentPlugin extends ConverterComponent {
649657
return isHidden;
650658
}
651659

660+
private excludedByCategory(reflection: Reflection): boolean {
661+
const excludeCategories = this.excludeCategories;
662+
let target: DeclarationReflection | undefined;
663+
if (reflection instanceof DeclarationReflection) {
664+
target = reflection;
665+
} else if (reflection instanceof SignatureReflection) {
666+
target = reflection.parent;
667+
}
668+
if (!target || !excludeCategories.length) return false;
669+
const categories = CategoryPlugin.getCategories(target);
670+
if (categories.size === 0) {
671+
categories.add(this.defaultCategory);
672+
}
673+
return excludeCategories.some((cat) => categories.has(cat));
674+
}
675+
652676
private validateParamTags(
653677
signature: SignatureReflection,
654678
comment: Comment,

src/lib/utils/options/declaration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface TypeDocOptionMap {
121121
excludePrivate: boolean;
122122
excludeProtected: boolean;
123123
excludeReferences: boolean;
124+
excludeCategories: string[];
124125
maxTypeConversionDepth: number;
125126
name: string;
126127
includeVersion: boolean;

src/lib/utils/options/sources/typedoc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
192192
help: (i18n) => i18n.help_excludeInternal(),
193193
type: ParameterType.Boolean,
194194
});
195+
options.addDeclaration({
196+
name: "excludeCategories",
197+
help: (i18n) => i18n.help_excludeCategories(),
198+
type: ParameterType.Array,
199+
defaultValue: [],
200+
});
195201
options.addDeclaration({
196202
name: "excludePrivate",
197203
help: (i18n) => i18n.help_excludePrivate(),

src/test/behavior.c2.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ describe("Behavior Tests", () => {
436436
logger.expectNoOtherMessages();
437437
});
438438

439+
it("Handles excludeCategories", () => {
440+
app.options.setValue("excludeCategories", ["A", "Default"]);
441+
app.options.setValue("defaultCategory", "Default");
442+
const project = convert("excludeCategories");
443+
equal(
444+
project.children?.map((c) => c.name),
445+
["c"],
446+
);
447+
});
448+
439449
it("Handles excludeNotDocumentedKinds", () => {
440450
app.options.setValue("excludeNotDocumented", true);
441451
app.options.setValue("excludeNotDocumentedKinds", ["Property"]);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @category A
3+
*/
4+
export const a = 1;
5+
/**
6+
* @category A
7+
* @category B
8+
*/
9+
export const b = 1;
10+
/**
11+
* @category C
12+
*/
13+
export const c = 1;
14+
export const d = 1;

0 commit comments

Comments
 (0)