Skip to content

Bug: [no-restricted-imports] allowTypeImports not work with regex pattern #10692

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

Closed
4 tasks done
indooorsman opened this issue Jan 21, 2025 · 3 comments · Fixed by #10699
Closed
4 tasks done

Bug: [no-restricted-imports] allowTypeImports not work with regex pattern #10692

indooorsman opened this issue Jan 21, 2025 · 3 comments · Fixed by #10699
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@indooorsman
Copy link

indooorsman commented Jan 21, 2025

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.7.2&fileType=.ts&code=PTAEAEBcGcFoEsDmA7A9gJwKYCh4FsAHDSUSATwM1AG9QBDUAX1ADN1U9QBycaAY1SVgdLgG4gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uhXyrPyIAJrUoBbYh2j5UGANrhsORNGhTIAGkyKlOYgEN8g6E1lg5WXUpiIA5ogAe6KLmRkOpVgDoAVJp1WUPrw8BwA7gAqJIgAkhJSMs58sIgBSgC%2BALppYOkB2RB56UA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

import type { a } from '@scope/a';

See https://typescript-eslint.io/play/#ts=5.7.2&fileType=.ts&code=PTAEAEBcGcFoEsDmA7A9gJwKYCh4FsAHDSUSATwM1AG9QBDUAX1ADN1U9QBycaAY1SVgdLgG4gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uhXyrPyIAJrUoBbYh2j5UGANrhsORNGhTIAGkyKlOYgEN8g6E1lg5WXUpiIA5ogAe6KLmRkOpVgDoAVJp1WUPrw8BwA7gAqJIgAkhJSMs58sIgBSgC%2BALppYOkB2RB56UA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  {
    "rules": {
      "@typescript-eslint/no-restricted-imports": [
        "error", {
          "patterns": [{
            "regex": "@scope/.*",
            "allowTypeImports": true
          }]
        }
      ]
    }
  }
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

Should not report error.

Actual Result

Report error:

'@scope/a' import is restricted from being used by a pattern.ESLint[@typescript-eslint/no-restricted-imports](https://typescript-eslint.io/rules/no-restricted-imports)
A screenshot of the error

Additional Info

No response

@indooorsman indooorsman added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 21, 2025
Copy link

Uh oh! @indooorsman, the image you shared is missing helpful alt text. Check your issue body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

1 similar comment
Copy link

Uh oh! @indooorsman, the image you shared is missing helpful alt text. Check your issue body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

@yeonjuan
Copy link
Contributor

yeonjuan commented Jan 22, 2025

The regex option was added in v9.7.0 in the upstream.

typescript-eslint/no-restricted-imports seems to need an update to support the regex option.

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jan 22, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Feb 11, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants