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 prop types of plugins #683

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Conversation

starpit
Copy link
Contributor

@starpit starpit commented Apr 10, 2022

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

This PR extends the prop-types of rehypePlugins and remarkPlugins to support strings and arrays of strings. See remarkjs/remark#945

@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Apr 10, 2022
@github-actions

This comment has been minimized.

@github-actions github-actions bot added 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Apr 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 10, 2022

Codecov Report

Merging #683 (8a6886b) into main (8143c12) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #683   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          731       765   +34     
=========================================
+ Hits           731       765   +34     
Impacted Files Coverage Δ
lib/react-markdown.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8143c12...8a6886b. Read the comment docs.

@starpit starpit marked this pull request as draft April 11, 2022 00:15
@starpit starpit marked this pull request as ready for review April 11, 2022 00:16
@wooorm
Copy link
Member

wooorm commented Apr 11, 2022

Can you add a test, that failed before, and is now solved?

@starpit
Copy link
Contributor Author

starpit commented Apr 11, 2022

Sure thing! I have updated the PR with tests.

Comment on lines 170 to 171
PropTypes.bool,
PropTypes.number,
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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[]>

Copy link
Member

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
          )
        ])
      )
    ])

Copy link
Member

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

Copy link
Contributor Author

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  

Copy link
Contributor Author

@starpit starpit Apr 12, 2022

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   

Copy link
Member

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.

Copy link
Contributor Author

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.

@starpit starpit changed the title Extend rehype/remarkPlugin propTypes to string and string[] Extend rehype/remarkPlugin propTypes to support array plugin options Apr 13, 2022
@wooorm wooorm changed the title Extend rehype/remarkPlugin propTypes to support array plugin options Fix prop types of plugins Apr 20, 2022
@wooorm wooorm merged commit a2fb833 into remarkjs:main Apr 20, 2022
@wooorm wooorm added 🏗 area/tools This affects tooling 💪 phase/solved Post is done labels Apr 20, 2022
@github-actions

This comment has been minimized.

@wooorm wooorm added the 👶 semver/patch This is a backwards-compatible fix label Apr 20, 2022
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Apr 20, 2022
@wooorm
Copy link
Member

wooorm commented Apr 20, 2022

Thanks, released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏗 area/tools This affects tooling 💪 phase/solved Post is done 👶 semver/patch This is a backwards-compatible fix
Development

Successfully merging this pull request may close these issues.

4 participants