Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(doclint): support lists in comments #1492

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions utils/doclint/check_public_api/MDBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class MDOutline {
const writer = new commonmark.HtmlRenderer();
const html = writer.render(parsed);

page.on('console', msg => {
console.log(msg.text());
});
const logConsole = msg => console.log(msg.text());
page.on('console', logConsole);
// Extract headings.
await page.setContent(html);
const {classes, errors} = await page.evaluate(() => {
Expand All @@ -56,9 +55,11 @@ class MDOutline {
const name = str.substring(0, str.indexOf('<')).replace(/\`/g, '').trim();
const type = findType(str);
const properties = [];
const comment = str.substring(str.indexOf('<') + type.length + 2).trim();
let comment = str.substring(str.indexOf('<') + type.length + 2).trim();
const hasNonEnumProperties = type.split('|').some(part => {
return part !== 'string' && part !== 'number' && part !== 'Array<string>' && !(part[0] === '"' && part[part.length - 1] === '"');
const basicTypes = new Set(['string', 'number', 'boolean']);
const arrayTypes = new Set([...basicTypes].map(type => `Array<${type}>`));
return !basicTypes.has(part) && !arrayTypes.has(part) && !(part.startsWith('"') && part.endsWith('"'));
});
if (hasNonEnumProperties) {
for (const childElement of element.querySelectorAll(':scope > ul > li')) {
Expand All @@ -77,6 +78,8 @@ class MDOutline {
property.required = true;
properties.push(property);
}
} else if (ul) {
comment += '\n' + parseComment(ul).split('\n').map(l => ` - ${l}`).join('\n');
}
return {
name,
Expand Down Expand Up @@ -214,6 +217,7 @@ class MDOutline {
return fragment;
}
});
page.off('console', logConsole);
return new MDOutline(classes, errors);
}

Expand Down
15 changes: 15 additions & 0 deletions utils/doclint/check_public_api/test/md-builder-comments/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### class: Foo

#### foo.method(arg1, arg2)
- `arg1` <[string]> A single line argument comment
- `arg2` <[string]> A multiline argument comment:
- it could be this
- or it could be that
- returns: <[Promise]<[ElementHandle]>>

The method does something.

[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String"
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
[ElementHandle]: # "ElementHandle"
[ElementHandle]: # "Frame"
35 changes: 35 additions & 0 deletions utils/doclint/check_public_api/test/md-builder-comments/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"classes": [
{
"name": "Foo",
"members": [
{
"name": "method",
"type": {
"name": "Promise<ElementHandle>"
},
"kind": "method",
"comment": "The method does something.",
"args": [
{
"name": "arg1",
"type": {
"name": "string"
},
"kind": "property",
"comment": "A single line argument comment"
},
{
"name": "arg2",
"type": {
"name": "string"
},
"kind": "property",
"comment": "A multiline argument comment:\n - it could be this\n - or it could be that"
}
]
}
]
}
]
}
11 changes: 8 additions & 3 deletions utils/doclint/check_public_api/test/md-builder-common/result.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@
"classes": [
{
"name": "Foo",
"comment": "This is a class.",
"members": [
{
"name": "frame",
"type": {
"name": "[Frame]"
},
"kind": "event"
"kind": "event",
"comment": "This event is dispatched."
},
{
"name": "$",
"type": {
"name": "Promise<ElementHandle>"
},
"kind": "method",
"comment": "The method runs document.querySelector.",
"args": [
{
"name": "selector",
"type": {
"name": "string"
},
"kind": "property"
"kind": "property",
"comment": "A selector to query page for"
}
]
},
Expand All @@ -31,7 +35,8 @@
"type": {
"name": "string"
},
"kind": "property"
"kind": "property",
"comment": "Contains the URL of the request."
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions utils/doclint/check_public_api/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('checkPublicAPI', function() {
it('js-builder-common', testJSBuilder);
it('js-builder-inheritance', testJSBuilder);
it('md-builder-common', testMDBuilder);
it('md-builder-comments', testMDBuilder);
});

runner.run();
Expand Down Expand Up @@ -101,6 +102,7 @@ function serialize(doc) {
const result = {
classes: doc.classesArray.map(cls => ({
name: cls.name,
comment: cls.comment || undefined,
members: cls.membersArray.map(serializeMember)
}))
};
Expand All @@ -114,6 +116,7 @@ function serializeMember(member) {
name: member.name,
type: serializeType(member.type),
kind: member.kind,
comment: member.comment || undefined,
args: member.argsArray.length ? member.argsArray.map(serializeMember) : undefined
}
}
Expand Down