-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Docgen/stop crashing on missing return types #37929
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
77c4104
docgen: Stop crashing on missing return types
dmsnell 2acd00d
Return a different message if we fail to get type information for a f…
dmsnell 69068cf
Avoid printing type information if it's not present.
dmsnell 457824c
Refactor tag formatting to draw out shape of output
dmsnell bf04550
Update tests to reflect relaxed type requirement
dmsnell 02aa382
Also allow missing types on @param tags
dmsnell cf19ba5
Remove try/catch that was guarding code that should never crash.
dmsnell b650710
Only add potential type if it's available
dmsnell 0ad56fc
Update snapshots
dmsnell 6a147f8
Fix that test too - falsy not ''
dmsnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ const formatTag = ( title, tags, formatter, docs ) => { | |
| docs.push( '\n' ); | ||
| docs.push( `*${ title }*` ); | ||
| docs.push( '\n' ); | ||
| docs.push( ...tags.map( formatter ) ); | ||
| docs.push( ...tags.map( ( tag ) => `\n${ formatter( tag ) }` ) ); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -103,54 +103,88 @@ module.exports = ( | |
| formatTag( | ||
| 'Related', | ||
| getSymbolTagsByName( symbol, 'see', 'link' ), | ||
| ( tag ) => | ||
| `\n- ${ tag.name.trim() }${ | ||
| tag.description ? ' ' : '' | ||
| }${ tag.description.trim() }`, | ||
| ( tag ) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for breaking out the conditional logic in the functions in this file. It improves the readability a lot. |
||
| const name = tag.name.trim(); | ||
| const desc = tag.description.trim(); | ||
|
|
||
| // prettier-ignore | ||
| return desc | ||
| ? `- ${ name } ${ desc }` | ||
| : `- ${ name }`; | ||
| }, | ||
| docs | ||
| ); | ||
| formatExamples( getSymbolTagsByName( symbol, 'example' ), docs ); | ||
| formatTag( | ||
| 'Type', | ||
| getSymbolTagsByName( symbol, 'type' ), | ||
| ( tag ) => | ||
| `\n- ${ getTypeOutput( tag ) }${ cleanSpaces( | ||
| ` ${ tag.name } ${ tag.description }` | ||
| ) }`, | ||
| ( tag ) => { | ||
| const type = tag.type && getTypeOutput( tag ); | ||
| const desc = cleanSpaces( | ||
| `${ tag.name } ${ tag.description }` | ||
| ); | ||
|
|
||
| // prettier-ignore | ||
| return type | ||
| ? `- ${ type }${ desc }` | ||
| : `- ${ desc }`; | ||
| }, | ||
| docs | ||
| ); | ||
| formatTag( | ||
| 'Parameters', | ||
| getSymbolTagsByName( symbol, 'param' ), | ||
| ( tag ) => | ||
| `\n- *${ tag.name }* ${ getTypeOutput( | ||
| tag | ||
| ) }: ${ cleanSpaces( tag.description ) }`, | ||
| ( tag ) => { | ||
| const name = tag.name; | ||
| const type = tag.type && getTypeOutput( tag ); | ||
| const desc = cleanSpaces( tag.description ); | ||
|
|
||
| return type | ||
| ? `- *${ name }* ${ type }: ${ desc }` | ||
| : `- *${ name }* ${ desc }`; | ||
| }, | ||
| docs | ||
| ); | ||
| formatTag( | ||
| 'Returns', | ||
| getSymbolTagsByName( symbol, 'return' ), | ||
| ( tag ) => { | ||
| return `\n- ${ getTypeOutput( tag ) }: ${ cleanSpaces( | ||
| const type = tag.type && getTypeOutput( tag ); | ||
| const desc = cleanSpaces( | ||
| `${ tag.name } ${ tag.description }` | ||
| ) }`; | ||
| ); | ||
|
|
||
| // prettier-ignore | ||
| return type | ||
| ? `- ${ type }: ${ desc }` | ||
| : `- ${ desc }`; | ||
| }, | ||
| docs | ||
| ); | ||
| formatTag( | ||
| 'Type Definition', | ||
| getSymbolTagsByName( symbol, 'typedef' ), | ||
| ( tag ) => `\n- *${ tag.name }* ${ getTypeOutput( tag ) }`, | ||
| ( tag ) => { | ||
| const name = tag.name; | ||
| const type = getTypeOutput( tag ); | ||
|
|
||
| return `- *${ name }* ${ type }`; | ||
| }, | ||
| docs | ||
| ); | ||
| formatTag( | ||
| 'Properties', | ||
| getSymbolTagsByName( symbol, 'property' ), | ||
| ( tag ) => | ||
| `\n- *${ tag.name }* ${ getTypeOutput( | ||
| tag | ||
| ) }: ${ cleanSpaces( tag.description ) }`, | ||
| ( tag ) => { | ||
| const name = tag.name; | ||
| const type = tag.type && getTypeOutput( tag ); | ||
| const desc = cleanSpaces( tag.description ); | ||
|
|
||
| // prettier-ignore | ||
| return type | ||
| ? `- *${ name }* ${ type }: ${ desc }` | ||
| : `- *${ name }* ${ desc }` | ||
| }, | ||
| docs | ||
| ); | ||
| docs.push( '\n' ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This particular function has been such a headache to maintain with its many edge cases. Thanks for taking the time to improve it!