Skip to content
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

noUselessIndex is not applied on project-relative path segments #2939

Open
park-jemin opened this issue Dec 14, 2023 · 3 comments
Open

noUselessIndex is not applied on project-relative path segments #2939

park-jemin opened this issue Dec 14, 2023 · 3 comments

Comments

@park-jemin
Copy link

As part of the no-useless-path-segments, we have a noUselessIndex option to remove unnecessary indexes. So the expected behavior works fine on relative imports:

import foo from './foo/index'; // flags fine

But when it comes to references from project-relative imports (e.g., absolute imports in Next), it doesn't seem to get detected:

import foo from 'foo/index'; // does not flag
Screenshot 2023-12-14 at 3 26 52 AM

Should we consider making this its own rule?

@ljharb
Copy link
Member

ljharb commented Dec 14, 2023

No, I think this is just part of the tradeoff you make by choosing a nonstandard approach - ie, project-relative imports.

There's no reasonable and reliable way for static analysis to "just know" that bare specifier aliases reliably point to what should be relative file paths.

@park-jemin
Copy link
Author

park-jemin commented Dec 14, 2023

Can you elaborate how that would affect detecting unnecessary index or index.js file imports in the path? Not sure I'm getting what you mean

@ljharb
Copy link
Member

ljharb commented Dec 14, 2023

A bare specifier typically maps to a package, and packages might have "exports", which wouldn't work with this rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants