Skip to content

Commit 9904ecb

Browse files
committed
feat(linter): create llm description rule
1 parent 1bf3748 commit 9904ecb

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/linter/constants.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export const LINT_MESSAGES = {
55
missingChangeVersion: 'Missing version field in the API doc entry',
66
invalidChangeVersion: 'Invalid version number: {{version}}',
77
duplicateStabilityNode: 'Duplicate stability node',
8+
missingLlmDescription:
9+
'Missing llm_description field or paragraph node in the API doc entry',
810
};

src/linter/rules/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { duplicateStabilityNodes } from './duplicate-stability-nodes.mjs';
44
import { invalidChangeVersion } from './invalid-change-version.mjs';
55
import { missingIntroducedIn } from './missing-introduced-in.mjs';
6+
import { missingLlmDescription } from './missing-llm-description.mjs';
67

78
/**
89
* @type {Record<string, import('../types').LintRule>}
@@ -11,4 +12,5 @@ export default {
1112
'duplicate-stability-nodes': duplicateStabilityNodes,
1213
'invalid-change-version': invalidChangeVersion,
1314
'missing-introduced-in': missingIntroducedIn,
15+
'missing-llm-description': missingLlmDescription,
1416
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { LINT_MESSAGES } from '../constants.mjs';
2+
3+
/**
4+
* Checks if a top-level entry is missing a llm_description field or a paragraph
5+
* node.
6+
*
7+
* @param {ApiDocMetadataEntry[]} entries
8+
* @returns {Array<import('../types.d.ts').LintIssue>}
9+
*/
10+
export const missingLlmDescription = entries => {
11+
const issues = [];
12+
13+
for (const entry of entries) {
14+
if (entry.heading.depth !== 1 || entry.llm_description) {
15+
continue;
16+
}
17+
18+
const descriptionNode = entry.content.children.find(
19+
child => child.type === 'paragraph'
20+
);
21+
22+
if (!descriptionNode) {
23+
issues.push({
24+
level: 'warn',
25+
message: LINT_MESSAGES.missingLlmDescription,
26+
location: {
27+
path: entry.api_doc_source,
28+
},
29+
});
30+
}
31+
}
32+
33+
return issues;
34+
};

0 commit comments

Comments
 (0)