Skip to content

Commit fc29f90

Browse files
authored
fix: Don't show warning that @returns JSDoc tag has no name (styleguidist#1671)
Fixes styleguidist#1667
1 parent 356906e commit fc29f90

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

src/client/rsg-components/Argument/ArgumentRenderer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const styles = ({ space }: Rsg.Theme) => ({
1515
});
1616

1717
export interface ArgumentProps {
18-
name: string;
18+
name?: string;
1919
type?: any;
2020
default?: string;
2121
description?: string;
@@ -70,7 +70,7 @@ export const ArgumentRenderer: React.FunctionComponent<ArgumentPropsWithClasses>
7070

7171
ArgumentRenderer.propTypes = {
7272
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
73-
name: PropTypes.string.isRequired,
73+
name: PropTypes.string,
7474
type: PropTypes.object,
7575
default: PropTypes.string,
7676
description: PropTypes.string,

src/loaders/utils/__tests__/getProps.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,40 @@ it("should not crash when using doctrine to parse a default prop that isn't in t
225225
expect(result).toMatchSnapshot();
226226
});
227227

228+
it('should not crash when using doctrine to parse a return method that does not have type in it', () => {
229+
const result = getProps(
230+
{
231+
displayName: 'Button',
232+
methods: [
233+
{
234+
docblock: `
235+
Public Method
236+
237+
@public
238+
@returns {Boolean} return a Boolean Value
239+
`,
240+
returns: {
241+
description: 'return a Boolean Value',
242+
type: { name: 'boolean' },
243+
},
244+
},
245+
] as any,
246+
},
247+
__filename
248+
);
249+
250+
// @ts-ignore
251+
expect(result.methods[0].returns).toEqual(
252+
expect.objectContaining({
253+
description: 'return a Boolean Value',
254+
type: {
255+
name: 'boolean',
256+
type: 'NameExpression',
257+
},
258+
})
259+
);
260+
});
261+
228262
it('should guess a displayName for components that react-docgen was not able to recognize', () => {
229263
const result = getProps(
230264
{

src/loaders/utils/getProps.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@ export default function getProps(doc: DocumentationObject, filepath?: string): R
9494
allTags as TagProps,
9595
JS_DOC_METHOD_RETURN_TAG_SYNONYMS
9696
) as TagParamObject[];
97-
const returns = method.returns || returnTags[0];
97+
const returns = method.returns
98+
? {
99+
...method.returns,
100+
type: {
101+
type: 'NameExpression',
102+
...method.returns.type,
103+
},
104+
}
105+
: returnTags[0];
98106

99107
if (returns) {
100108
method.returns = returns;

0 commit comments

Comments
 (0)