@astryxdesign/cli 0.7.2-canary.01eab6a → 0.7.2-canary.020e1fe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/api/build/help/help.mjs +1 -1
- package/api/docs/_adapter.d.mts +11 -0
- package/api/docs/_adapter.mjs +244 -1
- package/api/docs/integrationDocs.test.mjs +124 -0
- package/api/doctor/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/init/run/run.mjs +2 -2
- package/api/integration/add-contribution.mjs +1 -1
- package/api/integration/add-contribution.test.mjs +4 -2
- package/api/integration/check/check.d.mts +96 -0
- package/api/integration/check/check.mjs +357 -0
- package/api/integration/check/check.test.mjs +489 -0
- package/api/integration/integration-check.type.d.mts +118 -0
- package/api/integration/integration-check.type.mjs +84 -0
- package/api/integration/integrationCheck.doc.d.mts +10 -0
- package/api/integration/integrationCheck.doc.mjs +73 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +27 -6
- package/api/integration/validate-integration.mjs +8 -0
- package/api/integration/validate-integration.test.mjs +11 -0
- package/api/integration/validate-integration.type.d.mts +8 -0
- package/api/integration/validate-integration.type.mjs +12 -1
- package/api/integration/validateIntegration.doc.mjs +19 -3
- package/api/search/search.d.mts +72 -12
- package/api/search/search.domain-priority.test.mjs +108 -18
- package/api/search/search.integration-check.test.mjs +24 -0
- package/api/search/search.mjs +501 -37
- package/api/search/search.test.mjs +139 -0
- package/api/theme/build/build.family.test.mjs +54 -6
- package/api/theme/build/build.mjs +114 -17
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/assets/docs/README.md +10 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +3 -3
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
- package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
- package/assets/docs/tree/block-template.doc.mjs +8 -20
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +52 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
- package/assets/docs/tree/checks.doc.mjs +21 -13
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +3 -5
- package/assets/docs/tree/component-imports.doc.mjs +2 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/docs.doc.mjs +3 -3
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
- package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
- package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
- package/assets/docs/tree/integrations.doc.mjs +8 -0
- package/assets/docs/tree/links.doc.mjs +6 -5
- package/assets/docs/tree/migration-setup.doc.mjs +1 -0
- package/assets/docs/tree/migration-verification.doc.mjs +0 -1
- package/assets/docs/tree/migration.doc.mjs +0 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +4 -8
- package/assets/docs/tree/publishing.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +37 -21
- package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
- package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
- package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
- package/assets/docs/tree/single-component.doc.mjs +12 -4
- package/assets/docs/tree/start-a-template.doc.mjs +3 -3
- package/assets/docs/tree/subcomponent.doc.mjs +6 -6
- package/assets/docs/tree/template-assets.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +2 -2
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
- package/assets/docs/tree/type-scale.doc.mjs +3 -3
- package/assets/docs/tree/upgrading.doc.mjs +3 -3
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +6 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/theme.template.ts +1 -1
- package/authoring/codemod/codemod.doc.mjs +7 -3
- package/authoring/config/config.doc.mjs +9 -6
- package/authoring/config/type.ts +4 -2
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
- package/authoring/doctypes/command/command.doc.mjs +14 -12
- package/authoring/doctypes/component/component.doc.mjs +28 -25
- package/authoring/doctypes/component/type.ts +7 -5
- package/authoring/doctypes/enum/enum.doc.mjs +7 -4
- package/authoring/doctypes/function/function.doc.mjs +9 -8
- package/authoring/doctypes/hook/hook.doc.mjs +5 -4
- package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
- package/authoring/doctypes/reference/reference.doc.mjs +11 -10
- package/authoring/doctypes/schema/schema.doc.mjs +9 -9
- package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
- package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
- package/authoring/doctypes/template/parse.d.mts +6 -2
- package/authoring/doctypes/template/parse.mjs +3 -1
- package/authoring/doctypes/template/template.doc.mjs +3 -3
- package/authoring/doctypes/template/type.ts +22 -0
- package/authoring/doctypes/theme/theme.doc.mjs +2 -2
- package/authoring/gap-report/gap-report.doc.mjs +2 -2
- package/authoring/identity/identity.doc.mjs +3 -3
- package/authoring/index.d.ts +1 -0
- package/authoring/integration/integration.doc.mjs +12 -4
- package/authoring/integration/parse.test.mjs +10 -0
- package/authoring/integration/schema.d.mts +2 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +4 -0
- package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
- package/clients/cli/commands/build-theme.mjs +1 -1
- package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +11 -4
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
- package/clients/cli/commands/doctor-integration.test.mjs +512 -2
- package/clients/cli/commands/doctor.mjs +116 -0
- package/clients/cli/commands/integration-check.doc.mjs +85 -0
- package/clients/cli/commands/integration-check.test.mjs +267 -0
- package/clients/cli/commands/integration.doc.mjs +6 -2
- package/clients/cli/commands/integration.mjs +107 -1
- package/clients/cli/commands/setup-nudge.test.mjs +79 -1
- package/clients/cli/commands/swizzle.mjs +5 -3
- package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
- package/clients/cli/commands/text-json-parity.test.mjs +5 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/index.mjs +30 -5
- package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
- package/foundation/agent-docs/agent-doc-state.mjs +38 -0
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/config/project.mjs +82 -0
- package/foundation/discovery/authoring-self-docs.mjs +2 -1
- package/foundation/discovery/doc-types.d.mts +157 -0
- package/foundation/discovery/doc-types.mjs +1224 -0
- package/foundation/discovery/doc-types.test.mjs +700 -0
- package/foundation/discovery/docs-discovery.d.mts +81 -0
- package/foundation/discovery/docs-discovery.mjs +57 -0
- package/foundation/discovery/integration-doc-files.d.mts +22 -0
- package/foundation/discovery/integration-doc-files.mjs +231 -0
- package/foundation/discovery/integration-doc-files.test.mjs +246 -0
- package/foundation/discovery/project-typescript.d.mts +11 -2
- package/foundation/discovery/project-typescript.mjs +32 -4
- package/foundation/discovery/prop-drift.d.mts +62 -4
- package/foundation/discovery/prop-drift.mjs +561 -63
- package/foundation/discovery/prop-drift.test.mjs +1086 -11
- package/foundation/discovery/type-match.d.mts +53 -0
- package/foundation/discovery/type-match.mjs +660 -0
- package/foundation/discovery/type-match.test.mjs +169 -0
- package/foundation/discovery/type-text.d.mts +68 -0
- package/foundation/discovery/type-text.mjs +658 -0
- package/foundation/discovery/type-text.test.mjs +196 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +8 -2
- package/foundation/doc-compiler/links.d.mts +9 -5
- package/foundation/doc-compiler/links.mjs +4 -2
- package/foundation/response/response-types.doc.mjs +7 -2
- package/package.json +9 -9
- package/scripts/postinstall.mjs +3 -3
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
* pass the prop (one only some members of the props type require, or that
|
|
29
29
|
* the package's `defaultProps` fills, is optional, as it is to JSX
|
|
30
30
|
* callers; an entry that names several props claims its `required` for
|
|
31
|
-
* each)
|
|
31
|
+
* each);
|
|
32
|
+
* - `type_mismatch`: for a prop declared in the package, the documented type
|
|
33
|
+
* differs from the code's where both sides read exactly (type-match.mjs
|
|
34
|
+
* states the rules); every other type is listed as not compared.
|
|
32
35
|
*
|
|
33
36
|
* @input Component records (name, docPath, sourcePath), or prop tables, the
|
|
34
37
|
* package root, and the directories to resolve `typescript` from.
|
|
@@ -44,15 +47,18 @@ import {loadComponentDoc} from './component-loader.mjs';
|
|
|
44
47
|
import {readPackageTsconfig} from './package-tsconfig.mjs';
|
|
45
48
|
import {
|
|
46
49
|
resolveProjectTypeScript,
|
|
50
|
+
TYPESCRIPT_FIX,
|
|
47
51
|
unusableTypeScriptReason,
|
|
48
52
|
} from './project-typescript.mjs';
|
|
53
|
+
import {judgeType} from './type-match.mjs';
|
|
54
|
+
import {typeTextTooOld} from './type-text.mjs';
|
|
49
55
|
import {
|
|
50
56
|
unresolvedGlobals,
|
|
51
57
|
unresolvedReference,
|
|
52
58
|
} from './unresolved-references.mjs';
|
|
53
59
|
|
|
54
60
|
/**
|
|
55
|
-
* @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch'} PropDriftKind
|
|
61
|
+
* @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch' | 'type_mismatch'} PropDriftKind
|
|
56
62
|
*/
|
|
57
63
|
|
|
58
64
|
/**
|
|
@@ -77,6 +83,16 @@ import {
|
|
|
77
83
|
* @property {string} reason why its props could not be read
|
|
78
84
|
*/
|
|
79
85
|
|
|
86
|
+
/**
|
|
87
|
+
* @typedef {object} PropDriftTypesNotCompared
|
|
88
|
+
* @property {string} component
|
|
89
|
+
* @property {string} doc the doc file, relative to the package root
|
|
90
|
+
* @property {string} reason why: not a form the check judges exactly, a
|
|
91
|
+
* field the prop's variants give different types, a standard prop
|
|
92
|
+
* (`className`, `style`, …), or a prop declared outside the package
|
|
93
|
+
* @property {string[]} props documented props whose types were not compared
|
|
94
|
+
*/
|
|
95
|
+
|
|
80
96
|
/**
|
|
81
97
|
* @typedef {object} PropDriftReport
|
|
82
98
|
* @property {'checked' | 'skipped'} status `skipped` means nothing was
|
|
@@ -84,12 +100,16 @@ import {
|
|
|
84
100
|
* @property {string} [reason]
|
|
85
101
|
* @property {string} [typescript] the version of the compiler that read the props
|
|
86
102
|
* @property {number} components how many documented prop tables were compared
|
|
103
|
+
* @property {number} typesCompared how many documented prop types were judged
|
|
104
|
+
* @property {string} [typesSkipped] why no prop type was judged
|
|
87
105
|
* @property {PropDriftFinding[]} findings
|
|
88
106
|
* @property {PropDriftUnchecked[]} unchecked documented components whose props
|
|
89
107
|
* could not be read from the source
|
|
90
108
|
* @property {Array<PropDriftUnchecked & {props: string[]}>} [propsNotChecked]
|
|
91
109
|
* props a mapped type builds from keys the check can't trace, which a doc
|
|
92
110
|
* leaving out draws no warning for
|
|
111
|
+
* @property {PropDriftTypesNotCompared[]} typesNotCompared every other
|
|
112
|
+
* documented prop type, grouped by why it was not judged
|
|
93
113
|
*/
|
|
94
114
|
|
|
95
115
|
/**
|
|
@@ -125,11 +145,21 @@ export const PROPS_NOT_DOCUMENTED = Object.freeze([
|
|
|
125
145
|
|
|
126
146
|
/** The guidance's internal props: a declaration tagged `@internal`. */
|
|
127
147
|
const SKIP_TAGS = new Set(['internal']);
|
|
148
|
+
/** Why a documented prop type was not judged (`typesNotCompared`). */
|
|
149
|
+
const NOT_EXACT = 'not a form the check judges exactly';
|
|
150
|
+
/** A field documented with one variant's type, where they differ. */
|
|
151
|
+
const VARIANTS = "the prop's variants give this field different types";
|
|
152
|
+
/** @type {(name: string, code?: CodeProp) => string} why a prop is not judged */
|
|
153
|
+
const outside = (name, code) =>
|
|
154
|
+
code?.untraced
|
|
155
|
+
? NOT_EXACT
|
|
156
|
+
: PROPS_NOT_DOCUMENTED.includes(name)
|
|
157
|
+
? 'standard prop, not compared'
|
|
158
|
+
: 'declared outside the package, not compared';
|
|
128
159
|
const HOOK_NAME = /^use[A-Z0-9]/;
|
|
129
160
|
|
|
130
161
|
/** The line both surfaces print when the compiler is missing. */
|
|
131
|
-
export const TYPESCRIPT_MISSING_REASON =
|
|
132
|
-
'TypeScript is not installed in this project, so documented props were not compared with the code. Install typescript and run this check again.';
|
|
162
|
+
export const TYPESCRIPT_MISSING_REASON = `TypeScript is not installed in this project, so documented props were not compared with the code. ${TYPESCRIPT_FIX}`;
|
|
133
163
|
|
|
134
164
|
/**
|
|
135
165
|
* @template T
|
|
@@ -201,8 +231,14 @@ function ownFileTest(root) {
|
|
|
201
231
|
* @property {boolean} [untraced] built from keys the check can't trace
|
|
202
232
|
* @property {boolean} skipTagged its declaration carries an internal JSDoc tag
|
|
203
233
|
* @property {string[]} declared the type as written, per own declaration
|
|
204
|
-
* @property {() => string[]} renderings the compiler's renderings, computed on demand
|
|
234
|
+
* @property {() => string[][]} renderings the compiler's renderings, computed on demand
|
|
205
235
|
* @property {() => any[]} types the prop's type in each member of the props type
|
|
236
|
+
* @property {boolean} intersected one member declares it more than once (an
|
|
237
|
+
* intersection), so no one declaration's text is its type
|
|
238
|
+
* @property {() => any[] | null} indexed the type an index signature gives
|
|
239
|
+
* the name in each member that lacks the prop; null when two signatures
|
|
240
|
+
* in one member take it
|
|
241
|
+
* @property {any} location where names in the prop's type resolve
|
|
206
242
|
*/
|
|
207
243
|
|
|
208
244
|
/**
|
|
@@ -216,7 +252,7 @@ function ownFileTest(root) {
|
|
|
216
252
|
* @param {import('./unresolved-references.mjs').UnresolvedReference | null} ambient
|
|
217
253
|
* what the program's other roots cannot resolve, which any component may
|
|
218
254
|
* use
|
|
219
|
-
* @returns {{ok: true, props: Map<string, CodeProp>, accepts: (name: string) =>
|
|
255
|
+
* @returns {{ok: true, props: Map<string, CodeProp>, accepts: (name: string) => any} | {ok: false, reason: string}}
|
|
220
256
|
*/
|
|
221
257
|
function readCodeProps(
|
|
222
258
|
ts,
|
|
@@ -328,7 +364,7 @@ function readCodeProps(
|
|
|
328
364
|
}
|
|
329
365
|
/** @type {Map<string, CodeProp>} */
|
|
330
366
|
const props = new Map();
|
|
331
|
-
if (propsTypes.length === 0) return {ok: true, props, accepts: () =>
|
|
367
|
+
if (propsTypes.length === 0) return {ok: true, props, accepts: () => []};
|
|
332
368
|
|
|
333
369
|
// Props that are `any`, written so or made from it (`FC<any>`, or
|
|
334
370
|
// `forwardRef<E, any>`'s `Omit<any, 'ref'>`).
|
|
@@ -475,42 +511,75 @@ function readCodeProps(
|
|
|
475
511
|
),
|
|
476
512
|
),
|
|
477
513
|
// A property's `type` is the prop's type; a method's is its return
|
|
478
|
-
// type, so a method prop reads as the compiler renders it.
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
514
|
+
// type, so a method prop reads as the compiler renders it. A
|
|
515
|
+
// declaration's text counts only for its own symbol, or where a mapping
|
|
516
|
+
// copies its type unchanged (`Pick`, `Omit`): one that rewrites it
|
|
517
|
+
// (`{[K in keyof T]: T[K][]}`, `Required<T>`) is judged by its type.
|
|
518
|
+
declared: symbols.flatMap(
|
|
519
|
+
/** @param {any} s */ s =>
|
|
520
|
+
(s.declarations ?? [])
|
|
521
|
+
.filter(
|
|
522
|
+
/** @param {any} d */ d =>
|
|
523
|
+
ownDeclarations.includes(d) &&
|
|
524
|
+
d.type &&
|
|
525
|
+
!ts.isMethodSignature(d) &&
|
|
526
|
+
!ts.isMethodDeclaration(d) &&
|
|
527
|
+
copiesType(ts, checker, s, d, sourceFile),
|
|
528
|
+
)
|
|
529
|
+
.map(/** @param {any} d */ d => d.type.getText(d.getSourceFile())),
|
|
530
|
+
),
|
|
485
531
|
types: () =>
|
|
486
532
|
symbols.map(
|
|
487
533
|
/** @param {any} s */ s =>
|
|
488
534
|
checker.getTypeOfSymbolAtLocation(s, sourceFile),
|
|
489
535
|
),
|
|
536
|
+
intersected: symbols.some(
|
|
537
|
+
/** @param {any} s */ s =>
|
|
538
|
+
(s.declarations ?? []).filter(/** @param {any} d */ d => d.type)
|
|
539
|
+
.length > 1,
|
|
540
|
+
),
|
|
541
|
+
indexed: memo(() => {
|
|
542
|
+
const lacking = members.filter(
|
|
543
|
+
/** @param {any} m */ m => !checker.getPropertyOfType(m, name),
|
|
544
|
+
);
|
|
545
|
+
const each = lacking.map(
|
|
546
|
+
/** @param {any} m */ m => indexesFor(ts, checker, [m], name),
|
|
547
|
+
);
|
|
548
|
+
return each.some(indexes => indexes.length > 1)
|
|
549
|
+
? null
|
|
550
|
+
: each.flatMap(indexes => indexes.map(info => info.type));
|
|
551
|
+
}),
|
|
552
|
+
location: ownDeclarations[0] ?? sourceFile,
|
|
553
|
+
// Printed where the prop is declared, where a documented type's names
|
|
554
|
+
// resolve: a type another file imports under another name prints as
|
|
555
|
+
// that file names it.
|
|
490
556
|
renderings: memo(() => {
|
|
557
|
+
const at = ownDeclarations[0] ?? sourceFile;
|
|
491
558
|
/** @type {string[]} */
|
|
492
559
|
const printed = [];
|
|
560
|
+
/** @type {string[]} */
|
|
561
|
+
const expanded = [];
|
|
493
562
|
for (const s of symbols) {
|
|
494
563
|
const propType = checker.getTypeOfSymbolAtLocation(s, sourceFile);
|
|
495
564
|
for (const part of inDeclaredOrder(ts, checker, propType, s)) {
|
|
496
|
-
printed.push(checker.typeToString(part,
|
|
565
|
+
printed.push(checker.typeToString(part, at, flags));
|
|
566
|
+
expanded.push(
|
|
567
|
+
checker.typeToString(
|
|
568
|
+
part,
|
|
569
|
+
at,
|
|
570
|
+
flags | ts.TypeFormatFlags.InTypeAlias,
|
|
571
|
+
),
|
|
572
|
+
);
|
|
497
573
|
}
|
|
498
574
|
}
|
|
499
|
-
return printed;
|
|
575
|
+
return [printed, expanded];
|
|
500
576
|
}),
|
|
501
577
|
});
|
|
502
578
|
}
|
|
503
579
|
|
|
504
|
-
/**
|
|
580
|
+
/** The index signatures of the props type that take this name. */
|
|
505
581
|
const accepts = (/** @type {string} */ name) =>
|
|
506
|
-
members
|
|
507
|
-
/** @param {any} member */ member =>
|
|
508
|
-
(checker.getIndexInfosOfType?.(member) ?? []).some(
|
|
509
|
-
/** @param {any} info */ info =>
|
|
510
|
-
!holdsNothing(ts, info.type) &&
|
|
511
|
-
keyAccepts(ts, checker, info.keyType, name),
|
|
512
|
-
),
|
|
513
|
-
);
|
|
582
|
+
indexesFor(ts, checker, members, name);
|
|
514
583
|
return {ok: true, props, accepts};
|
|
515
584
|
}
|
|
516
585
|
|
|
@@ -567,30 +636,140 @@ function inDeclaredOrder(ts, checker, type, symbol) {
|
|
|
567
636
|
);
|
|
568
637
|
}
|
|
569
638
|
|
|
639
|
+
/**
|
|
640
|
+
* Whether a declaration's text reads as the prop's type: it is the prop's own
|
|
641
|
+
* declaration, or the generic type's prop it instantiates when the result
|
|
642
|
+
* prints as the declared type in the component's file (a generic component
|
|
643
|
+
* passing its own type parameters on), or a mapping copies its type
|
|
644
|
+
* unchanged. Instantiated with another type (`Box<string>`, `ListProps<T[]>`,
|
|
645
|
+
* or an imported `Item` the file names another way), its text names a type
|
|
646
|
+
* the prop no longer has.
|
|
647
|
+
* @param {any} ts
|
|
648
|
+
* @param {any} checker
|
|
649
|
+
* @param {any} symbol the prop
|
|
650
|
+
* @param {any} declaration one of its declarations
|
|
651
|
+
* @param {any} location
|
|
652
|
+
*/
|
|
653
|
+
function copiesType(ts, checker, symbol, declaration, location) {
|
|
654
|
+
const own = declaration.name && checker.getSymbolAtLocation(declaration.name);
|
|
655
|
+
if (!own) return false;
|
|
656
|
+
if (own === symbol) return true;
|
|
657
|
+
const type = checker.getTypeOfSymbolAtLocation(symbol, location);
|
|
658
|
+
const declared = checker.getTypeOfSymbolAtLocation(own, location);
|
|
659
|
+
/** @param {any} t */
|
|
660
|
+
const print = t =>
|
|
661
|
+
checker.typeToString(t, location, ts.TypeFormatFlags.NoTruncation);
|
|
662
|
+
return (
|
|
663
|
+
declared === type ||
|
|
664
|
+
(own === (symbol.links ?? symbol).target && print(type) === print(declared))
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Does the code take `undefined` itself, written or through an alias? With
|
|
670
|
+
* `exactOptionalPropertyTypes` that is part of the type a message shows;
|
|
671
|
+
* otherwise an optional prop takes `undefined` anyway.
|
|
672
|
+
* @param {any} checker
|
|
673
|
+
* @param {CodeProp} code
|
|
674
|
+
* @param {boolean} exactOptional
|
|
675
|
+
*/
|
|
676
|
+
function ownUndefined(checker, code, exactOptional) {
|
|
677
|
+
const undefinedType = checker.getUndefinedType?.();
|
|
678
|
+
return (
|
|
679
|
+
exactOptional &&
|
|
680
|
+
(code.declared.some(text => /\bundefined\b/.test(text)) ||
|
|
681
|
+
code
|
|
682
|
+
.types()
|
|
683
|
+
.some(t => (t.isUnion() ? t.types : [t]).includes(undefinedType)))
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* One of a prop's renderings for a message, without the `undefined` an
|
|
689
|
+
* optional prop adds, unless the code takes it itself.
|
|
690
|
+
* @param {CodeProp} code
|
|
691
|
+
* @param {number} which 0 as printed, 1 expanded
|
|
692
|
+
* @param {boolean} keepUndefined
|
|
693
|
+
*/
|
|
694
|
+
function rendered(code, which, keepUndefined) {
|
|
695
|
+
const parts = code.renderings()[which];
|
|
696
|
+
return [
|
|
697
|
+
...new Set(
|
|
698
|
+
parts.filter(
|
|
699
|
+
part =>
|
|
700
|
+
!(code.required !== true && part === 'undefined' && !keepUndefined),
|
|
701
|
+
),
|
|
702
|
+
),
|
|
703
|
+
].join(' | ');
|
|
704
|
+
}
|
|
705
|
+
|
|
570
706
|
/**
|
|
571
707
|
* The prop's type for a message: as the source writes it when its
|
|
572
708
|
* declarations agree, else (a method or accessor, or declarations that differ
|
|
573
|
-
* or narrow each other in an intersection) as the compiler prints it
|
|
574
|
-
* the `undefined` an optional prop adds.
|
|
709
|
+
* or narrow each other in an intersection) as the compiler prints it.
|
|
575
710
|
* @param {CodeProp} code
|
|
711
|
+
* @param {boolean} keepUndefined
|
|
576
712
|
*/
|
|
577
|
-
function codeTypeText(code) {
|
|
713
|
+
function codeTypeText(code, keepUndefined) {
|
|
578
714
|
const written = [...new Set(code.declared)];
|
|
579
715
|
const text =
|
|
580
|
-
written.length === 1
|
|
581
|
-
? written[0]
|
|
582
|
-
: [
|
|
583
|
-
...new Set(
|
|
584
|
-
code
|
|
585
|
-
.renderings()
|
|
586
|
-
.filter(
|
|
587
|
-
part => !(code.required !== true && part === 'undefined'),
|
|
588
|
-
),
|
|
589
|
-
),
|
|
590
|
-
].join(' | ');
|
|
716
|
+
written.length === 1 ? written[0] : rendered(code, 0, keepUndefined);
|
|
591
717
|
return text.replace(/\s+/g, ' ').trim();
|
|
592
718
|
}
|
|
593
719
|
|
|
720
|
+
/**
|
|
721
|
+
* Judge a documented type against a prop's code type (type-match.mjs).
|
|
722
|
+
* @param {any} ts
|
|
723
|
+
* @param {any} checker
|
|
724
|
+
* @param {string} docType
|
|
725
|
+
* @param {CodeProp} code
|
|
726
|
+
* @param {{nullable: boolean, exactOptional: boolean, isDefaultLibrary: (file: any) => boolean}} reading
|
|
727
|
+
* how the project checks null, and which files are TypeScript's own
|
|
728
|
+
*/
|
|
729
|
+
function judgeProp(ts, checker, docType, code, reading) {
|
|
730
|
+
// A member that lacks the prop may take its name through an index
|
|
731
|
+
// signature, which a doc may describe too.
|
|
732
|
+
const indexed = code.indexed();
|
|
733
|
+
if (indexed == null) return 'not_compared';
|
|
734
|
+
return judgeMembers(docType, [...code.types(), ...indexed], {
|
|
735
|
+
ts,
|
|
736
|
+
checker,
|
|
737
|
+
location: code.location,
|
|
738
|
+
optional: code.required !== true && !reading.exactOptional,
|
|
739
|
+
...reading,
|
|
740
|
+
// Declared text reads as the type only when each declaration is one
|
|
741
|
+
// member's; intersected declarations narrow each other.
|
|
742
|
+
written: code.intersected
|
|
743
|
+
? code.renderings()
|
|
744
|
+
: [
|
|
745
|
+
code.declared,
|
|
746
|
+
...code.declared.map(text => [text]),
|
|
747
|
+
...code.renderings(),
|
|
748
|
+
],
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Judge a documented type against the types a prop has in the members of a
|
|
754
|
+
* union of props types: a doc may describe one member, so any member's type,
|
|
755
|
+
* or their union, matches, and it is a mismatch only against every one.
|
|
756
|
+
* @param {string} docType
|
|
757
|
+
* @param {any[]} types the type in each member
|
|
758
|
+
* @param {import('./type-match.mjs').JudgeContext} ctx
|
|
759
|
+
* @returns {import('./type-match.mjs').TypeVerdict}
|
|
760
|
+
*/
|
|
761
|
+
function judgeMembers(docType, types, ctx) {
|
|
762
|
+
const candidates =
|
|
763
|
+
types.length > 1 ? [types, ...types.map(type => [type])] : [types];
|
|
764
|
+
const verdicts = candidates.map(candidate =>
|
|
765
|
+
judgeType(docType, candidate, ctx),
|
|
766
|
+
);
|
|
767
|
+
if (verdicts.includes('match')) return 'match';
|
|
768
|
+
return verdicts.every(verdict => verdict === 'mismatch')
|
|
769
|
+
? 'mismatch'
|
|
770
|
+
: 'not_compared';
|
|
771
|
+
}
|
|
772
|
+
|
|
594
773
|
/**
|
|
595
774
|
* The props one doc entry names. `a / b` documents each of `a` and `b`, with
|
|
596
775
|
* the entry's `required` (and the type split the same way when it splits
|
|
@@ -656,37 +835,101 @@ function holders(ts, checker, type, depth = 0) {
|
|
|
656
835
|
}
|
|
657
836
|
|
|
658
837
|
/**
|
|
659
|
-
*
|
|
660
|
-
*
|
|
838
|
+
* Whether a type takes `undefined` (an index signature's value type, which
|
|
839
|
+
* TypeScript holds an explicit `undefined` to).
|
|
840
|
+
* @param {any} ts
|
|
841
|
+
* @param {any} type
|
|
842
|
+
*/
|
|
843
|
+
function takesUndefined(ts, type) {
|
|
844
|
+
return (type.isUnion() ? type.types : [type]).some(
|
|
845
|
+
/** @param {any} t */ t => t.flags & ts.TypeFlags.Undefined,
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* The types a field path reaches in a prop's type (in each member of a union
|
|
851
|
+
* that has it, through arrays at any depth), and whether its last field is
|
|
852
|
+
* optional: null when no member has the path, `any` when a type on the way
|
|
853
|
+
* is `any` or `unknown`, which holds any field.
|
|
661
854
|
* @param {any} ts
|
|
662
855
|
* @param {any} checker
|
|
663
856
|
* @param {CodeProp} code
|
|
664
857
|
* @param {string[]} fieldPath
|
|
858
|
+
* @returns {{types: any[], optional: boolean, ambiguous: boolean, indexed: boolean} | 'any' | null}
|
|
859
|
+
* `ambiguous` when two index signatures take a field on the path, and
|
|
860
|
+
* `indexed` when only index signatures take the last field
|
|
665
861
|
*/
|
|
666
|
-
function
|
|
862
|
+
function fieldTypes(ts, checker, code, fieldPath) {
|
|
667
863
|
/** @type {any[]} */
|
|
668
864
|
let current = code.types();
|
|
865
|
+
let optional = false;
|
|
866
|
+
let ambiguous = false;
|
|
867
|
+
let indexed = false;
|
|
669
868
|
for (const field of fieldPath) {
|
|
670
869
|
/** @type {any[]} */
|
|
671
870
|
const next = [];
|
|
871
|
+
optional = false;
|
|
872
|
+
let byName = false;
|
|
672
873
|
for (const holder of current.flatMap(t => holders(ts, checker, t))) {
|
|
673
|
-
if (holder.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
|
|
874
|
+
if (holder.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
|
|
875
|
+
return 'any';
|
|
876
|
+
}
|
|
674
877
|
const prop = checker.getPropertyOfType(holder, field);
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
878
|
+
if (prop) {
|
|
879
|
+
next.push(checker.getTypeOfSymbol(prop));
|
|
880
|
+
if (prop.flags & ts.SymbolFlags.Optional) optional = true;
|
|
881
|
+
byName = true;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
// A field an index signature takes (`Record<string, string>`) is of the
|
|
885
|
+
// index's type, which takes `undefined` only when it says so; two that
|
|
886
|
+
// take it hold it to both.
|
|
887
|
+
const indexes = indexesFor(ts, checker, [holder], field);
|
|
888
|
+
if (indexes.length > 1) ambiguous = true;
|
|
889
|
+
if (indexes.length > 0) {
|
|
890
|
+
next.push(indexes[0].type);
|
|
891
|
+
if (takesUndefined(ts, indexes[0].type)) optional = true;
|
|
892
|
+
}
|
|
685
893
|
}
|
|
686
|
-
if (next.length === 0) return
|
|
894
|
+
if (next.length === 0) return null;
|
|
687
895
|
current = next;
|
|
896
|
+
indexed = !byName;
|
|
688
897
|
}
|
|
689
|
-
return
|
|
898
|
+
return {types: current, optional, ambiguous, indexed};
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* The types a field path reaches, printed where the prop is declared, where
|
|
903
|
+
* a documented type's names resolve.
|
|
904
|
+
* @param {any} ts
|
|
905
|
+
* @param {any} checker
|
|
906
|
+
* @param {{types: any[], optional: boolean}} reached
|
|
907
|
+
* @param {boolean} exactOptional the project sets `exactOptionalPropertyTypes`
|
|
908
|
+
* @param {any} location where the prop is declared
|
|
909
|
+
* @returns {string[]}
|
|
910
|
+
*/
|
|
911
|
+
function fieldTypeText(ts, checker, reached, exactOptional, location) {
|
|
912
|
+
// An optional field's `undefined` is the compiler's own; with
|
|
913
|
+
// `exactOptionalPropertyTypes` it is a marker of its own, and one the code
|
|
914
|
+
// declares stays.
|
|
915
|
+
const own = /** @param {any} t */ t =>
|
|
916
|
+
reached.optional &&
|
|
917
|
+
t.flags & ts.TypeFlags.Undefined &&
|
|
918
|
+
(!exactOptional || t !== checker.getUndefinedType?.());
|
|
919
|
+
return [
|
|
920
|
+
...new Set(
|
|
921
|
+
reached.types
|
|
922
|
+
.flatMap(t => (t.isUnion() ? t.types : [t]))
|
|
923
|
+
.filter(t => !own(t))
|
|
924
|
+
.map(t =>
|
|
925
|
+
checker.typeToString(
|
|
926
|
+
t,
|
|
927
|
+
location,
|
|
928
|
+
ts.TypeFormatFlags.UseSingleQuotesForStringLiteralType,
|
|
929
|
+
),
|
|
930
|
+
),
|
|
931
|
+
),
|
|
932
|
+
];
|
|
690
933
|
}
|
|
691
934
|
|
|
692
935
|
/**
|
|
@@ -902,6 +1145,33 @@ function keyAccepts(ts, checker, key, name) {
|
|
|
902
1145
|
return new RegExp(`^${pattern}$`).test(name);
|
|
903
1146
|
}
|
|
904
1147
|
|
|
1148
|
+
/**
|
|
1149
|
+
* The index signatures of these types that take a name, as TypeScript
|
|
1150
|
+
* matches keys. TypeScript holds a value to every one of them.
|
|
1151
|
+
* @param {any} ts
|
|
1152
|
+
* @param {any} checker
|
|
1153
|
+
* @param {any[]} types
|
|
1154
|
+
* @param {string} name
|
|
1155
|
+
* @returns {any[]}
|
|
1156
|
+
*/
|
|
1157
|
+
function indexesFor(ts, checker, types, name) {
|
|
1158
|
+
// One signature seen through several union members is one signature.
|
|
1159
|
+
const seen = new Set();
|
|
1160
|
+
return types
|
|
1161
|
+
.flatMap(type => checker.getIndexInfosOfType?.(type) ?? [])
|
|
1162
|
+
.filter(
|
|
1163
|
+
/** @param {any} info */ info => {
|
|
1164
|
+
const key = `${checker.typeToString(info.keyType)}\0${checker.typeToString(info.type)}`;
|
|
1165
|
+
if (seen.has(key)) return false;
|
|
1166
|
+
seen.add(key);
|
|
1167
|
+
return (
|
|
1168
|
+
!holdsNothing(ts, info.type) &&
|
|
1169
|
+
keyAccepts(ts, checker, info.keyType, name)
|
|
1170
|
+
);
|
|
1171
|
+
},
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
905
1175
|
/**
|
|
906
1176
|
* Can a value of this type be passed at all? `never`, or only `undefined`
|
|
907
1177
|
* (`Record<string, never>`, the usual way to write "no props"), cannot.
|
|
@@ -1348,8 +1618,10 @@ export function comparePropTables(tables, options) {
|
|
|
1348
1618
|
)
|
|
1349
1619
|
: TYPESCRIPT_MISSING_REASON,
|
|
1350
1620
|
components: 0,
|
|
1621
|
+
typesCompared: 0,
|
|
1351
1622
|
findings: [],
|
|
1352
1623
|
unchecked: [],
|
|
1624
|
+
typesNotCompared: [],
|
|
1353
1625
|
};
|
|
1354
1626
|
}
|
|
1355
1627
|
const {ts, version} = compiler;
|
|
@@ -1369,8 +1641,10 @@ export function comparePropTables(tables, options) {
|
|
|
1369
1641
|
status: 'checked',
|
|
1370
1642
|
typescript: version,
|
|
1371
1643
|
components: 0,
|
|
1644
|
+
typesCompared: 0,
|
|
1372
1645
|
findings: [],
|
|
1373
1646
|
unchecked,
|
|
1647
|
+
typesNotCompared: [],
|
|
1374
1648
|
};
|
|
1375
1649
|
}
|
|
1376
1650
|
|
|
@@ -1393,8 +1667,10 @@ export function comparePropTables(tables, options) {
|
|
|
1393
1667
|
status: 'checked',
|
|
1394
1668
|
typescript: version,
|
|
1395
1669
|
components: 0,
|
|
1670
|
+
typesCompared: 0,
|
|
1396
1671
|
findings: [],
|
|
1397
1672
|
unchecked,
|
|
1673
|
+
typesNotCompared: [],
|
|
1398
1674
|
};
|
|
1399
1675
|
}
|
|
1400
1676
|
const program = ts.createProgram({
|
|
@@ -1416,12 +1692,30 @@ export function comparePropTables(tables, options) {
|
|
|
1416
1692
|
project.options,
|
|
1417
1693
|
isOwnFile,
|
|
1418
1694
|
);
|
|
1695
|
+
// Without strict null checks the compiler drops `null` and `undefined`.
|
|
1696
|
+
// Whether they are on by default depends on the TypeScript version.
|
|
1697
|
+
const compilerOptions = program.getCompilerOptions();
|
|
1698
|
+
const nullable = !(typeof ts.getStrictOptionValue === 'function'
|
|
1699
|
+
? ts.getStrictOptionValue(compilerOptions, 'strictNullChecks')
|
|
1700
|
+
: (compilerOptions.strictNullChecks ?? compilerOptions.strict ?? false));
|
|
1701
|
+
const reading = {
|
|
1702
|
+
nullable,
|
|
1703
|
+
// An optional prop takes `undefined` only when the project lets it.
|
|
1704
|
+
exactOptional:
|
|
1705
|
+
!nullable && compilerOptions.exactOptionalPropertyTypes === true,
|
|
1706
|
+
isDefaultLibrary: (/** @type {any} */ file) =>
|
|
1707
|
+
program.isSourceFileDefaultLibrary(file),
|
|
1708
|
+
};
|
|
1419
1709
|
|
|
1420
1710
|
/** @type {PropDriftFinding[]} */
|
|
1421
1711
|
const findings = [];
|
|
1422
1712
|
/** @type {Array<PropDriftUnchecked & {props: string[]}>} */
|
|
1423
1713
|
const propsNotChecked = [];
|
|
1424
1714
|
let compared = 0;
|
|
1715
|
+
let typesCompared = 0;
|
|
1716
|
+
/** @type {PropDriftTypesNotCompared[]} */
|
|
1717
|
+
const typesNotCompared = [];
|
|
1718
|
+
const typesSkipped = typeTextTooOld(ts);
|
|
1425
1719
|
for (const table of tables) {
|
|
1426
1720
|
/** @type {ReturnType<typeof readCodeProps> | null} */
|
|
1427
1721
|
let read = null;
|
|
@@ -1456,14 +1750,41 @@ export function comparePropTables(tables, options) {
|
|
|
1456
1750
|
compared++;
|
|
1457
1751
|
const source = rel(sourcePath);
|
|
1458
1752
|
const documented = new Set();
|
|
1753
|
+
/** @type {Map<string, Set<string>>} */
|
|
1754
|
+
const notCompared = new Map();
|
|
1755
|
+
/** @type {(reason: string, name: string) => void} */
|
|
1756
|
+
const skip = (reason, name) => {
|
|
1757
|
+
notCompared.set(reason, (notCompared.get(reason) ?? new Set()).add(name));
|
|
1758
|
+
};
|
|
1459
1759
|
for (const raw of table.props) {
|
|
1460
1760
|
if (!raw || typeof raw.name !== 'string') continue;
|
|
1461
1761
|
const entries = documentedProps(raw);
|
|
1462
1762
|
for (const entry of entries) {
|
|
1463
1763
|
const propName = entry.name;
|
|
1464
1764
|
if (entry.spread) continue;
|
|
1765
|
+
const docType = entry.type;
|
|
1766
|
+
if (typesSkipped) entry.type = undefined;
|
|
1465
1767
|
documented.add(propName);
|
|
1466
1768
|
const code = read.props.get(propName);
|
|
1769
|
+
const reached =
|
|
1770
|
+
code && entry.path.length > 0
|
|
1771
|
+
? fieldTypes(ts, checker, code, entry.path)
|
|
1772
|
+
: null;
|
|
1773
|
+
if (
|
|
1774
|
+
entry.type === undefined &&
|
|
1775
|
+
!typesSkipped &&
|
|
1776
|
+
typeof raw.type === 'string' &&
|
|
1777
|
+
(code && entry.path.length > 0
|
|
1778
|
+
? reached
|
|
1779
|
+
: code || read.accepts(propName).length > 0)
|
|
1780
|
+
) {
|
|
1781
|
+
// `a / b` with one type that does not split across the names (a
|
|
1782
|
+
// field only once it is found).
|
|
1783
|
+
skip(
|
|
1784
|
+
code && !code.own ? outside(propName, code) : NOT_EXACT,
|
|
1785
|
+
entry.written,
|
|
1786
|
+
);
|
|
1787
|
+
}
|
|
1467
1788
|
const base = {
|
|
1468
1789
|
component: table.name,
|
|
1469
1790
|
prop: entry.written,
|
|
@@ -1472,11 +1793,74 @@ export function comparePropTables(tables, options) {
|
|
|
1472
1793
|
source,
|
|
1473
1794
|
};
|
|
1474
1795
|
if (entry.path.length > 0) {
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
) {
|
|
1796
|
+
// Listed only once the field is found; a missing one is reported.
|
|
1797
|
+
if (code && !code.own && reached && typeof entry.type === 'string') {
|
|
1798
|
+
skip(outside(propName, code), entry.written);
|
|
1799
|
+
}
|
|
1800
|
+
if (reached === 'any') {
|
|
1801
|
+
// A field of an `any` or `unknown` prop has no type to judge.
|
|
1802
|
+
if (code?.own && typeof entry.type === 'string') {
|
|
1803
|
+
skip(NOT_EXACT, entry.written);
|
|
1804
|
+
}
|
|
1805
|
+
continue;
|
|
1806
|
+
}
|
|
1807
|
+
if (code && reached) {
|
|
1808
|
+
const fieldText = fieldTypeText(
|
|
1809
|
+
ts,
|
|
1810
|
+
checker,
|
|
1811
|
+
reached,
|
|
1812
|
+
reading.exactOptional,
|
|
1813
|
+
code.location,
|
|
1814
|
+
);
|
|
1815
|
+
const ctx = {
|
|
1816
|
+
ts,
|
|
1817
|
+
checker,
|
|
1818
|
+
location: code.location,
|
|
1819
|
+
// A name an index signature takes sets the index's
|
|
1820
|
+
// `undefined` aside, as a prop of that name does.
|
|
1821
|
+
optional:
|
|
1822
|
+
reached.optional && (!reading.exactOptional || reached.indexed),
|
|
1823
|
+
...reading,
|
|
1824
|
+
written: [fieldText],
|
|
1825
|
+
};
|
|
1826
|
+
const verdict =
|
|
1827
|
+
code.own && typeof entry.type === 'string'
|
|
1828
|
+
? reached.ambiguous
|
|
1829
|
+
? 'not_compared'
|
|
1830
|
+
: judgeType(entry.type, reached.types, ctx)
|
|
1831
|
+
: null;
|
|
1832
|
+
// The field takes every variant's type: the types of only some
|
|
1833
|
+
// variants are neither its type nor wrong. Past six, the sets of
|
|
1834
|
+
// them are not tried, and the type is never reported.
|
|
1835
|
+
const variants = [...new Set(reached.types)];
|
|
1836
|
+
const someVariants =
|
|
1837
|
+
(verdict === 'mismatch' || verdict === 'not_compared') &&
|
|
1838
|
+
!reached.ambiguous &&
|
|
1839
|
+
variants.length > 1 &&
|
|
1840
|
+
(variants.length > 6 ||
|
|
1841
|
+
Array.from({length: 2 ** variants.length - 2}, (_, i) =>
|
|
1842
|
+
variants.filter((__, j) => ((i + 1) >> j) & 1),
|
|
1843
|
+
).some(
|
|
1844
|
+
some => judgeType(entry.type ?? '', some, ctx) === 'match',
|
|
1845
|
+
));
|
|
1846
|
+
if (someVariants) skip(VARIANTS, entry.written);
|
|
1847
|
+
else if (verdict === 'not_compared') skip(NOT_EXACT, entry.written);
|
|
1848
|
+
else if (verdict) typesCompared++;
|
|
1849
|
+
if (verdict === 'mismatch' && !someVariants) {
|
|
1850
|
+
const codeType = fieldText.join(' | ');
|
|
1851
|
+
findings.push({
|
|
1852
|
+
...base,
|
|
1853
|
+
kind: 'type_mismatch',
|
|
1854
|
+
message: `"${entry.written}" is documented as ${entry.type}, but the code declares ${codeType}.`,
|
|
1855
|
+
docType: entry.type,
|
|
1856
|
+
codeType,
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
continue;
|
|
1860
|
+
}
|
|
1861
|
+
if (!code && read.accepts(propName).length > 0) {
|
|
1862
|
+
// A field of a name only an index signature takes.
|
|
1863
|
+
if (typeof entry.type === 'string') skip(NOT_EXACT, entry.written);
|
|
1480
1864
|
continue;
|
|
1481
1865
|
}
|
|
1482
1866
|
findings.push({
|
|
@@ -1489,12 +1873,70 @@ export function comparePropTables(tables, options) {
|
|
|
1489
1873
|
continue;
|
|
1490
1874
|
}
|
|
1491
1875
|
if (!code) {
|
|
1492
|
-
|
|
1876
|
+
// A name an index signature takes is a prop of the index's type;
|
|
1877
|
+
// TypeScript holds it to every signature that takes it, so with
|
|
1878
|
+
// several its type is not compared. Another package's signature is
|
|
1879
|
+
// not the package's to judge, and a mapped type's (`Record`) has no
|
|
1880
|
+
// declaration to say whose it is.
|
|
1881
|
+
const indexes = read.accepts(propName);
|
|
1882
|
+
const own = indexes.filter(
|
|
1883
|
+
(/** @type {any} */ i) =>
|
|
1884
|
+
i.declaration &&
|
|
1885
|
+
isOwnFile(i.declaration.getSourceFile().fileName),
|
|
1886
|
+
);
|
|
1887
|
+
const index = indexes.length === 1 ? own[0] : null;
|
|
1888
|
+
if (indexes.length > 0 && !index && typeof entry.type === 'string') {
|
|
1889
|
+
const declared = indexes.every(
|
|
1890
|
+
(/** @type {any} */ i) => i.declaration,
|
|
1891
|
+
);
|
|
1892
|
+
skip(
|
|
1893
|
+
own.length || !declared ? NOT_EXACT : outside(propName),
|
|
1894
|
+
propName,
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
if (index && typeof entry.type === 'string') {
|
|
1898
|
+
const verdict = judgeType(entry.type, [index.type], {
|
|
1899
|
+
ts,
|
|
1900
|
+
checker,
|
|
1901
|
+
location: index.declaration,
|
|
1902
|
+
// An index signature takes `undefined` only when its type does.
|
|
1903
|
+
optional: takesUndefined(ts, index.type),
|
|
1904
|
+
...reading,
|
|
1905
|
+
// Printed where the index is declared, as the doc's names
|
|
1906
|
+
// resolve there.
|
|
1907
|
+
written: [
|
|
1908
|
+
[
|
|
1909
|
+
checker.typeToString(
|
|
1910
|
+
index.type,
|
|
1911
|
+
index.declaration,
|
|
1912
|
+
ts.TypeFormatFlags.UseSingleQuotesForStringLiteralType,
|
|
1913
|
+
),
|
|
1914
|
+
],
|
|
1915
|
+
],
|
|
1916
|
+
});
|
|
1917
|
+
if (verdict === 'not_compared') skip(NOT_EXACT, propName);
|
|
1918
|
+
else typesCompared++;
|
|
1919
|
+
if (verdict === 'mismatch') {
|
|
1920
|
+
const codeType = checker.typeToString(
|
|
1921
|
+
index.type,
|
|
1922
|
+
index.declaration,
|
|
1923
|
+
ts.TypeFormatFlags.UseSingleQuotesForStringLiteralType,
|
|
1924
|
+
);
|
|
1925
|
+
findings.push({
|
|
1926
|
+
...base,
|
|
1927
|
+
kind: 'type_mismatch',
|
|
1928
|
+
message: `"${propName}" is documented as ${entry.type}, but ${table.name}'s props take it as ${codeType}.`,
|
|
1929
|
+
docType: entry.type,
|
|
1930
|
+
codeType,
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
if (indexes.length > 0) continue;
|
|
1493
1935
|
findings.push({
|
|
1494
1936
|
...base,
|
|
1495
1937
|
kind: 'not_in_code',
|
|
1496
1938
|
message: `"${propName}" is documented, but ${table.name}'s props have no "${propName}".`,
|
|
1497
|
-
...(typeof
|
|
1939
|
+
...(typeof docType === 'string' ? {docType} : {}),
|
|
1498
1940
|
});
|
|
1499
1941
|
continue;
|
|
1500
1942
|
}
|
|
@@ -1510,6 +1952,42 @@ export function comparePropTables(tables, options) {
|
|
|
1510
1952
|
codeRequired: code.required,
|
|
1511
1953
|
});
|
|
1512
1954
|
}
|
|
1955
|
+
if (!code.own && typeof entry.type === 'string') {
|
|
1956
|
+
skip(outside(propName, code), propName);
|
|
1957
|
+
}
|
|
1958
|
+
if (code.own && typeof entry.type === 'string') {
|
|
1959
|
+
const verdict = judgeProp(
|
|
1960
|
+
ts,
|
|
1961
|
+
checker,
|
|
1962
|
+
String(entry.type),
|
|
1963
|
+
code,
|
|
1964
|
+
reading,
|
|
1965
|
+
);
|
|
1966
|
+
if (verdict === 'not_compared') skip(NOT_EXACT, propName);
|
|
1967
|
+
else typesCompared++;
|
|
1968
|
+
if (verdict === 'mismatch') {
|
|
1969
|
+
const keep = ownUndefined(checker, code, reading.exactOptional);
|
|
1970
|
+
const codeType = codeTypeText(code, keep);
|
|
1971
|
+
const expanded = rendered(code, 1, keep);
|
|
1972
|
+
// The optional prop's `undefined` the expansion sets aside is no
|
|
1973
|
+
// difference to show.
|
|
1974
|
+
const bare = codeType
|
|
1975
|
+
.split(' | ')
|
|
1976
|
+
.filter(part => part !== 'undefined')
|
|
1977
|
+
.join(' | ');
|
|
1978
|
+
const shown =
|
|
1979
|
+
expanded && expanded !== codeType && expanded !== bare
|
|
1980
|
+
? `${codeType} (${expanded.length <= 400 ? expanded : `${expanded.slice(0, 400)}…`})`
|
|
1981
|
+
: codeType;
|
|
1982
|
+
findings.push({
|
|
1983
|
+
...base,
|
|
1984
|
+
kind: 'type_mismatch',
|
|
1985
|
+
message: `"${propName}" is documented as ${entry.type}, but the code declares ${shown}.`,
|
|
1986
|
+
docType: entry.type,
|
|
1987
|
+
codeType,
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1513
1991
|
}
|
|
1514
1992
|
}
|
|
1515
1993
|
/** @type {string[]} */
|
|
@@ -1526,6 +2004,10 @@ export function comparePropTables(tables, options) {
|
|
|
1526
2004
|
if (code.untraced) untraced.push(code.name);
|
|
1527
2005
|
continue;
|
|
1528
2006
|
}
|
|
2007
|
+
const codeType = codeTypeText(
|
|
2008
|
+
code,
|
|
2009
|
+
ownUndefined(checker, code, reading.exactOptional),
|
|
2010
|
+
);
|
|
1529
2011
|
findings.push({
|
|
1530
2012
|
component: table.name,
|
|
1531
2013
|
prop: code.name,
|
|
@@ -1534,7 +2016,7 @@ export function comparePropTables(tables, options) {
|
|
|
1534
2016
|
message: `${table.name} declares "${code.name}", but the doc does not list it.`,
|
|
1535
2017
|
doc: table.doc,
|
|
1536
2018
|
source,
|
|
1537
|
-
codeType
|
|
2019
|
+
codeType,
|
|
1538
2020
|
codeRequired: code.required,
|
|
1539
2021
|
});
|
|
1540
2022
|
}
|
|
@@ -1546,6 +2028,14 @@ export function comparePropTables(tables, options) {
|
|
|
1546
2028
|
props: untraced.sort(),
|
|
1547
2029
|
});
|
|
1548
2030
|
}
|
|
2031
|
+
for (const [reason, props] of notCompared) {
|
|
2032
|
+
typesNotCompared.push({
|
|
2033
|
+
component: table.name,
|
|
2034
|
+
doc: table.doc,
|
|
2035
|
+
reason,
|
|
2036
|
+
props: [...props].sort(),
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
1549
2039
|
}
|
|
1550
2040
|
|
|
1551
2041
|
// Field by field: collation ignores a separator such as NUL, which would
|
|
@@ -1557,12 +2047,20 @@ export function comparePropTables(tables, options) {
|
|
|
1557
2047
|
a.kind.localeCompare(b.kind),
|
|
1558
2048
|
);
|
|
1559
2049
|
unchecked.sort((a, b) => a.component.localeCompare(b.component));
|
|
2050
|
+
typesNotCompared.sort(
|
|
2051
|
+
(a, b) =>
|
|
2052
|
+
a.component.localeCompare(b.component) ||
|
|
2053
|
+
a.reason.localeCompare(b.reason),
|
|
2054
|
+
);
|
|
1560
2055
|
return {
|
|
1561
2056
|
status: 'checked',
|
|
1562
2057
|
typescript: version,
|
|
1563
2058
|
components: compared,
|
|
2059
|
+
typesCompared,
|
|
1564
2060
|
findings,
|
|
1565
2061
|
unchecked,
|
|
2062
|
+
typesNotCompared,
|
|
2063
|
+
...(typesSkipped ? {typesSkipped} : {}),
|
|
1566
2064
|
...(propsNotChecked.length > 0 ? {propsNotChecked} : {}),
|
|
1567
2065
|
};
|
|
1568
2066
|
}
|