question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: no-restricted-imports patterns interpret path patterns relative to each file rather than to .eslintrc

See original GitHub issue

Environment

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?

@typescript-eslint/parser

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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
peeycommented, Sep 14, 2021

I’ll check if no-restricted-paths is suitable for blocking parent-directory imports and get back to you.

0reactions
nzakascommented, Nov 4, 2021

Closing per last comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I want to make an error in eslint when importing a file from ...
The current eslintrc.js is described. Added @typescript-eslint/no-restricted-imports. module.exports = { parser ...
Read more >
no-restricted-imports - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
no-restricted-imports | typescript-eslint
Examples​. This rule extends the base eslint/no-restricted-imports rule. ... You can specify this option for a specific path or pattern as follows:.
Read more >
Airbnb JavaScript Style Guide()
Why? let is block-scoped rather than function-scoped like var . ... 10.4 Only import from a path in one place. eslint: no-duplicate-imports.
Read more >
Eslint-module-utils NPM - npm.io
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found