Skip to content
Permalink
Browse files

fix: Make JSDoc @param display arrays (#1623)

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 921e8b1ea8ba0c62a2b7400facdcee06cde07fd2
@@ -93,8 +93,8 @@ module.exports = {
env === 'development'
? false
: {
maxAssetSize: 1100000, // bytes
maxEntrypointSize: 1100000, // bytes
maxAssetSize: 1150000, // bytes
maxEntrypointSize: 1150000, // bytes
hints: 'error',
},
}),
@@ -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),
@@ -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}
/>
);
@@ -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}
/>
@@ -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}
/>
@@ -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) => ({
@@ -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'}
@@ -49,7 +51,7 @@ export const ArgumentRenderer: React.FunctionComponent<ArgumentPropsWithClasses>
)}
{type && (
<Type>
{type.name}
{typeName}
{isOptional && '?'}
{!!defaultValue && `=${defaultValue}`}
</Type>
@@ -513,7 +513,7 @@ describe('props columns', () => {
{
name: 'Foo',
description: 'Converts foo to bar',
type: { name: 'Array' },
type: {type: 'NameExpression', name: 'Array' },
},
],
param: [
@@ -551,7 +551,7 @@ describe('props columns', () => {
{
title: 'Foo',
description: 'Returns foo from bar',
type: { name: 'Array' },
type: {type: 'NameExpression', name: 'Array' },
},
],
},
@@ -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,

0 comments on commit 921e8b1

Please sign in to comment.
You can’t perform that action at this time.