-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: support TS syntax in no-restricted-imports
#19562
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
d4d142d
to
dffbc64
Compare
There was a problem hiding this 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
.
There was a problem hiding this 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! 🔪
@JoshuaKGoldberg This needs a re-review. |
There was a problem hiding this 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. 🚀
There was a problem hiding this 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
?
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. |
@JoshuaKGoldberg @mdjermanovic I have addressed your feedback. |
There was a problem hiding this 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! 👏
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. |
Apologies for the delay, will push an update & resolve the comments. |
There was a problem hiding this 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.
Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
@snitin315 can you check the CI failures? |
lib/rules/no-restricted-imports.js
Outdated
// Skip if this is a type-only import specifier and type imports are allowed | ||
if ( | ||
allowTypeImports && | ||
isTypeOnlySpecifier(specifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isTypeOnlySpecifier(specifier) | |
isTypeOnlySpecifier(specifier.specifier) |
Seems that tests for this are missing as this wasn't caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
if (allowTypeImports) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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";
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/