Description
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
Repro Code
import * as Test from "test.js";
console.log(Test);
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"rules": {
"no-restricted-imports": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
"patterns": [],
// (alternatively)
// "paths": []
}
]
}
},
};
tsconfig
No response
Expected Result
- ESLint does not crash
Actual Result
- ESLint crashes with the following error:
TypeError: rules.ImportDeclaration is not a function
Occurred while linting ...filename...
Rule: "@typescript-eslint/no-restricted-imports"
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:
- ESLint: 8.56.0
- @typescript-eslint/*: 6.15.0