-
-
Notifications
You must be signed in to change notification settings - Fork 303
Extract documentation from Component methods #66
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
Conversation
That's going to make the react native docs so much better thanks! (I haven't written a single line in this codebase so I'm not a good reviewer) |
This is awesome! I looked over the code and it looks great. I'm not such a big fan of making assumptions and parse the docblock with doctrine, but then again, this is probably the most common use case (having jsdoc-like docblocks), so including these bells and whistles will probably be a good thing? Thoughts? |
I think that as long as it doesn't break with other docblock styles than jsdoc (does that even exists) it is fine. We could always just return the raw docblock and leave the parsing to clients but I think the flow/jsdoc setup is common enough to parse it by default and adds a lot of useful info like description for each parameter. |
|
||
// Add jsdoc @return description. | ||
if (jsDoc) { | ||
const returnTag = jsDoc.tags.find(tag => tag.title === 'returns'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be (tag.title === 'returns' || tag.title === 'return')
as 'return' is the synonym.
I haven't tested it yet, but looked through it and added some comments. On thing I noticed is that annotations which are not evaluated in the handlers are completely swallowed right now (for example we use a lot @example), and as the raw docblock is also not there, one would currently need to parse the file again, to get the remaining jsdoc-annotations. But providing them in an array would even more lock-in react-docgen to jsdoc and the format that doctrine uses, so I wouldn't do that. For consistency with the react-compnent I would say to have the raw description in there is probably the best, so one doesn't endup parsing the file a second time. But the |
Good point about annotations, we should definitely return the raw docblock so additional parsing can be done. I think we should still keep the description as it is now to avoid having to remove jsdoc tags that we don't want to show in the documentation. |
Actually I think I should move all the JSDoc stuff in a separate handler and only extract the docblock in |
That sounds like a good plan. 👍 |
…nd add raw docblock
@danez I think I addressed most of the things you pointed out.
|
Awesome, looks good to me. I hope I have time next week to try it out. I can then also make additional PR to add missing edge cases if I ran into any. |
Thanks for all the work and thought you put into this. And thanks for the fruitful discussion! |
@fkling Could you make a new version on NPM? I'd like to start integrating this on the react-native website :) |
@janicduplessis: Done! (2.8.1 because I messed up the npm publish process). If you have a small input/output example handy, I can update the release notes with it :) |
Hey @janicduplessis, I chatted with @fkling who suggested I post here with regards to a question I had around improving RN docs. I was exploring whether we could tease out the type definitions, ex: https://github.com/facebook/react-native/blob/master/Libraries/Components/StatusBar/StatusBar.js we have one called StatusBarAnimation that I'd like to list separately with perhaps the option of adding more comments around it. So the method signature code snippet
Gets turned into
The JSON output of parsing doesn't contain any mention of StatusBarAnimation so we could perhaps list it in the doc. A part of it looks like this:
So the question is, any idea on how we could bring out the custom type name into the returned JSON, StatusBarAnimation in this example? |
It should be possible to get the name of the type Identifier before resolving the flow type. Here's the relevent code for params and return value Here's what the ast should look like https://astexplorer.net/#/SSIvYwuj5V. We can probably look for GenericTypeAnnotation and then get it's Identifier name and add this to the returned type object. Let me know if that makes sense :) |
@janicduplessis thanks for the pointer. I tried it out by making the following change in getMethodDocumentation.js
It seems to spit out the right stuff. Is that what you were pointing me towards? |
This adds documentation for methods of react components. It works with both React.createClass and classes. It reads from jsdoc blocks for descriptions and flow types for type information.
It supports:
It only removes react component methods and leaves removing private methods to the users if they choose so.
Tested on the react-native codebase.
Closes #17
cc @danez @fkling @vjeux