Bug: no-restricted-imports
crashes when paths
& patterns
are both empty, but defined
#8103
Closed
4 tasks done
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
bug
Something isn't working
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.3.2&fileType=.tsx&code=JYWwDg9gTgLgBAKjgQwM5wCoFNXwGZQQhwBEMOMAdAFaokDcAUIwMYQB2qEANlpdxADmACmy4AlPSA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQHYHsBaaFAF2gEsBjUxAE0IoFsAHfaU1DSfAM18gAacNkgABUgE8WKKpRalCKeBVykA9AWJlKNeo1btO6MAG0R2KImjR2Qi9iyXRLAIala0XFzMBdBxAAvg7%2BQSCBQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
No response
Expected Result
Actual Result
Additional Info
Looking at the code of both base rule & extension rule, it seems the base rule does the following check and bails out if there's nothing to lint (it returns nothing in this case):
https://github.com/eslint/eslint/blob/5aa9c499da48b2d3187270d5d8ece71ad7521f56/lib/rules/no-restricted-imports.js#L192-L195
However, the extension rule does not check for that, nor checks whether base rule did not return anything useful:
typescript-eslint/packages/eslint-plugin/src/rules/no-restricted-imports.ts
Lines 228 to 233 in 6128a02
This is most likely not a usual case to handle (as "no paths and patterns" usually means we don't need the rule enabled), I've discovered it only because our shared eslint config has this rule configurable, and one of the projects did not need any exclude patterns. However, it would still be nice if this rule didn't crash the entire ESLint's execution, and handle it like the base rule does.
Tested with:
The text was updated successfully, but these errors were encountered: