Skip to content

Commit e6da96e

Browse files
committed
Added "property to member" plugin for JSDoc
This automatically fixes usage of the form /** desc * @Property {T} name - desc To /** desc * @member {T} name Being careful to only make the transformation when it is logical to do and preserving both descriptions as appropriate.
1 parent be8499f commit e6da96e

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

docs/build/conf.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
"includePattern": ".+\\.js(doc)?$",
2929
"excludePattern": "(^|\\/|\\\\)_"
3030
},
31-
"plugins" : ["plugins/markdown"],
31+
"plugins" : [
32+
"local-plugins/proptomember",
33+
"plugins/markdown"
34+
],
3235
"templates": {
3336
"cleverLinks" : false,
3437
"monospaceLinks" : false,
@@ -56,4 +59,4 @@
5659
"private": false,
5760
"lenient": true
5861
}
59-
}
62+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Transform @property tags to @member tags if it looks like @property was incorrectly used.
3+
* - That is, there is only one property and it has the same name as the member.
4+
* The result is less-redundancy and better type exposure in the JSDoc output.
5+
*
6+
* If the member type is not assigned then the property type is used.
7+
*
8+
* A meld of the description are used; appending the property description if appropriate.
9+
*
10+
* This approach works for most cases in Phaser because JSDoc automatically determines the name if not specified in @name, @method, @member or @field.
11+
*/
12+
13+
var path = require('path');
14+
15+
function looksLikeItMightContain (haystack, needle) {
16+
17+
haystack = haystack || '';
18+
needle = needle || '';
19+
20+
if (!needle) {
21+
return false;
22+
}
23+
24+
haystack = haystack.replace(/[^a-z]/gi, '').toLowerCase();
25+
needle = needle.replace(/[^a-z]/gi, '').toLowerCase();
26+
27+
return haystack.indexOf(needle) > -1;
28+
29+
}
30+
31+
exports.handlers = {};
32+
exports.handlers.newDoclet = function (e) {
33+
34+
var doclet = e.doclet;
35+
var props = e.doclet.properties;
36+
37+
if (doclet.kind === 'member' &&
38+
props && props.length === 1 &&
39+
props[0].name === doclet.name)
40+
{
41+
// "Duplicate"
42+
var prop = props[0];
43+
44+
if (!doclet.type)
45+
{
46+
doclet.type = prop.type;
47+
}
48+
49+
if (!doclet.description)
50+
{
51+
doclet.description = prop.description;
52+
}
53+
else
54+
{
55+
if (!looksLikeItMightContain(doclet.description, prop.description))
56+
{
57+
// Tack it on..
58+
doclet.description += " " + prop.description;
59+
}
60+
}
61+
62+
// And no more prop
63+
e.doclet.properties = undefined;
64+
}
65+
66+
};

0 commit comments

Comments
 (0)