-
-
Notifications
You must be signed in to change notification settings - Fork 896
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 prop types of plugins #683
Conversation
This comment has been minimized.
This comment has been minimized.
Codecov Report
@@ Coverage Diff @@
## main #683 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 731 765 +34
=========================================
+ Hits 731 765 +34
Continue to review full report at Codecov.
|
4245653
to
14c0952
Compare
14c0952
to
8a6886b
Compare
Can you add a test, that failed before, and is now solved? |
8a6886b
to
2d73d4d
Compare
Sure thing! I have updated the PR with tests. |
lib/react-markdown.js
Outdated
PropTypes.bool, | ||
PropTypes.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any example of plugins that use bool or number that we could test with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not on our side, but it seemed worth having the completeness? There is nothing wrong with a plugin taking numbers or booleans as options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChristianMurphy You previously said:
-
[…] I don't see
any
as being a good fit -
I'm […] cautious adding […] complexity to the prop types, […] the TypeScript types offer a more precise understanding of what is accepted.
I feel most for the latter. In particular because TS types are better and this current prop-types code is overlong, what about using “any”s here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that any
is a better fit. Isn't it what the typescript type declarations have, anyway? Is this the right type to be looking at?
type Pluggable<PluginParameters extends any[] = any[]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that any is a better fit. Isn't it what the typescript type declarations have, anyway? Is this the right type to be looking at?
Not quite. Walking through that:
<PluginParameters
Means that TypeScript wants a specific type
extends any[]
means that TypeScript means that a plugin can have from 0 to any number of settings
= any[]>
means for plugins without typings, don't type check.
Practically that means TypeScript will match an exact type based off what the plugin passes, but can fallback for legacy plugins which are untyped.
[…] I don't see any as being a good fit
I'm […] cautious adding […] complexity to the prop types, […] the TypeScript types offer a more precise understanding of what is accepted.
I feel most for the latter. In particular because TS types are better and this current prop-types code is overlong, what about using “any”s here?
I'd see more a balance of these.
Maybe using any
for one of the inner-more types?
For example:
// Plugin options:
remarkPlugins: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.object,
PropTypes.func,
PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.func,
PropTypes.arrayOf(
PropTypes.any
)
])
)
])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is also acceptable to me. Boolean is most important, but a) I’ve also seen userland plugins accept other random stuff (which is slightly weird so it’s not very important), b) the more stuff is added, the closer it becomes to any
anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed this update. I had to add a pragma around the use of PropTypes.any
:
// type-coverage:ignore-next-line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well that's bizarre. the code formatter you use changed the case of the pragmas, thus breaking the pragmas. Adding
// prettier-ignore
// type-coverage:ignore-next-line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ESLint rule turned on by xo
does unfortunately not understand type-coverage
comments.
https://github.com/xojs/eslint-config-xo/blob/0a302bdd73bfd49e956ec7f5ebf2c2247c62c310/index.js#L274-L284.
You could try and PR it to them, or you can turn it off here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the PR to disable the code formatting rule for the type-coverage line.
2d73d4d
to
a04e417
Compare
a04e417
to
34e062c
Compare
This comment has been minimized.
This comment has been minimized.
Thanks, released! |
Initial checklist
Description of changes
This PR extends the prop-types of rehypePlugins and remarkPlugins to support strings and arrays of strings. See remarkjs/remark#945