Skip to content

Commit

Permalink
fix: Make JSDoc @param display arrays (#1623)
Browse files Browse the repository at this point in the history
Doctrine has a function to stringify the parameter types. If the type is a string[], doctrine will stringify this into Array.<string>. 

Fixes #1611
  • Loading branch information
isaacbuckman committed Jul 14, 2020
1 parent a8b5e7a commit 921e8b1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/sections/styleguide.config.js
Expand Up @@ -93,8 +93,8 @@ module.exports = {
env === 'development'
? false
: {
maxAssetSize: 1100000, // bytes
maxEntrypointSize: 1100000, // bytes
maxAssetSize: 1150000, // bytes
maxEntrypointSize: 1150000, // bytes
hints: 'error',
},
}),
Expand Down
8 changes: 4 additions & 4 deletions src/client/rsg-components/Argument/Argument.spec.tsx
Expand Up @@ -3,7 +3,7 @@ import { shallow } from 'enzyme';
import { ArgumentRenderer, styles } from './ArgumentRenderer';

const name = 'Foo';
const type = { name: 'Array' };
const type = {type: 'NameExpression', name: 'Array'};
const description = 'Converts foo to bar';
const props = {
classes: classes(styles),
Expand All @@ -28,7 +28,7 @@ it('should render optional argument', () => {
const actual = shallow(
<ArgumentRenderer
{...props}
type={{ type: 'OptionalType', expression: { name: 'Array' } }}
type={{ type: 'OptionalType', expression: {type: 'NameExpression', name: 'Array'} }}
description={description}
/>
);
Expand All @@ -40,7 +40,7 @@ it('should render default value of argument', () => {
const actual = shallow(
<ArgumentRenderer
{...props}
type={{ name: 'String' }}
type={{type: 'NameExpression', name: 'String'}}
default="bar"
description={description}
/>
Expand All @@ -53,7 +53,7 @@ it('should render default value of optional argument', () => {
const actual = shallow(
<ArgumentRenderer
{...props}
type={{ type: 'OptionalType', expression: { name: 'Boolean' } }}
type={{ type: 'OptionalType', expression: {type: 'NameExpression', name: 'Boolean'} }}
default="true"
description={description}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/client/rsg-components/Argument/ArgumentRenderer.tsx
Expand Up @@ -5,6 +5,7 @@ import Markdown from 'rsg-components/Markdown';
import Name from 'rsg-components/Name';
import Type from 'rsg-components/Type';
import Group from 'react-group';
import doctrine from 'doctrine';
import * as Rsg from '../../../typings';

export const styles = ({ space }: Rsg.Theme) => ({
Expand Down Expand Up @@ -38,6 +39,7 @@ export const ArgumentRenderer: React.FunctionComponent<ArgumentPropsWithClasses>
if (isOptional) {
type = type.expression;
}
const typeName = type ? doctrine.type.stringify(type) : '';
const content = (
<Group>
{returns && 'Returns'}
Expand All @@ -49,7 +51,7 @@ export const ArgumentRenderer: React.FunctionComponent<ArgumentPropsWithClasses>
)}
{type && (
<Type>
{type.name}
{typeName}
{isOptional && '?'}
{!!defaultValue && `=${defaultValue}`}
</Type>
Expand Down
4 changes: 2 additions & 2 deletions src/client/rsg-components/Props/Props.spec.tsx
Expand Up @@ -513,7 +513,7 @@ describe('props columns', () => {
{
name: 'Foo',
description: 'Converts foo to bar',
type: { name: 'Array' },
type: {type: 'NameExpression', name: 'Array' },
},
],
param: [
Expand Down Expand Up @@ -551,7 +551,7 @@ describe('props columns', () => {
{
title: 'Foo',
description: 'Returns foo from bar',
type: { name: 'Array' },
type: {type: 'NameExpression', name: 'Array' },
},
],
},
Expand Down
Expand Up @@ -47,7 +47,7 @@ const componentWithEverything: Rsg.Component = {
{
name: 'newValue',
description: 'New value for the counter.',
type: { name: 'Number' },
type: {type: 'NameExpression', name: 'Number' },
},
],
returns: null,
Expand Down

0 comments on commit 921e8b1

Please sign in to comment.