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

[Docs only] Various fixes/cleanups with demo code imports #5641

Merged
merged 17 commits into from
Feb 24, 2022

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Feb 15, 2022

Summary

List of fixes/improvements in this PR:

  • Fixed CodeSandbox links not using the correct demo code with cleaned up/ordered imports
  • Fixed the import regex not recognizing @emotion/react as a valid import
  • Fixed line comments before imports (original PR, see below sub-section)
  • Accounted for the edge case where code might not have an EUI import in it
  • Cleaned up/enforced more consistent newlines between imports
  • Misc cleanup & tech debt (comment headings, removed unnecessary escapes, and added unit tests)

Import comment fix

Certain 3rd-party imports had location-sensitive comments directly above them, e.g. // @ts-ignore or // eslint-disable. Those comments were not getting caught by our new import regex added in #5533 and were falling out of order.

Example: https://elastic.github.io/eui/#/tabular-content/data-grid-ref-methods (click on Demo TS tab)

Before

After

Checklist

@cee-chen cee-chen force-pushed the docs/fix-ts-ignore-imports branch from b08b3c8 to a473452 Compare February 15, 2022 22:27
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5641/

@cchaos
Copy link
Contributor

cchaos commented Feb 15, 2022

Also, was the order of the React imports vs EUI imports ever discussed in #5533? Maybe it's just what I'm familiar with, but it feels odd to have EUI first, then React especially since EUI depends on React. Didn't know if there might be a quick fix for this.

@cee-chen
Copy link
Contributor Author

@chandlerprall Any thoughts on Caroline's comments above? I have no strong feelings either way personally, I can kind of follow the reasoning that since EUI is the primary library that the demo code is intending to show, it's fine that the EUI imports come first. But like I said, I don't super mind either way and it would be a relatively quick change.

@breehall
Copy link
Contributor

breehall commented Feb 16, 2022

Also, was the order of the React imports vs EUI imports ever discussed in #5533?

This wasn't something that was originally discussed and likely happened because I didn't change the order of the original logic in this file, I just cleaned it up. I don't think I have any strong feelings either way and would be fine with the order change.

@chandlerprall
Copy link
Contributor

I've no strong feelings either, but I do prefer importing react first. Would be a nice change if it's quick & straightforward 👍

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5641/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5641/

…(??)

- c4329bc hadn't fixed every edge case/import permutation, so I wrote some unit tests to make sure I'd fully captured everything
@cee-chen
Copy link
Contributor Author

welp, this was a pretty textbook case of going down a rabbit hole 🐰

I went a little extra and wrote unit tests for this file since it was getting pretty complex. @chandlerprall any chance you can help me out with running yarn jest on files inside ./src-docs? Right now the error it's giving is something about not being able to find ./scripts/babel/proptypes-from-ts-props from the babelrc config. I manually commented those lines locally to get my tests running, but it would be nice to run them automatically

@cee-chen cee-chen changed the title [Docs only] Account for line comments before imports on demo JS/TS [Docs only] Various fixes/cleanups with demo code imports Feb 17, 2022
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5641/

Copy link
Contributor

@breehall breehall left a comment

Choose a reason for hiding this comment

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

This looks good to me! Thank you for adding tests for the utils file. It's become more complex with our recent changes, so the tests are a great addition!

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM! Tested in the preview, changes look like they apply as desired in the Demo TS tab, and the codesandbox initial file now opens correctly too.

Holding off on an approval until the local test configuration is updated (talked about the potential fix over zoom), but wanted to get everything else out of the way.

);
baseConfig.plugins.splice(
index + 1,
0,
'./scripts/babel/react-docgen-typescript'
`${__dirname}/../scripts/babel/react-docgen-typescript`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chandlerprall I have no idea why this works but I cribbed it from parcel-bundler/parcel#1698 (comment) and it seems to solve the broken Jest tests 🙈 I also don't really know why this one needs ../ and the previous one doesn't, hahaa

FWIW though I ran yarn start, yarn test-unit, and yarn build-pack and all of them ran with no errors with this change (and the new regex unit tests do show up as expected in yarn test-unit 🎉)

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5641/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Confirmed the src-docs test is detected & executed, :shipit:

@cee-chen
Copy link
Contributor Author

If this causes unexpected babel shenanigans down the line please do feel free to blame/ping (bling, if you will) me!

@cee-chen cee-chen merged commit bd60073 into elastic:main Feb 24, 2022
@cee-chen cee-chen deleted the docs/fix-ts-ignore-imports branch February 24, 2022 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants