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

import/order: unresolved imports affecting the other #957

Open
aliaksandr-yermalayeu opened this issue Oct 20, 2017 · 5 comments
Open

import/order: unresolved imports affecting the other #957

aliaksandr-yermalayeu opened this issue Oct 20, 2017 · 5 comments

Comments

@aliaksandr-yermalayeu
Copy link

Unresolved imports automatically get "NaN" rank and also take part in finding out order violations.

Config:

{
    "rules": {
        "import/order": ["error", {
            "groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
            "newlines-between": "ignore"
    }]
}

Example 1.

import a from "a.js"; //external import
import b from "b.js";
import d from "../d.js";
import e from "./e.js";
import c from "src/c.js"; //eslint-error

Example 2.

import a from "~/a.js"; //unresolved import
import b from "b.js";
import d from "../d.js";
import e from "./e.js";
import c from "src/c.js"; //no error

In the first example you may see that the order of imports is violated, because external import c goes after parent d. In the second one a becomes an unresolved due to ~ sign and starts interfering to plugin work.

I would say that unresolved imports should be ignored from the ordering process.

@atos1990
Copy link

I have a similar problem.
I'm use Webpack alias '~' in imports and during applying Order Rule such imports have NaN rank.
Maybe should add possibility to resolve Import type by Webpack alias?

@fdev
Copy link

fdev commented Apr 19, 2020

Any update on this? import/no-unresolved still creates import/order errors.

@ljharb
Copy link
Member

ljharb commented Apr 19, 2020

It’s not clear what the solution is to me. Ignoring them doesn’t necessarily work - does that mean they end up at the bottom? Unchanged, but other things can be moved across them?

A PR with tests would be welcome.

@fdev
Copy link

fdev commented Apr 19, 2020

I would not ignore them.

Imports of type parent, sibling and index would remain the same. Even if the module path does not resolve, the path string still implies the type.
Imports of type builtin will always resolve; otherwise it's type internal or external.
That leaves internal and external. I assume you have to resolve the module path to tell the difference. In this case, when a path does not resolve, I would default to an interpretation of external as this is presumably more common than internal.

@ljharb
Copy link
Member

ljharb commented Apr 19, 2020

That seems reasonable.

Of course, the best workaround for this is, make sure all your specifiers resolve - whether that's npm install, or configuring a resolver for this eslint plugin so it knows how to resolve your paths.

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

No branches or pull requests

4 participants