Skip to content
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

Fix Warning in ArgumentRenderer #1667 #1671

Merged
merged 2 commits into from
Sep 7, 2020

Conversation

mitsuruog
Copy link
Contributor

@mitsuruog mitsuruog commented Aug 27, 2020

Resolved

I checked the behavior of the component of the original issue after I changed the name to optional and found that the following error occurred.

DoctrineError {name: "DoctrineError", message: "Unknown type undefined"}

What I have found in my research is that in the above cases, type.type in the returns is lost in getProps in this case.
returns should have NameExpression in type.type in my opinion.

// I saw this shape.
{ 
  description: 'return a Boolean Value', 
  type: { name: 'boolean' } 
}

// but it should be this shape.
{
  title: 'returns',
  description: 'return a Boolean Value',
  type: { type: 'NameExpression', name: 'boolean' }
}

@codecov
Copy link

codecov bot commented Aug 27, 2020

Codecov Report

Merging #1671 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
...lient/rsg-components/Argument/ArgumentRenderer.tsx 100.00% <ø> (ø)
src/loaders/utils/getProps.ts 98.61% <100.00%> (+0.03%) ⬆️
src/loaders/utils/resolveESModule.ts 100.00% <0.00%> (ø)

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request!

@@ -94,7 +94,7 @@ 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 || returnTags[0]) && { ...method.returns, ...returnTags[0] };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this isn't different from the previous version, unless I'm missing something (in this case we should make it more clear).

We're returning method.returns if it's truthy, or returnTags[0].

Copy link
Contributor Author

@mitsuruog mitsuruog Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... we need to make it more clear. in my case, method.returns have this object:

{ 
  description: 'return a Boolean Value', 
  type: { name: 'boolean' } 
}

and returnTags[0] have this object:

{
  title: 'returns',
  description: 'return a Boolean Value',
  type: { type: 'NameExpression', name: 'boolean' }
}

method.returns will have occurred DoctrineError when it does not have { type: 'NameExpression' }.
so I figured that merging both results would result in the intended object shape.
But I'm also sure I don't understand enough about this logic.

What should the correct object shape of results be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm even more confused. So now we're overwriting anything in method.returns with returnTags[0] but previously method.returns had higher priority.

If method.returns is missing the type, why not add it there? Something like this:

const getReturns = ({method, tags}) => {
                 if (method.returns) {
                       return {
                           ...method.returns,
                           type: { type: 'NameExpression', ...method.returns.type } 
                       }
                 }

		const returnTags = getMergedTag(
			tags as TagProps,
			JS_DOC_METHOD_RETURN_TAG_SYNONYMS
		) as TagParamObject[];

                 return returnTags[0];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously method.returns had higher priority.

I got it. I’ll add a change on the method.returns side.

@mitsuruog
Copy link
Contributor Author

@sapegin please review me.

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦄

@sapegin sapegin merged commit fc29f90 into styleguidist:master Sep 7, 2020
@mitsuruog mitsuruog deleted the fix-1667 branch September 7, 2020 10:27
@styleguidist-bot
Copy link
Collaborator

🎉 This PR is included in version 11.0.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants