forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing-llm-description.mjs
More file actions
47 lines (41 loc) · 1.2 KB
/
missing-llm-description.mjs
File metadata and controls
47 lines (41 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { LINT_MESSAGES } from '../constants.mjs';
/**
* Checks if a top-level entry is missing a llm_description field or a paragraph
* node.
*
* @param {ApiDocMetadataEntry[]} entries
* @returns {Array<import('../types.d.ts').LintIssue>}
*/
export const missingLlmDescription = entries => {
return entries
.filter(entry => {
// Only process top-level headings
if (entry.heading.depth !== 1) {
return false;
}
// Skip entries that have an llm_description property
if (entry.llm_description !== undefined) {
return false;
}
const hasParagraph = entry.content.children.some(
node => node.type === 'paragraph'
);
// Skip entries that contain a paragraph that can be used as a fallback.
if (hasParagraph) {
return false;
}
return true;
})
.map(entry => mapToMissingEntryWarning(entry));
};
/**
* Maps a entry to a warning for missing llm description.
*
* @param {ApiDocMetadataEntry} entry
* @returns {import('../types.d.ts').LintIssue}
*/
const mapToMissingEntryWarning = entry => ({
level: 'warn',
message: LINT_MESSAGES.missingLlmDescription,
location: { path: entry.api_doc_source },
});