Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add validator run event to allow plugins to perform custom validation #2184

Merged
merged 2 commits into from Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/application-events.ts
@@ -1,3 +1,4 @@
export const ApplicationEvents = {
BOOTSTRAP_END: "bootstrapEnd",
};
VALIDATION_RUN: "validationRun",
} as const;
8 changes: 8 additions & 0 deletions src/lib/application.ts
Expand Up @@ -107,6 +107,12 @@ export class Application extends ChildableComponent<
*/
static readonly EVENT_BOOTSTRAP_END = ApplicationEvents.BOOTSTRAP_END;

/**
* Emitted when validation is being run.
* The listener will be given an instance of {@link ProjectReflection}.
*/
static readonly EVENT_VALIDATION_RUN = ApplicationEvents.VALIDATION_RUN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think validateProject might be better - it immediately implies that the callback will be passed a project, thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ApplicationEvents.VALIDATE_PROJECT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, and validateProject for the string, otherwise lgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's all set up :)


/**
* Create a new TypeDoc application instance.
*/
Expand Down Expand Up @@ -431,6 +437,8 @@ export class Application extends ChildableComponent<
validateLinks(project, this.logger);
}

this.trigger(Application.EVENT_VALIDATION_RUN, project);

this.logger.verbose(`Validation took ${Date.now() - start}ms`);
}

Expand Down
11 changes: 10 additions & 1 deletion src/lib/utils/events.ts
Expand Up @@ -7,6 +7,9 @@
// The Events object is a typesafe conversion of Backbones Events object:
// https://github.com/jashkenas/backbone/blob/05fde9e201f7e2137796663081105cd6dad12a98/backbone.js#L119-L374

import type { ProjectReflection } from "../models/index";
import type { Application } from "../application";

const uniqueId = (function () {
const prefixes: Record<string, number | undefined> = Object.create(null);
return function (prefix: string) {
Expand Down Expand Up @@ -433,6 +436,12 @@ export class EventDispatcher {
context?: any,
priority?: number
): this;
on(
RebeccaStevens marked this conversation as resolved.
Show resolved Hide resolved
name: (typeof Application)["EVENT_VALIDATION_RUN"],
callback: (project: ProjectReflection) => void,
context?: any,
priority?: number
): this;
on(
name: string,
callback: EventCallback,
Expand All @@ -441,7 +450,7 @@ export class EventDispatcher {
): this;
on(
nameOrMap: EventMap | string,
callback: EventCallback,
callback?: EventCallback,
context?: any,
priority?: number
) {
Expand Down