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

Refactor some type related things #1037

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Conversation

mikavilpas
Copy link
Contributor

refactor: eslint uses import type where possible

This commit adds an eslint rule
@typescript-eslint/consistent-type-imports that warns (and
automatically fixes) when import is used instead of import type for
importing types.

This has minor performance benefits at build time and maybe at runtime,
but can also communicate the intent of the import more clearly.

For a nice developer experience, it's recommended to enable autofixing
fixable eslint issues so that the developer never has to worry about
this - it's done completely automatically when the file is saved.
Autoformatting with prettier is also recommended.


refactor: remove unnecessary type assertion

Copy link

stackblitz bot commented Sep 12, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Sep 12, 2024

⚠️ No Changeset found

Latest commit: 1e49b28

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hey-api-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 5:46am

Copy link
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

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

Nice improvements, thank you! I think you will want to update snapshots to ensure tests pass + left one question

@@ -1,8 +1,7 @@
import type { ClassElement, FunctionParameter } from '../compiler';
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this pull Comments and Node too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure why eslint picked this option - I ran . I agree it looks a bit weird.

I will try to fix it manually.

@mikavilpas
Copy link
Contributor Author

The snapshots have been updated and all the tests pass for me locally now.

I noticed I needed to run CI=true pnpm --recursive test to be able to run the tests though. Otherwise I think one of the tests starts a file watcher that does not finish. Do you get this behaviour?

image

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.94%. Comparing base (e4da79c) to head (1e49b28).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1037      +/-   ##
==========================================
- Coverage   75.95%   75.94%   -0.02%     
==========================================
  Files          89       89              
  Lines       10849    10844       -5     
  Branches     1116     1116              
==========================================
- Hits         8240     8235       -5     
  Misses       2602     2602              
  Partials        7        7              
Flag Coverage Δ
unittests 75.94% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mrlubos
Copy link
Member

mrlubos commented Sep 12, 2024

I usually run pnpm openapi-ts test:update and manually stop file watcher. I'm not sure what the error is in e2e tests where the CI is failing. If you can't figure it out and don't want to spend time on it, put e2e folder into ignored patterns for the plugin. That folder is a bit of a pain right now

@mikavilpas
Copy link
Contributor Author

I'll take a look at the failing e2e test - looks like some angular issue. Let's see what comes up.

This commit adds an eslint rule
`@typescript-eslint/consistent-type-imports` that warns (and
automatically fixes) when `import` is used instead of `import type` for
importing types.

This has minor performance benefits at build time and maybe at runtime,
but can also communicate the intent of the import more clearly.

For a nice developer experience, it's recommended to enable autofixing
fixable eslint issues so that the developer never has to worry about
this - it's done completely automatically when the file is saved.
Autoformatting with prettier is also recommended.

- https://typescript-eslint.io/blog/consistent-type-imports-and-exports-why-and-how/
- https://typescript-eslint.io/rules/consistent-type-imports/
@mikavilpas
Copy link
Contributor Author

Ok, it looked like the angular e2e test did not work with this, so I reverted that file and added an eslint ignore for the new rule for it. The e2e tests now also seem to pass locally, let's hope CI agrees 🤞🏻

Copy link

pkg-pr-new bot commented Sep 12, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@hey-api/client-axios@1037
pnpm add https://pkg.pr.new/@hey-api/client-fetch@1037
pnpm add https://pkg.pr.new/@hey-api/openapi-ts@1037

commit: 1e49b28

@mrlubos mrlubos merged commit 8fbd4e4 into hey-api:main Sep 12, 2024
16 of 17 checks passed
@mikavilpas mikavilpas deleted the refactor-types branch September 12, 2024 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants