@astryxdesign/cli 0.7.2-canary.64e1dde → 0.7.2-canary.6c792d8
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 +62 -62
- package/api/component/_adapter.d.mts +31 -0
- package/api/component/_adapter.mjs +116 -0
- package/api/component/component.mjs +60 -10
- package/api/component/doc-links.test.mjs +386 -0
- package/api/discover/detail/doc/doc.mjs +9 -1
- package/api/docs/_adapter.d.mts +63 -0
- package/api/docs/_adapter.mjs +309 -16
- package/api/docs/integration-tree.test.mjs +22 -0
- package/api/docs/list/list.mjs +12 -2
- package/api/integration/_adapter.d.mts +23 -0
- package/api/integration/_adapter.mjs +45 -0
- package/api/integration/authoring-checks.mjs +87 -3
- package/api/integration/authoring-checks.test.mjs +443 -0
- package/api/integration/authoring-checks.type.d.mts +84 -0
- package/api/integration/authoring-checks.type.mjs +40 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +3 -1
- package/api/integration/integrationDocConflicts.doc.mjs +7 -2
- package/api/integration/pack-check.mjs +4 -0
- package/api/integration/pack-check.test.mjs +26 -0
- package/api/integration/validate-integration-fixes.test.mjs +67 -0
- package/api/integration/validate-integration.mjs +28 -3
- package/api/integration/validate-integration.test.mjs +77 -8
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/search.mjs +2 -1
- package/assets/docs/browser-support.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
- package/assets/docs/tree/check-the-props.doc.mjs +5 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +10 -2
- package/assets/docs/tree/checks.doc.mjs +4 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -7
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/publishing.doc.mjs +2 -2
- package/assets/docs/tree/sections-and-placement.doc.mjs +2 -2
- package/authoring/doctypes/component/type.ts +8 -0
- package/authoring/doctypes/hook/type.ts +4 -0
- package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -2
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +3 -1
- package/clients/cli/commands/doctor-integration.test.mjs +48 -1
- package/clients/cli/commands/doctor.mjs +60 -5
- package/clients/cli/commands/integration-authoring.test.mjs +46 -0
- package/clients/cli/commands/integration-check.test.mjs +79 -0
- package/clients/cli/commands/integration.mjs +10 -4
- package/foundation/discovery/copied-passages.d.mts +8 -0
- package/foundation/discovery/copied-passages.mjs +2 -2
- package/foundation/discovery/doc-consistency.d.mts +34 -0
- package/foundation/discovery/doc-consistency.mjs +513 -0
- package/foundation/discovery/doc-consistency.test.mjs +347 -0
- package/foundation/discovery/doc-fluff.d.mts +112 -0
- package/foundation/discovery/doc-fluff.mjs +328 -0
- package/foundation/discovery/doc-fluff.test.mjs +142 -0
- package/foundation/discovery/doc-types.mjs +12 -5
- package/foundation/discovery/doc-types.test.mjs +46 -2
- package/foundation/discovery/prop-drift.d.mts +25 -6
- package/foundation/discovery/prop-drift.mjs +171 -6
- package/foundation/discovery/prop-drift.test.mjs +65 -0
- package/foundation/discovery/stray-pointers.d.mts +52 -0
- package/foundation/discovery/stray-pointers.mjs +293 -0
- package/foundation/discovery/stray-pointers.test.mjs +86 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +12 -0
- package/foundation/doc-compiler/links.d.mts +32 -0
- package/foundation/doc-compiler/links.mjs +163 -26
- package/foundation/doc-compiler/links.test.mjs +97 -4
- package/foundation/doc-compiler/tree.mjs +30 -1
- package/foundation/doc-compiler/tree.test.mjs +7 -0
- package/foundation/integrations/contribution-inventory.d.mts +11 -0
- package/foundation/integrations/contribution-inventory.mjs +50 -2
- package/foundation/integrations/issue.ts +6 -0
- package/foundation/integrations/validate-contributions.mjs +30 -1
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +9 -9
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fluff in docs: padding phrases that add words and no meaning, and guides
|
|
5
|
+
* whose prose is mostly function words. Docs are read by people and agents
|
|
6
|
+
* with a budget, so every word should carry something.
|
|
7
|
+
*
|
|
8
|
+
* Only prose is read (the same strings copied passages compare), and inline
|
|
9
|
+
* code and quoted text are set aside, so a phrase inside a command, or one
|
|
10
|
+
* quoted as an example, never counts.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
|
|
15
|
+
import {builtinGuideFiles} from './docs-discovery.mjs';
|
|
16
|
+
import {
|
|
17
|
+
contentWords,
|
|
18
|
+
fileWords,
|
|
19
|
+
lineAtOffset,
|
|
20
|
+
locateWords,
|
|
21
|
+
loadQuietly,
|
|
22
|
+
proseStrings,
|
|
23
|
+
passageWords,
|
|
24
|
+
textWords,
|
|
25
|
+
} from './copied-passages.mjs';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Padding phrases: each can be cut, or replaced by a shorter word, without
|
|
29
|
+
* losing meaning. Only phrases that are padding in every use are listed;
|
|
30
|
+
* words such as "just", "simply" or "really", and phrases such as "whether or
|
|
31
|
+
* not" or "keep in mind", which carry meaning in a correct sentence ("not
|
|
32
|
+
* simply a wrapper", "regardless of whether"), are not.
|
|
33
|
+
*/
|
|
34
|
+
export const FILLER_PHRASES = [
|
|
35
|
+
"it's important to note",
|
|
36
|
+
'it is important to note',
|
|
37
|
+
'important to note that',
|
|
38
|
+
"it's worth noting",
|
|
39
|
+
'it is worth noting',
|
|
40
|
+
'worth noting that',
|
|
41
|
+
'it should be noted',
|
|
42
|
+
'please note',
|
|
43
|
+
'note that',
|
|
44
|
+
'as mentioned above',
|
|
45
|
+
'as mentioned earlier',
|
|
46
|
+
'as mentioned before',
|
|
47
|
+
'as noted above',
|
|
48
|
+
'as you can see',
|
|
49
|
+
'needless to say',
|
|
50
|
+
'in order to',
|
|
51
|
+
'due to the fact that',
|
|
52
|
+
'for the purpose of',
|
|
53
|
+
'at this point in time',
|
|
54
|
+
'in other words',
|
|
55
|
+
'basically',
|
|
56
|
+
'essentially',
|
|
57
|
+
'obviously',
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
/** What to write instead, where a phrase is not simply cut. */
|
|
61
|
+
const INSTEAD = {
|
|
62
|
+
'in order to': 'to',
|
|
63
|
+
'due to the fact that': 'because',
|
|
64
|
+
'for the purpose of': 'to or for',
|
|
65
|
+
'at this point in time': 'now',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** A guide shorter than this many prose words is not scored for density. */
|
|
69
|
+
export const DENSITY_MIN_WORDS = 80;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A guide whose share of content words is below this is mostly glue. Core's
|
|
73
|
+
* own guides score from about 0.51 up, with a median near 0.62.
|
|
74
|
+
*/
|
|
75
|
+
export const MIN_DENSITY = 0.5;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} phrase
|
|
79
|
+
* @returns {RegExp}
|
|
80
|
+
*/
|
|
81
|
+
function phrasePattern(phrase) {
|
|
82
|
+
const escaped = phrase.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
83
|
+
// "note that" is padding as a sentence opener ("Note that X"), not inside
|
|
84
|
+
// one ("a note that explains").
|
|
85
|
+
return phrase === 'note that'
|
|
86
|
+
? new RegExp(`(?:^|[.;:!?]\\s+)${escaped}\\b`, 'gi')
|
|
87
|
+
: // A hyphen joins words ("non-obviously"), so it bounds no phrase.
|
|
88
|
+
new RegExp(`(?<![a-z'-])${escaped}(?![a-z-])`, 'gi');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const PATTERNS = FILLER_PHRASES.map(phrase => ({
|
|
92
|
+
phrase,
|
|
93
|
+
pattern: phrasePattern(phrase),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A prose string with what is not prose blanked out, length kept: `{@link}`
|
|
98
|
+
* pointers, inline code, and quoted text. A quoted phrase is mentioned, not
|
|
99
|
+
* used ("cut 'in order to'").
|
|
100
|
+
*
|
|
101
|
+
* @param {string} text
|
|
102
|
+
* @returns {string}
|
|
103
|
+
*/
|
|
104
|
+
export function maskProse(text) {
|
|
105
|
+
// A quoted phrase is mentioned, not used ("cut 'in order to'"), so quotes
|
|
106
|
+
// are set aside along with inline code. Each mask keeps the text's length,
|
|
107
|
+
// so an offset in the masked text is an offset in the text.
|
|
108
|
+
const blank = (/** @type {string} */ span) => ' '.repeat(span.length);
|
|
109
|
+
return (
|
|
110
|
+
text
|
|
111
|
+
// A pointer names a doc, and its target is no prose ("{@link
|
|
112
|
+
// generic:obviously-fast}").
|
|
113
|
+
.replace(/\{@link\s[^}]*\}/g, blank)
|
|
114
|
+
.replace(/`[^`]*`/g, blank)
|
|
115
|
+
.replace(/"[^"]*"|“[^”]*”|‘[^’]*’/g, blank)
|
|
116
|
+
.replace(/’/g, "'")
|
|
117
|
+
// A single-quoted span opens and closes beside a non-letter, so the
|
|
118
|
+
// apostrophe in "don't" or "it's" opens nothing.
|
|
119
|
+
.replace(/(?<![A-Za-z])'[^']*'(?![A-Za-z])/g, blank)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Each padding phrase in a text, outside inline code and quotes, in order,
|
|
125
|
+
* with its offset in the text.
|
|
126
|
+
*
|
|
127
|
+
* `thatAfter` is true when the phrase is followed by a "that" a reader cuts
|
|
128
|
+
* with it ("It is worth noting that the cache is shared").
|
|
129
|
+
*
|
|
130
|
+
* @param {string} text
|
|
131
|
+
* @returns {{phrase: string, at: number, thatAfter: boolean}[]}
|
|
132
|
+
*/
|
|
133
|
+
export function fillerAt(text) {
|
|
134
|
+
const prose = maskProse(text);
|
|
135
|
+
/** @type {{phrase: string, at: number, thatAfter: boolean}[]} */
|
|
136
|
+
const found = [];
|
|
137
|
+
for (const {phrase, pattern} of PATTERNS) {
|
|
138
|
+
for (const match of prose.matchAll(pattern)) {
|
|
139
|
+
// A phrase inside a longer listed one ("note that" in "worth noting
|
|
140
|
+
// that") is the longer one's.
|
|
141
|
+
const at = match.index + match[0].toLowerCase().indexOf(phrase);
|
|
142
|
+
if (
|
|
143
|
+
!found.some(each => at >= each.at && at < each.at + each.phrase.length)
|
|
144
|
+
) {
|
|
145
|
+
found.push({
|
|
146
|
+
phrase,
|
|
147
|
+
at,
|
|
148
|
+
// Only a phrase that ends in note or noting leads into a "that"
|
|
149
|
+
// clause the reader cuts with it; "Obviously that works" and "As
|
|
150
|
+
// noted above that flag" keep their "that".
|
|
151
|
+
thatAfter:
|
|
152
|
+
/\bnot(?:e|ed|ing)$/.test(phrase) &&
|
|
153
|
+
!phrase.endsWith('that') &&
|
|
154
|
+
/^\s+that\b/i.test(prose.slice(at + phrase.length)),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return found.sort((a, b) => a.at - b.at);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Each padding phrase in a text, outside inline code and quotes, in order.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} text
|
|
166
|
+
* @returns {string[]}
|
|
167
|
+
*/
|
|
168
|
+
export function fillerIn(text) {
|
|
169
|
+
return fillerAt(text).map(each => each.phrase);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The share of a doc's prose words that are content words.
|
|
174
|
+
*
|
|
175
|
+
* @param {{word: string}[]} words
|
|
176
|
+
* @returns {number}
|
|
177
|
+
*/
|
|
178
|
+
export function density(words) {
|
|
179
|
+
if (words.length === 0) return 1;
|
|
180
|
+
let content = 0;
|
|
181
|
+
for (let i = 0; i < words.length; i++) {
|
|
182
|
+
if (contentWords(words, i, 1) === 1) content++;
|
|
183
|
+
}
|
|
184
|
+
return content / words.length;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* A number rounded down to `places` decimals, so a share under the floor
|
|
189
|
+
* never reads as the floor.
|
|
190
|
+
*
|
|
191
|
+
* @param {number} value
|
|
192
|
+
* @param {number} places
|
|
193
|
+
* @returns {number}
|
|
194
|
+
*/
|
|
195
|
+
export function floorTo(value, places) {
|
|
196
|
+
const scale = 10 ** places;
|
|
197
|
+
return Math.floor(value * scale + 1e-9) / scale;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* A share as a percent with one decimal, rounded down ("49.5%").
|
|
202
|
+
*
|
|
203
|
+
* @param {number} share
|
|
204
|
+
* @returns {string}
|
|
205
|
+
*/
|
|
206
|
+
export function sharePercent(share) {
|
|
207
|
+
return `${floorTo(share * 100, 1).toFixed(1)}%`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The words a topic's density is measured on: its prose, without what the
|
|
212
|
+
* phrase check also leaves unread (links, inline code, quoted text).
|
|
213
|
+
*
|
|
214
|
+
* @param {unknown} doc
|
|
215
|
+
* @returns {{word: string}[]}
|
|
216
|
+
*/
|
|
217
|
+
export function densityWords(doc) {
|
|
218
|
+
return proseStrings(doc).flatMap(({text}) =>
|
|
219
|
+
passageWords(maskProse(text)).map(word => ({word})),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The median density of Core's own guides of at least
|
|
225
|
+
* {@link DENSITY_MIN_WORDS} words.
|
|
226
|
+
*
|
|
227
|
+
* @returns {Promise<number>}
|
|
228
|
+
*/
|
|
229
|
+
export async function coreDensityMedian() {
|
|
230
|
+
// Core's guides are measured the way a package's topics are.
|
|
231
|
+
/** @type {number[]} */
|
|
232
|
+
const scores = [];
|
|
233
|
+
for (const file of builtinGuideFiles()) {
|
|
234
|
+
const doc = await loadQuietly(file);
|
|
235
|
+
if (typeof doc?.name !== 'string') continue;
|
|
236
|
+
const words = densityWords(doc);
|
|
237
|
+
if (words.length >= DENSITY_MIN_WORDS) scores.push(density(words));
|
|
238
|
+
}
|
|
239
|
+
scores.sort((a, b) => a - b);
|
|
240
|
+
return scores.length === 0 ? 0 : scores[Math.floor(scores.length / 2)];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Fluff in a package's topics: every padding phrase, with its section and
|
|
245
|
+
* file line, and every topic of at least {@link DENSITY_MIN_WORDS} words
|
|
246
|
+
* whose density is below {@link MIN_DENSITY}.
|
|
247
|
+
*
|
|
248
|
+
* @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[]}} discovered
|
|
249
|
+
* the package's docs, as discoverIntegrationDocs returns them
|
|
250
|
+
* @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').DocFluff[]>}
|
|
251
|
+
*/
|
|
252
|
+
export async function findFluff(discovered) {
|
|
253
|
+
const topics = [
|
|
254
|
+
...discovered.records.map(record => ({
|
|
255
|
+
name: record.name,
|
|
256
|
+
file: record.path,
|
|
257
|
+
})),
|
|
258
|
+
...(discovered.guides ?? []).map(guide => ({
|
|
259
|
+
name: guide.name,
|
|
260
|
+
file: guide.ref?.topicFile,
|
|
261
|
+
})),
|
|
262
|
+
];
|
|
263
|
+
/** @type {import('../../api/integration/authoring-checks.type.mjs').DocFluff[]} */
|
|
264
|
+
const found = [];
|
|
265
|
+
/** @type {number | null} */
|
|
266
|
+
let median = null;
|
|
267
|
+
for (const {name, file} of topics) {
|
|
268
|
+
const doc = file ? await loadQuietly(file) : null;
|
|
269
|
+
if (!doc || !file) continue;
|
|
270
|
+
/** @type {{word: string, line: number}[]} */
|
|
271
|
+
let source = [];
|
|
272
|
+
try {
|
|
273
|
+
source = fileWords(fs.readFileSync(file, 'utf8'));
|
|
274
|
+
} catch {
|
|
275
|
+
// No line numbers; each finding still names its section.
|
|
276
|
+
}
|
|
277
|
+
// Each string is found by its whole run of words, from where the last
|
|
278
|
+
// one was found, so two strings that open alike keep their own lines.
|
|
279
|
+
let cursor = 0;
|
|
280
|
+
for (const {text, section} of proseStrings(doc)) {
|
|
281
|
+
const words = textWords(text);
|
|
282
|
+
let index = locateWords(source, words, cursor);
|
|
283
|
+
if (index < 0) index = locateWords(source, words);
|
|
284
|
+
if (index >= 0) cursor = index + words.length;
|
|
285
|
+
for (const {phrase, at, thatAfter} of fillerAt(text)) {
|
|
286
|
+
const line = index < 0 ? null : lineAtOffset(source, index, words, at);
|
|
287
|
+
const where = section ? ` (section "${section}")` : '';
|
|
288
|
+
const instead = /** @type {Record<string, string>} */ (INSTEAD)[phrase];
|
|
289
|
+
found.push({
|
|
290
|
+
topic: name,
|
|
291
|
+
kind: 'phrase',
|
|
292
|
+
phrase,
|
|
293
|
+
section,
|
|
294
|
+
file,
|
|
295
|
+
line,
|
|
296
|
+
density: null,
|
|
297
|
+
message:
|
|
298
|
+
`"${name}"${where} pads its prose with "${phrase}"` +
|
|
299
|
+
`${line == null ? '' : ` (line ${line})`}. ` +
|
|
300
|
+
(instead
|
|
301
|
+
? `Write "${instead}" instead.`
|
|
302
|
+
: thatAfter
|
|
303
|
+
? 'Cut it and the "that" after it; the sentence says the same without them.'
|
|
304
|
+
: 'Cut it; the sentence says the same without it.'),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const words = densityWords(doc);
|
|
309
|
+
if (words.length < DENSITY_MIN_WORDS) continue;
|
|
310
|
+
const score = density(words);
|
|
311
|
+
if (score >= MIN_DENSITY) continue;
|
|
312
|
+
median ??= await coreDensityMedian();
|
|
313
|
+
found.push({
|
|
314
|
+
topic: name,
|
|
315
|
+
kind: 'density',
|
|
316
|
+
phrase: null,
|
|
317
|
+
section: null,
|
|
318
|
+
file,
|
|
319
|
+
line: null,
|
|
320
|
+
density: floorTo(score, 3),
|
|
321
|
+
message:
|
|
322
|
+
`"${name}" is mostly glue: ${sharePercent(score)} of its ${words.length} prose words carry content, ` +
|
|
323
|
+
`under the ${Math.round(MIN_DENSITY * 100)}% floor (Core's guides have a median of ${Math.round(median * 100)}%). ` +
|
|
324
|
+
'Cut filler and restated context until each sentence states one thing.',
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return found;
|
|
328
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
density,
|
|
7
|
+
densityWords,
|
|
8
|
+
fillerAt,
|
|
9
|
+
fillerIn,
|
|
10
|
+
floorTo,
|
|
11
|
+
sharePercent,
|
|
12
|
+
} from './doc-fluff.mjs';
|
|
13
|
+
import {passageWords} from './copied-passages.mjs';
|
|
14
|
+
|
|
15
|
+
const words = (/** @type {string} */ text) =>
|
|
16
|
+
passageWords(text).map(word => ({word}));
|
|
17
|
+
|
|
18
|
+
describe('fillerIn', () => {
|
|
19
|
+
it('finds padding phrases in order, the longest one only', () => {
|
|
20
|
+
expect(
|
|
21
|
+
fillerIn(
|
|
22
|
+
'In order to start, it is worth noting that you basically run it. Note that it builds.',
|
|
23
|
+
),
|
|
24
|
+
).toEqual(['in order to', 'it is worth noting', 'basically', 'note that']);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('leaves inline code, quotes, a noun "note", and ambiguous words alone', () => {
|
|
28
|
+
expect(
|
|
29
|
+
fillerIn(
|
|
30
|
+
'Run `basically --in order to`. Cut "in order to" and “basically”. Add a note that explains it. Copy just this one file; it really is the source.',
|
|
31
|
+
),
|
|
32
|
+
).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('sets aside single-quoted text, but not an apostrophe', () => {
|
|
36
|
+
expect(
|
|
37
|
+
fillerIn(
|
|
38
|
+
"Avoid ‘basically’ and ‘obviously’. Don't write 'it is worth noting that' in a guide.",
|
|
39
|
+
),
|
|
40
|
+
).toEqual([]);
|
|
41
|
+
expect(fillerIn("Don't pad: it's important to note the order.")).toEqual([
|
|
42
|
+
"it's important to note",
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('lists no phrase that carries meaning in a correct sentence', () => {
|
|
47
|
+
expect(
|
|
48
|
+
fillerIn(
|
|
49
|
+
'It is not simply a wrapper. Every app gets a theme whether or not anyone picks one. Keep in mind the order. Feel free to skip it.',
|
|
50
|
+
),
|
|
51
|
+
).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('reads a curly apostrophe like a straight one', () => {
|
|
55
|
+
expect(fillerIn('It’s important to note the order.')).toEqual([
|
|
56
|
+
"it's important to note",
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('fillerAt', () => {
|
|
62
|
+
it('reads no phrase inside a link target or a hyphenated word', () => {
|
|
63
|
+
expect(
|
|
64
|
+
fillerIn(
|
|
65
|
+
'Read {@link generic:obviously-fast} before you tune the build.',
|
|
66
|
+
),
|
|
67
|
+
).toEqual([]);
|
|
68
|
+
expect(fillerIn('A non-obviously slow build still passes.')).toEqual([]);
|
|
69
|
+
expect(fillerIn('It is obviously slow.')).toEqual(['obviously']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('marks a "that" the reader cuts with the phrase', () => {
|
|
73
|
+
expect(
|
|
74
|
+
fillerAt('It is worth noting that the cache is shared.').map(
|
|
75
|
+
each => each.thatAfter,
|
|
76
|
+
),
|
|
77
|
+
).toEqual([true]);
|
|
78
|
+
expect(
|
|
79
|
+
fillerAt('Basically, the cache is shared.').map(each => each.thatAfter),
|
|
80
|
+
).toEqual([false]);
|
|
81
|
+
// Only a note or noting phrase leads a clause the reader cuts.
|
|
82
|
+
expect(
|
|
83
|
+
fillerAt('Obviously that works only in a browser.').map(
|
|
84
|
+
each => each.thatAfter,
|
|
85
|
+
),
|
|
86
|
+
).toEqual([false]);
|
|
87
|
+
expect(
|
|
88
|
+
fillerAt('As noted above that flag is required.').map(
|
|
89
|
+
each => each.thatAfter,
|
|
90
|
+
),
|
|
91
|
+
).toEqual([false]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('densityWords', () => {
|
|
96
|
+
it('measures prose only, not quoted text, inline code or links', () => {
|
|
97
|
+
const doc = {
|
|
98
|
+
sections: [
|
|
99
|
+
{
|
|
100
|
+
title: 'Overview',
|
|
101
|
+
content: [
|
|
102
|
+
{
|
|
103
|
+
type: 'prose',
|
|
104
|
+
text: 'Theme tokens set colors. Write "it is in the" or `of the` as {@link generic:theme} shows.',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
expect(densityWords(doc).map(each => each.word)).toEqual([
|
|
111
|
+
'theme',
|
|
112
|
+
'tokens',
|
|
113
|
+
'set',
|
|
114
|
+
'colors.',
|
|
115
|
+
'write',
|
|
116
|
+
'or',
|
|
117
|
+
'as',
|
|
118
|
+
'shows.',
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('share rounding', () => {
|
|
124
|
+
it('rounds a share under the floor down, never up to it', () => {
|
|
125
|
+
expect(floorTo(0.4995, 3)).toBe(0.499);
|
|
126
|
+
expect(sharePercent(0.4995)).toBe('49.9%');
|
|
127
|
+
expect(sharePercent(0.5)).toBe('50.0%');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('density', () => {
|
|
132
|
+
it('scores a padded sentence well below a dense one', () => {
|
|
133
|
+
const padded = words(
|
|
134
|
+
'So that is why it is the one that you would want to use if you can.',
|
|
135
|
+
);
|
|
136
|
+
const dense = words(
|
|
137
|
+
'Name each codemod folder after the Core version whose upgrade runs it.',
|
|
138
|
+
);
|
|
139
|
+
expect(density(padded)).toBeLessThan(0.3);
|
|
140
|
+
expect(density(dense)).toBeGreaterThan(0.6);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -827,16 +827,23 @@ function findingsFor(ts, diagnostic, astPath, where) {
|
|
|
827
827
|
named != null && /^[A-Za-z_$][\w$]*$/.test(named)
|
|
828
828
|
? named
|
|
829
829
|
: where.typeName;
|
|
830
|
+
// One diagnostic can list several missing fields; each finding's message
|
|
831
|
+
// names only its own field, so two findings never share one message.
|
|
832
|
+
const source = /^Type '(.*)' is missing the following properties/.exec(
|
|
833
|
+
leaf,
|
|
834
|
+
)?.[1];
|
|
830
835
|
return missing.map(name => {
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
836
|
+
const key = unquote(/** @type {string} */ (name));
|
|
837
|
+
const field = formatPath([...parts, key]);
|
|
838
|
+
const message =
|
|
839
|
+
missing.length > 1
|
|
840
|
+
? `Property '${key}' is missing${source == null ? '' : ` in type '${source}'`} but required in type '${ownerType}'.`
|
|
841
|
+
: leaf;
|
|
835
842
|
return {
|
|
836
843
|
...base,
|
|
837
844
|
field,
|
|
838
845
|
problem: /** @type {const} */ ('missing_field'),
|
|
839
|
-
message: shorten(
|
|
846
|
+
message: shorten(message),
|
|
840
847
|
fix: `Add \`${field}\`: ${shorten(ownerType)} requires it.`,
|
|
841
848
|
};
|
|
842
849
|
});
|
|
@@ -565,7 +565,7 @@ describe('checkDocTypes', () => {
|
|
|
565
565
|
'components/Badge.doc.mjs',
|
|
566
566
|
[
|
|
567
567
|
`export default ${JSON.stringify(COMPONENT)};`,
|
|
568
|
-
"export const docsDense = {name: 'Badge', description: 'count chip'};",
|
|
568
|
+
"export const docsDense = {name: 'Badge', displayName: 'Badge', summary: 'chip', description: 'count chip'};",
|
|
569
569
|
`export const docsZh = ${JSON.stringify({...COMPONENT, displayName: undefined, keyword: []})};`,
|
|
570
570
|
'',
|
|
571
571
|
].join('\n'),
|
|
@@ -575,12 +575,56 @@ describe('checkDocTypes', () => {
|
|
|
575
575
|
|
|
576
576
|
expect(report.docs).toBe(3);
|
|
577
577
|
expect(summary(report)).toEqual([
|
|
578
|
-
'components/Badge.doc.mjs docsDense
|
|
578
|
+
'components/Badge.doc.mjs docsDense summary unknown_field',
|
|
579
579
|
'components/Badge.doc.mjs docsZh keyword unknown_field',
|
|
580
580
|
]);
|
|
581
581
|
expect(report.findings[0].type).toBe('ComponentTranslationDoc');
|
|
582
582
|
});
|
|
583
583
|
|
|
584
|
+
it('allows a translation overlay to name its component, as Core overlays do', async () => {
|
|
585
|
+
withTypeScript();
|
|
586
|
+
write(
|
|
587
|
+
'components/Badge.doc.mjs',
|
|
588
|
+
[
|
|
589
|
+
`export default ${JSON.stringify(COMPONENT)};`,
|
|
590
|
+
"export const docsZh = {name: 'Badge', displayName: '徽章', description: '计数'};",
|
|
591
|
+
"export const docsDense = {name: 'Badge', displayName: 'Badge', description: 'count chip'};",
|
|
592
|
+
'',
|
|
593
|
+
].join('\n'),
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
const report = await check([['components/Badge.doc.mjs', 'components']]);
|
|
597
|
+
|
|
598
|
+
expect(summary(report)).toEqual([]);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it('gives each field TypeScript reports missing together a message naming only that field', async () => {
|
|
602
|
+
withTypeScript();
|
|
603
|
+
write(
|
|
604
|
+
'components/Badge.doc.mjs',
|
|
605
|
+
[
|
|
606
|
+
'export default {',
|
|
607
|
+
" type: 'component',",
|
|
608
|
+
" name: 'Badge',",
|
|
609
|
+
" props: [{name: 'label', type: 'string', description: 'Text.'}],",
|
|
610
|
+
'};',
|
|
611
|
+
'',
|
|
612
|
+
].join('\n'),
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
const report = await check([['components/Badge.doc.mjs', 'components']]);
|
|
616
|
+
const missing = report.findings.filter(f => f.problem === 'missing_field');
|
|
617
|
+
|
|
618
|
+
expect(missing.length).toBeGreaterThan(1);
|
|
619
|
+
expect(new Set(missing.map(f => f.message)).size).toBe(missing.length);
|
|
620
|
+
for (const finding of missing) {
|
|
621
|
+
const others = missing.filter(f => f !== finding).map(f => f.field);
|
|
622
|
+
expect(finding.message).toContain(`'${finding.field}'`);
|
|
623
|
+
for (const other of others)
|
|
624
|
+
expect(finding.message).not.toContain(`'${other}'`);
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
|
|
584
628
|
it('checks a template, a docs topic by its stamp, a topic overlay, and a theme', async () => {
|
|
585
629
|
withTypeScript();
|
|
586
630
|
write(
|
|
@@ -25,7 +25,7 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
|
|
|
25
25
|
loadDoc?: (docPath: string) => Promise<any>;
|
|
26
26
|
}): Promise<PropDriftReport>;
|
|
27
27
|
/**
|
|
28
|
-
* @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch' | 'type_mismatch'} PropDriftKind
|
|
28
|
+
* @typedef {'not_in_code' | 'not_in_doc' | 'required_mismatch' | 'type_mismatch' | 'default_mismatch'} PropDriftKind
|
|
29
29
|
*/
|
|
30
30
|
/**
|
|
31
31
|
* @typedef {object} PropDriftFinding
|
|
@@ -40,6 +40,9 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
|
|
|
40
40
|
* @property {string} [codeType] the type as the source declares it
|
|
41
41
|
* @property {boolean} [docRequired]
|
|
42
42
|
* @property {boolean} [codeRequired]
|
|
43
|
+
* @property {string} [docDefault] the documented default, as written
|
|
44
|
+
* @property {string} [codeDefault] the literal default the code writes
|
|
45
|
+
* @property {string} [fix] what to change, ready to paste
|
|
43
46
|
*/
|
|
44
47
|
/**
|
|
45
48
|
* @typedef {object} PropDriftUnchecked
|
|
@@ -53,8 +56,10 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
|
|
|
53
56
|
* @property {string} doc the doc file, relative to the package root
|
|
54
57
|
* @property {string} reason why: not a form the check judges exactly, a
|
|
55
58
|
* field the prop's variants give different types, a standard prop
|
|
56
|
-
* (`className`, `style`, …),
|
|
57
|
-
*
|
|
59
|
+
* (`className`, `style`, …), a prop declared outside the package, or a
|
|
60
|
+
* default that is not a literal on one side
|
|
61
|
+
* @property {string[]} props documented props whose types, or defaults, were
|
|
62
|
+
* not compared
|
|
58
63
|
*/
|
|
59
64
|
/**
|
|
60
65
|
* @typedef {object} PropDriftReport
|
|
@@ -146,7 +151,7 @@ export type CodeProp = {
|
|
|
146
151
|
*/
|
|
147
152
|
location: any;
|
|
148
153
|
};
|
|
149
|
-
export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch" | "type_mismatch";
|
|
154
|
+
export type PropDriftKind = "not_in_code" | "not_in_doc" | "required_mismatch" | "type_mismatch" | "default_mismatch";
|
|
150
155
|
export type PropDriftFinding = {
|
|
151
156
|
/**
|
|
152
157
|
* the documented component (export) name
|
|
@@ -174,6 +179,18 @@ export type PropDriftFinding = {
|
|
|
174
179
|
codeType?: string | undefined;
|
|
175
180
|
docRequired?: boolean | undefined;
|
|
176
181
|
codeRequired?: boolean | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* the documented default, as written
|
|
184
|
+
*/
|
|
185
|
+
docDefault?: string | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* the literal default the code writes
|
|
188
|
+
*/
|
|
189
|
+
codeDefault?: string | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* what to change, ready to paste
|
|
192
|
+
*/
|
|
193
|
+
fix?: string | undefined;
|
|
177
194
|
};
|
|
178
195
|
export type PropDriftUnchecked = {
|
|
179
196
|
component: string;
|
|
@@ -195,11 +212,13 @@ export type PropDriftTypesNotCompared = {
|
|
|
195
212
|
/**
|
|
196
213
|
* why: not a form the check judges exactly, a
|
|
197
214
|
* field the prop's variants give different types, a standard prop
|
|
198
|
-
* (`className`, `style`, …),
|
|
215
|
+
* (`className`, `style`, …), a prop declared outside the package, or a
|
|
216
|
+
* default that is not a literal on one side
|
|
199
217
|
*/
|
|
200
218
|
reason: string;
|
|
201
219
|
/**
|
|
202
|
-
* documented props whose types
|
|
220
|
+
* documented props whose types, or defaults, were
|
|
221
|
+
* not compared
|
|
203
222
|
*/
|
|
204
223
|
props: string[];
|
|
205
224
|
};
|