Skip to content

Commit 37880de

Browse files
committed
Add new option to enable/disable validation checks
As discussed in #1685.
1 parent 61c3806 commit 37880de

File tree

16 files changed

+302
-42
lines changed

16 files changed

+302
-42
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Unreleased
22

3+
### Features
4+
5+
- Added new `validation` option which can be used to disable checks for non-exported symbols.
6+
On the command line, this can be specified with `--validation.notExported true`, or in an options file with:
7+
```json
8+
{
9+
"validation": {
10+
"notExported": true
11+
}
12+
}
13+
```
14+
- Added invalidLink to `validation` option, deprecated `listInvalidSymbolLinks`, which will be removed in 0.23.
15+
316
## v0.22.2 (2021-08-11)
417

518
### Bug Fixes

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"pretest": "node scripts/copy_test_files.js",
6666
"test": "mocha --config .config/mocha.fast.json",
6767
"pretest:full": "npm run pretest",
68-
"test:full": "nyc --reporter=html --reporter=text-summary mocha --config .config/mocha.full.json",
68+
"test:full": "nyc mocha --config .config/mocha.full.json",
6969
"test:visual": "node ./dist/test/capture-screenshots.js && reg-suit -c .config/regconfig.json compare",
7070
"test:visual:accept": "node scripts/accept_visual_regression.js",
7171
"prerebuild_specs": "npm run pretest",
@@ -90,8 +90,13 @@
9090
".ts",
9191
".tsx"
9292
],
93+
"reporter": [
94+
"html",
95+
"text-summary"
96+
],
9397
"exclude": [
94-
"**/*.d.ts"
98+
"**/*.d.ts",
99+
"src/test"
95100
]
96101
}
97102
}

