Skip to content

Commit ee63084

Browse files
committed
refactor(linter): remove for-of loop
1 parent 9904ecb commit ee63084

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/linter/rules/missing-llm-description.mjs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,40 @@ import { LINT_MESSAGES } from '../constants.mjs';
88
* @returns {Array<import('../types.d.ts').LintIssue>}
99
*/
1010
export const missingLlmDescription = entries => {
11-
const issues = [];
11+
return entries
12+
.filter(entry => {
13+
// Only process top-level headings
14+
if (entry.heading.depth !== 1) {
15+
return false;
16+
}
1217

13-
for (const entry of entries) {
14-
if (entry.heading.depth !== 1 || entry.llm_description) {
15-
continue;
16-
}
18+
// Skip entries that have an llm_description property
19+
if (entry.llm_description !== undefined) {
20+
return false;
21+
}
1722

18-
const descriptionNode = entry.content.children.find(
19-
child => child.type === 'paragraph'
20-
);
23+
const hasParagraph = entry.content.children.some(
24+
node => node.type === 'paragraph'
25+
);
2126

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-
}
27+
// Skip entries that contain a paragraph that can be used as a fallback.
28+
if (hasParagraph) {
29+
return false;
30+
}
3231

33-
return issues;
32+
return true;
33+
})
34+
.map(entry => mapToMissingEntryWarning(entry));
3435
};
36+
37+
/**
38+
* Maps a entry to a warning for missing llm description.
39+
*
40+
* @param {ApiDocMetadataEntry} entry
41+
* @returns {import('../types.d.ts').LintIssue}
42+
*/
43+
const mapToMissingEntryWarning = entry => ({
44+
level: 'warn',
45+
message: LINT_MESSAGES.missingLlmDescription,
46+
location: { path: entry.api_doc_source },
47+
});

0 commit comments

Comments
 (0)