Skip to content

Commit 04abc19

Browse files
refactor: create Validator class
1 parent c565bc6 commit 04abc19

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

src/lib/application.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ import {
3232
} from "./utils/entry-point";
3333
import { nicePath } from "./utils/paths";
3434
import { getLoadedPaths, hasBeenLoadedMultipleTimes } from "./utils/general";
35-
import { validateExports } from "./validation/exports";
36-
import { validateDocumentation } from "./validation/documentation";
37-
import { validateLinks } from "./validation/links";
3835
import { ApplicationEvents } from "./application-events";
36+
import { Validator } from "./validation/validator";
3937

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

76+
/**
77+
* The validator used to valid documentation.
78+
*/
79+
validator: Validator;
80+
7881
/**
7982
* The serializer used to generate JSON output.
8083
*/
@@ -119,6 +122,7 @@ export class Application extends ChildableComponent<
119122
this.serializer = new Serializer();
120123
this.converter = this.addComponent<Converter>("converter", Converter);
121124
this.renderer = this.addComponent<Renderer>("renderer", Renderer);
125+
this.validator = this.addComponent<Validator>("validator", Validator);
122126
}
123127

124128
/**
@@ -408,30 +412,7 @@ export class Application extends ChildableComponent<
408412
}
409413

410414
validate(project: ProjectReflection) {
411-
const checks = this.options.getValue("validation");
412-
const start = Date.now();
413-
414-
if (checks.notExported) {
415-
validateExports(
416-
project,
417-
this.logger,
418-
this.options.getValue("intentionallyNotExported")
419-
);
420-
}
421-
422-
if (checks.notDocumented) {
423-
validateDocumentation(
424-
project,
425-
this.logger,
426-
this.options.getValue("requiredToBeDocumented")
427-
);
428-
}
429-
430-
if (checks.invalidLink) {
431-
validateLinks(project, this.logger);
432-
}
433-
434-
this.logger.verbose(`Validation took ${Date.now() - start}ms`);
415+
this.validator.validate(project);
435416
}
436417

437418
/**

src/lib/validation/components.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { AbstractComponent } from "../utils/component";
2+
import type { Validator } from "./validator";
3+
4+
export abstract class ValidatorComponent extends AbstractComponent<Validator> {}

src/lib/validation/validator.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { Application } from "../application";
2+
import type { ProjectReflection } from "../models/index";
3+
import { Component, ChildableComponent } from "../utils/component";
4+
import { ValidatorComponent } from "./components";
5+
6+
import { validateExports } from "./exports";
7+
import { validateDocumentation } from "./documentation";
8+
import { validateLinks } from "./links";
9+
10+
@Component({
11+
name: "validator",
12+
internal: true,
13+
childClass: ValidatorComponent,
14+
})
15+
export class Validator extends ChildableComponent<
16+
Application,
17+
ValidatorComponent
18+
> {
19+
constructor(owner: Application) {
20+
super(owner);
21+
}
22+
23+
validate(project: ProjectReflection) {
24+
const checks = this.application.options.getValue("validation");
25+
const start = Date.now();
26+
27+
if (checks.notExported) {
28+
validateExports(
29+
project,
30+
this.application.logger,
31+
this.application.options.getValue("intentionallyNotExported")
32+
);
33+
}
34+
35+
if (checks.notDocumented) {
36+
validateDocumentation(
37+
project,
38+
this.application.logger,
39+
this.application.options.getValue("requiredToBeDocumented")
40+
);
41+
}
42+
43+
if (checks.invalidLink) {
44+
validateLinks(project, this.application.logger);
45+
}
46+
47+
this.application.logger.verbose(
48+
`Validation took ${Date.now() - start}ms`
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)