Skip to content

Conversation

snitin315
Copy link
Contributor

@snitin315 snitin315 commented Mar 22, 2025

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Refers #19173

It adds support for type import syntaxes:

  • import type X from "..."
  • import { type X } from "..."
  • import x = require("...")

Is there anything you'd like reviewers to focus on?

https://typescript-eslint.io/rules/no-restricted-imports/

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Mar 22, 2025
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Mar 22, 2025
@github-actions github-actions bot added the rule Relates to ESLint's core rules label Mar 22, 2025
Copy link

netlify bot commented Mar 22, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 94d8d83
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/6897451edffc820008d496c3

@snitin315 snitin315 force-pushed the ts/no-restricted-imports branch from d4d142d to dffbc64 Compare March 26, 2025 15:27
@snitin315 snitin315 marked this pull request as ready for review March 26, 2025 15:38
@snitin315 snitin315 requested a review from a team as a code owner March 26, 2025 15:38
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

There seems to be either extra functionality or missing tests with allowedTypeImportPathNameSet / isAllowedTypeImportPath.

@nzakas nzakas moved this from Needs Triage to Implementing in Triage Mar 27, 2025
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I think we can actually get rid of a bunch of this extension code! 🔪

@snitin315
Copy link
Contributor Author

@JoshuaKGoldberg This needs a re-review.

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

The core functionality looks perfect to me. Just requesting changes on docs (sorry for not till now) and a bit more tests. 🚀

@snitin315 snitin315 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Apr 9, 2025
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

Can you also update the types for this rule in lib/types/rules.d.ts?

Copy link

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions bot added Stale and removed Stale labels Apr 24, 2025
@snitin315
Copy link
Contributor Author

@JoshuaKGoldberg @mdjermanovic I have addressed your feedback.

JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes May 6, 2025
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Looks great, nicely done! 👏

@snitin315 snitin315 moved this from Implementing to Second Review Needed in Triage May 11, 2025
@snitin315 snitin315 requested a review from mdjermanovic May 11, 2025 05:19
@mdjermanovic mdjermanovic moved this from Second Review Needed to Implementing in Triage May 25, 2025
Copy link

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label May 26, 2025
@github-actions github-actions bot removed the Stale label Jul 6, 2025
@snitin315
Copy link
Contributor Author

Apologies for the delay, will push an update & resolve the comments.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Added some notes on the docs.

@nzakas
Copy link
Member

nzakas commented Jul 24, 2025

@snitin315 can you check the CI failures?

@mdjermanovic mdjermanovic moved this from Evaluating to Implementing in Triage Jul 30, 2025
// Skip if this is a type-only import specifier and type imports are allowed
if (
allowTypeImports &&
isTypeOnlySpecifier(specifier)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
isTypeOnlySpecifier(specifier)
isTypeOnlySpecifier(specifier.specifier)

Seems that tests for this are missing as this wasn't caught.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment on lines +511 to +513
if (allowTypeImports) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (allowTypeImports) {
return;
}
if (
allowTypeImports &&
isTypeOnlySpecifier(specifier.specifier)
) {
return;
}

Looks like the isTypeOnlySpecifier() check has been removed instead of fixed (#19562 (comment)).

For example, this should not pass:

/* eslint no-restricted-imports: ["error", { paths: [{
    name: "foo",
	allowImportNames: ["bar"],
	allowTypeImports: true
}]}] */

import { baz } from "foo";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

6 participants