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

feat(eslint-plugin): [no-restricted-imports] support import = require #7709

Conversation

Josh-Cena
Copy link
Member

@Josh-Cena Josh-Cena commented Oct 1, 2023

PR Checklist

Overview

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Josh-Cena!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@netlify
Copy link

netlify bot commented Oct 1, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f9befaf
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/652efcc1e4c1ef00085765fa
😎 Deploy Preview https://deploy-preview-7709--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 98 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@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.

Swell, LGTM!

I think this is a breaking change and blocked on going into our next major release?

@@ -6,7 +6,7 @@ description: 'Disallow specified modules when loaded by `import`.'
>
> See **https://typescript-eslint.io/rules/no-restricted-imports** for documentation.

This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule.
This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule. It adds support for the type import (`import type X from "..."`, `import { type X } from "..."`) and `import x = require("...")` syntaxes.
Copy link
Member

Choose a reason for hiding this comment

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

[Praise] Yes! I've started souring on extension docs that don't explicitly say what gets added.

specifier.importKind === 'type',
))
!isAllowedTypeImportPath(importSource) &&
!isAllowedTypeImportPattern(importSource)
Copy link
Member

Choose a reason for hiding this comment

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

[Cleanup] Nit: there's a teeny bit of duplication with calling !isAllowedTypeImportPath(importSource) && !isAllowedTypeImportPattern(importSource). Maybe worth a helper function? It's only two places, so maybe not...

@JoshuaKGoldberg JoshuaKGoldberg added the breaking change This change will require a new major version to be released label Oct 8, 2023
@Josh-Cena
Copy link
Member Author

Josh-Cena commented Oct 8, 2023

I don't think this qualifies as a breaking change (if people really think so it can be behind an option). We usually don't automatically categorize "more errors" as breaking change, especially in the case where an error should be highly expected and the lack of one can only be explained as a bug/oversight.

@JoshuaKGoldberg
Copy link
Member

Yeah I think you're right. In theory, if a lot of devs still used import = require syntax, then I think this'd be more debatable. But it's not a super-used feature.

🚀 ship it!

@JoshuaKGoldberg JoshuaKGoldberg removed the breaking change This change will require a new major version to be released label Oct 17, 2023
@JoshuaKGoldberg JoshuaKGoldberg merged commit 4c8edcf into typescript-eslint:main Oct 18, 2023
45 of 46 checks passed
@Josh-Cena Josh-Cena deleted the no-restricted-imports-check-require branch October 18, 2023 01:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-restricted-imports] No way to use this rule with import = require() syntax.
2 participants