Skip to content

Commit ccdaa2c

Browse files
feat: add validator run event to allow plugins to perform custom validation
1 parent c565bc6 commit ccdaa2c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/lib/application-events.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const ApplicationEvents = {
22
BOOTSTRAP_END: "bootstrapEnd",
3-
};
3+
VALIDATION_RUN: "validationRun",
4+
} as const;

src/lib/application.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ export class Application extends ChildableComponent<
107107
*/
108108
static readonly EVENT_BOOTSTRAP_END = ApplicationEvents.BOOTSTRAP_END;
109109

110+
/**
111+
* Emitted when validation is being run.
112+
* The listener will be given an instance of {@link ProjectReflection}.
113+
*/
114+
static readonly EVENT_VALIDATION_RUN = ApplicationEvents.VALIDATION_RUN;
115+
110116
/**
111117
* Create a new TypeDoc application instance.
112118
*/
@@ -431,6 +437,8 @@ export class Application extends ChildableComponent<
431437
validateLinks(project, this.logger);
432438
}
433439

440+
this.trigger(Application.EVENT_VALIDATION_RUN, project);
441+
434442
this.logger.verbose(`Validation took ${Date.now() - start}ms`);
435443
}
436444

src/lib/utils/events.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// The Events object is a typesafe conversion of Backbones Events object:
88
// https://github.com/jashkenas/backbone/blob/05fde9e201f7e2137796663081105cd6dad12a98/backbone.js#L119-L374
99

10+
import type { ProjectReflection } from "../models/index";
11+
import type { Application } from "../application";
12+
1013
const uniqueId = (function () {
1114
const prefixes: Record<string, number | undefined> = Object.create(null);
1215
return function (prefix: string) {
@@ -433,6 +436,12 @@ export class EventDispatcher {
433436
context?: any,
434437
priority?: number
435438
): this;
439+
on(
440+
name: (typeof Application)["EVENT_VALIDATION_RUN"],
441+
callback: (project: ProjectReflection) => void,
442+
context?: any,
443+
priority?: number
444+
): this;
436445
on(
437446
name: string,
438447
callback: EventCallback,
@@ -441,7 +450,7 @@ export class EventDispatcher {
441450
): this;
442451
on(
443452
nameOrMap: EventMap | string,
444-
callback: EventCallback,
453+
callback?: EventCallback,
445454
context?: any,
446455
priority?: number
447456
) {

0 commit comments

Comments
 (0)