scripts/generate_options_schema.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,26 @@ addTypeDocOptions({
2828
case ParameterType.Array:
2929
data.type = "array";
3030
data.items = { type: "string" };
31-
data.default = option.defaultValue ?? [];
31+
data.default =
32+
/** @type {import("../dist").ArrayDeclarationOption} */ (
33+
option
34+
).defaultValue ?? [];
3235
break;
3336
case ParameterType.String:
3437
data.type = "string";
3538
if (!IGNORED_DEFAULT_OPTIONS.has(option.name)) {
36-
data.default = option.defaultValue ?? "";
39+
data.default =
40+
/** @type {import("../dist").StringDeclarationOption} */ (
41+
option
42+
).defaultValue ?? "";
3743
}
3844
break;
3945
case ParameterType.Boolean:
4046
data.type = "boolean";
41-
data.default = option.defaultValue ?? false;
47+
data.default =
48+
/** @type {import("../dist").BooleanDeclarationOption} */ (
49+
option
50+
).defaultValue ?? false;
4251
break;
4352
case ParameterType.Number: {
4453
const decl =
@@ -60,9 +69,27 @@ addTypeDocOptions({
6069
map instanceof Map
6170
? [...map.keys()]
6271
: Object.keys(map).filter((key) => isNaN(+key));
63-
data.default = option.defaultValue;
72+
data.default =
73+
/** @type {import("../dist").MapDeclarationOption} */ (
74+
option
75+
).defaultValue;
6476
break;
6577
}
78+
case ParameterType.Flags: {
79+
data.properties = {};
80+
const defaults =
81+
/** @type {import("../dist").FlagsDeclarationOption<Record<string, boolean>>} */ (
82+
option
83+
).defaults;
84+
85+
for (const key of Object.keys(defaults)) {
86+
data[key] = {
87+
type: "boolean",
88+
};
89+
}
90+
data.additionalProperties = false;
91+
data.default = defaults;
92+
}
6693
case ParameterType.Mixed:
6794
break; // Nothing to do... TypeDoc really shouldn't have any of these.
6895
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type {
3535
OptionsReader,
3636
TypeDocOptions,
3737
TypeDocOptionMap,
38+
ValidationOptions,
3839
TypeDocOptionValues,
3940
KeyToDeclaration,
4041
DeclarationOption,
@@ -45,6 +46,7 @@ export type {
4546
ArrayDeclarationOption,
4647
MixedDeclarationOption,
4748
MapDeclarationOption,
49+
FlagsDeclarationOption,
4850
DeclarationOptionToOptionType,
4951
SortStrategy,
5052
ParameterTypeToOptionTypeMap,

src/lib/application.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,19 @@ export class Application extends ChildableComponent<
368368
}
369369

370370
validate(project: ProjectReflection) {
371-
validateExports(
372-
project,
373-
this.logger,
374-
this.options.getValue("intentionallyNotExported")
375-
);
371+
const checks = this.options.getValue("validation");
372+
373+
if (checks.notExported) {
374+
validateExports(
375+
project,
376+
this.logger,
377+
this.options.getValue("intentionallyNotExported")
378+
);
379+
}
380+
381+
// checks.invalidLink is currently handled when rendering by the MarkedLinksPlugin.
382+
// It should really move here, but I'm putting that off until done refactoring the comment
383+
// parsing so that we don't have duplicate parse logic all over the place.
376384
}
377385

378386
/**

src/lib/output/plugins/MarkedLinksPlugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Util from "util";
33
import type { Reflection } from "../../models/reflections/abstract";
44
import { Component, ContextAwareRendererComponent } from "../components";
55
import { MarkdownEvent, RendererEvent } from "../events";
6-
import { BindOption } from "../../utils";
6+
import { BindOption, ValidationOptions } from "../../utils";
77

88
/**
99
* A plugin that builds links in markdown texts.
@@ -24,6 +24,9 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
2424
@BindOption("listInvalidSymbolLinks")
2525
listInvalidSymbolLinks!: boolean;
2626

27+
@BindOption("validation")
28+
validation!: ValidationOptions;
29+
2730
private warnings: string[] = [];
2831

2932
/**
@@ -165,7 +168,15 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
165168
* Triggered when {@link Renderer} is finished
166169
*/
167170
onEndRenderer(_event: RendererEvent) {
168-
if (this.listInvalidSymbolLinks && this.warnings.length > 0) {
171+
const enabled =
172+
this.listInvalidSymbolLinks || this.validation.invalidLink;
173+
if (this.listInvalidSymbolLinks) {
174+
this.application.logger.warn(
175+
"listInvalidSymbolLinks is deprecated and will be removed in 0.23, set validation.invalidLink instead."
176+
);
177+
}
178+
179+
if (enabled && this.warnings.length > 0) {
169180
this.application.logger.warn(
170181
"\n[MarkedLinksPlugin]: Found invalid symbol reference(s) in JSDocs, " +
171182
"they will not render as links in the generated documentation." +

src/lib/output/themes/MarkedPlugin.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ customMarkedRenderer.heading = (text, level, _, slugger) => {
2222

2323
/**
2424
* Implements markdown and relativeURL helpers for templates.
25+
* @internal
2526
*/
2627
@Component({ name: "marked" })
2728
export class MarkedPlugin extends ContextAwareRendererComponent {
@@ -194,22 +195,13 @@ output file :
194195
"markedOptions"
195196
) ?? {}) as Marked.MarkedOptions;
196197

197-
if (
198-
typeof markedOptions === "object" &&
199-
!Array.isArray(markedOptions)
200-
) {
201-
// Set some default values if they are not specified via the TypeDoc option
202-
markedOptions.highlight ??= (text: any, lang: any) =>
203-
this.getHighlighted(text, lang);
204-
markedOptions.renderer ??= customMarkedRenderer;
205-
markedOptions.mangle ??= false; // See https://github.com/TypeStrong/typedoc/issues/1395
206-
207-
return markedOptions;
208-
}
198+
// Set some default values if they are not specified via the TypeDoc option
199+
markedOptions.highlight ??= (text: any, lang: any) =>
200+
this.getHighlighted(text, lang);
201+
markedOptions.renderer ??= customMarkedRenderer;
202+
markedOptions.mangle ??= false; // See https://github.com/TypeStrong/typedoc/issues/1395
209203

210-
throw new Error(
211-
"The value provided via the 'markedOptions' option must be a non-array object."
212-
);
204+
return markedOptions;
213205
}
214206

215207
/**

src/lib/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ export type {
3939
MapDeclarationOption,
4040
MixedDeclarationOption,
4141
NumberDeclarationOption,
42+
FlagsDeclarationOption,
4243
OptionsReader,
4344
StringDeclarationOption,
4445
TypeDocOptionMap,
4546
TypeDocOptions,
47+
ValidationOptions,
4648
TypeDocOptionValues,
4749
ParameterTypeToOptionTypeMap,
4850
} from "./options";

0 commit comments

Comments
 (0)