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

Linter: Turn on rule to warn missing import type #95462

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

gabrielcaires
Copy link
Contributor

Closes # #87244

Proposed Changes

Turn on rule '@typescript-eslint/consistent-type-import`

"TypeScript allows specifying a type keyword on imports to indicate that the export exists only in the type system, not at runtime. This allows transpilers to drop imports without knowing the types of the dependencies."

Why are these changes being made?

*Ensure transpilers will safely be removed from the bundle files that we are only importing the type.

Testing Instructions

  • Open any ts(x) file that is importing a type (E.g. /client/landing/stepper/declarative-flow/internals/steps-repository/site-migration-identify/index.tsx)
  • Import a type without use the "type"
  • Check if you can see a warning about it.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@gabrielcaires gabrielcaires marked this pull request as ready for review October 17, 2024 10:38
@gabrielcaires gabrielcaires requested a review from a team October 17, 2024 10:38
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 17, 2024
@gabrielcaires gabrielcaires self-assigned this Oct 17, 2024
@matticbot
Copy link
Contributor

matticbot commented Oct 17, 2024

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications

To test WordPress.com changes, run install-plugin.sh $pluginSlug chore/warn-import-type on your sandbox.

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@daledupreez
Copy link
Contributor

@gabrielcaires, this may need a rebase/merge -- it looks like there are some pretty fundamental issues with the Docker build.

@gabrielcaires gabrielcaires force-pushed the chore/warn-import-type branch from 0da936f to b129d5a Compare October 17, 2024 16:14
@gabrielcaires
Copy link
Contributor Author

@daledupreez rebased, I hope it will work now

Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

@gabrielcaires, the functional change here is working as expected, but it has some knock-on effects:

  • We're adding thousands of new warnings to the linter due to existing issues in the code
  • Some of the new warnings can't be fixed automatically, as the fixed code triggers other linting issues, especially around import/order and import/no-duplicates, but it looks like there are also some "import() type annotations are forbidden" warnings

While I really want this to land, I think we need a clearer, documented plan for getting the changes into the code base before we can generate all the noise this new rule will create.

@gabrielcaires
Copy link
Contributor Author

@daledupreez Next week, I will investigate it.

The most similar PR I found was this one: https://github.com/Automattic/wp-calypso/pull/91408/files

If we have a volunteer to review, I am okay with making some PRs to fix the lint issues gradually in 3-4 PRs.

@daledupreez
Copy link
Contributor

I'd be more than happy to review the PRs! It may make sense to run the linter/fixer on the code base first, identify the issues, and then fix them across a handful of PRs, and then finally deploy the overall linter change once the codebase is in a better position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Type] Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants