Skip to content

Commit

Permalink
refactor: create Validator class
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Feb 24, 2023
1 parent c565bc6 commit 04abc19
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
35 changes: 8 additions & 27 deletions src/lib/application.ts
Expand Up @@ -32,10 +32,8 @@ import {
} from "./utils/entry-point";
import { nicePath } from "./utils/paths";
import { getLoadedPaths, hasBeenLoadedMultipleTimes } from "./utils/general";
import { validateExports } from "./validation/exports";
import { validateDocumentation } from "./validation/documentation";
import { validateLinks } from "./validation/links";
import { ApplicationEvents } from "./application-events";
import { Validator } from "./validation/validator";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageInfo = require("../../package.json") as {
Expand Down Expand Up @@ -75,6 +73,11 @@ export class Application extends ChildableComponent<
*/
renderer: Renderer;

/**
* The validator used to valid documentation.
*/
validator: Validator;

/**
* The serializer used to generate JSON output.
*/
Expand Down Expand Up @@ -119,6 +122,7 @@ export class Application extends ChildableComponent<
this.serializer = new Serializer();
this.converter = this.addComponent<Converter>("converter", Converter);
this.renderer = this.addComponent<Renderer>("renderer", Renderer);
this.validator = this.addComponent<Validator>("validator", Validator);
}

/**
Expand Down Expand Up @@ -408,30 +412,7 @@ export class Application extends ChildableComponent<
}

validate(project: ProjectReflection) {
const checks = this.options.getValue("validation");
const start = Date.now();

if (checks.notExported) {
validateExports(
project,
this.logger,
this.options.getValue("intentionallyNotExported")
);
}

if (checks.notDocumented) {
validateDocumentation(
project,
this.logger,
this.options.getValue("requiredToBeDocumented")
);
}

if (checks.invalidLink) {
validateLinks(project, this.logger);
}

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

/**
Expand Down
4 changes: 4 additions & 0 deletions src/lib/validation/components.ts
@@ -0,0 +1,4 @@
import { AbstractComponent } from "../utils/component";
import type { Validator } from "./validator";

export abstract class ValidatorComponent extends AbstractComponent<Validator> {}
51 changes: 51 additions & 0 deletions src/lib/validation/validator.ts
@@ -0,0 +1,51 @@
import type { Application } from "../application";
import type { ProjectReflection } from "../models/index";
import { Component, ChildableComponent } from "../utils/component";
import { ValidatorComponent } from "./components";

import { validateExports } from "./exports";
import { validateDocumentation } from "./documentation";
import { validateLinks } from "./links";

@Component({
name: "validator",
internal: true,
childClass: ValidatorComponent,
})
export class Validator extends ChildableComponent<
Application,
ValidatorComponent
> {
constructor(owner: Application) {
super(owner);
}

validate(project: ProjectReflection) {
const checks = this.application.options.getValue("validation");
const start = Date.now();

if (checks.notExported) {
validateExports(
project,
this.application.logger,
this.application.options.getValue("intentionallyNotExported")
);
}

if (checks.notDocumented) {
validateDocumentation(
project,
this.application.logger,
this.application.options.getValue("requiredToBeDocumented")
);
}

if (checks.invalidLink) {
validateLinks(project, this.application.logger);
}

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

0 comments on commit 04abc19

Please sign in to comment.