Skip to content

Commit

Permalink
fix: Don't show warning that @returns JSDoc tag has no name (#1671)
Browse files Browse the repository at this point in the history
Fixes #1667
  • Loading branch information
mitsuruog committed Sep 7, 2020
1 parent 356906e commit fc29f90
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/client/rsg-components/Argument/ArgumentRenderer.tsx
Expand Up @@ -15,7 +15,7 @@ export const styles = ({ space }: Rsg.Theme) => ({
});

export interface ArgumentProps {
name: string;
name?: string;
type?: any;
default?: string;
description?: string;
Expand Down Expand Up @@ -70,7 +70,7 @@ export const ArgumentRenderer: React.FunctionComponent<ArgumentPropsWithClasses>

ArgumentRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
name: PropTypes.string.isRequired,
name: PropTypes.string,
type: PropTypes.object,
default: PropTypes.string,
description: PropTypes.string,
Expand Down
34 changes: 34 additions & 0 deletions src/loaders/utils/__tests__/getProps.spec.ts
Expand Up @@ -225,6 +225,40 @@ it("should not crash when using doctrine to parse a default prop that isn't in t
expect(result).toMatchSnapshot();
});

it('should not crash when using doctrine to parse a return method that does not have type in it', () => {
const result = getProps(
{
displayName: 'Button',
methods: [
{
docblock: `
Public Method
@public
@returns {Boolean} return a Boolean Value
`,
returns: {
description: 'return a Boolean Value',
type: { name: 'boolean' },
},
},
] as any,
},
__filename
);

// @ts-ignore
expect(result.methods[0].returns).toEqual(
expect.objectContaining({
description: 'return a Boolean Value',
type: {
name: 'boolean',
type: 'NameExpression',
},
})
);
});

it('should guess a displayName for components that react-docgen was not able to recognize', () => {
const result = getProps(
{
Expand Down
10 changes: 9 additions & 1 deletion src/loaders/utils/getProps.ts
Expand Up @@ -94,7 +94,15 @@ export default function getProps(doc: DocumentationObject, filepath?: string): R
allTags as TagProps,
JS_DOC_METHOD_RETURN_TAG_SYNONYMS
) as TagParamObject[];
const returns = method.returns || returnTags[0];
const returns = method.returns
? {
...method.returns,
type: {
type: 'NameExpression',
...method.returns.type,
},
}
: returnTags[0];

if (returns) {
method.returns = returns;
Expand Down

0 comments on commit fc29f90

Please sign in to comment.