Bug: no-restricted-imports patterns interpret path patterns relative to each file rather than to .eslintrc
See original GitHub issueEnvironment
Environment Info:
Node version: v12.18.2 npm version: v7.18.1 Local ESLint version: v7.32.0 (Currently used) Global ESLint version: Not found Operating System: linux 5.11.6-051106-generic
What parser are you using?
What did you do?
Configuration
{ “root”: true, “ignorePatterns”: [ “projects/**/" ], “overrides”: [ { “files”: [ ".ts” ], “parserOptions”: { “project”: [ “tsconfig.json”, ], “createDefaultProgram”: true }, “extends”: [ “plugin:@angular-eslint/recommended”, “plugin:@angular-eslint/template/process-inline-templates” ], “rules”: { “no-restricted-imports”: [“error”, { “patterns”: [“…/*”] }] } } ] }
Directory structure
src/dir-a src/dir-b .eslintrc
Positive example file (eslint should allow)
// src/dir-a/a.ts import B from "../dir-b/b"
Negative example file (eslint should disallow)
// src/dir-a/a.ts import X from "../../../something"
What did you expect to happen?
I expected patterns to be relative to location of .eslintrc
, so that positive example would be allowed and negative one disallowed.
Instead, both are disallowed.
What actually happened?
Patterns seem to be relative only to location of the file being linted, which are weird semantics.
This perhaps doesn’t matter in the common case where import restrictions are being placed on modules from node_modules
. But it matters whenever the rule is being made for a path.
Participation
- I am willing to submit a pull request for this issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
I’ll check if
no-restricted-paths
is suitable for blocking parent-directory imports and get back to you.Closing per last comment.