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.

eslint-plugin-import doesn't work when load entire module

See original GitHub issue

Hello, while using this packahe found that it doesn’t work correctly when try to load entire module.

My configuration is

// .eslintrc

"extends": [
    ...
    "plugin:import/typescript"
],

"rules": {
    ...
    "import/order": [
            "error",
            {
                "groups": ["builtin", "external", "internal", ["parent", "sibling", "index"]],
                "pathGroupsExcludedImportTypes": ["builtin"],
                "pathGroups": [
                    {
                        "pattern": "core-config/**",
                        "group": "internal",
                        "position": "before"
                    },
                    {
                        "pattern": "core/**",
                        "group": "internal",
                        "position": "before"
                    },
                    {
                        "pattern": "config/**",
                        "group": "internal",
                        "position": "before"
                    },
                    {
                        "pattern": "inject!*/**",
                        "group": "internal",
                        "position": "after"
                    },
                    {
                        "pattern": "core-test/**",
                        "group": "internal",
                        "position": "after"
                    },
                    {
                        "pattern": "test/**",
                        "group": "internal",
                        "position": "after"
                    }
                ],
                "newlines-between": "always",
                "alphabetize": {
                    "order": "asc",
                    "caseInsensitive": true
                }
            }
        ]
}

"settings": {
        ...
        "import/resolver": {
            "typescript": {
                "project": [
                    "*/tsconfig.json"
                ]
            }
        }
    },
// core/tsconfig.json, other tsconfigs are similar

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "core-config/*": [
                "../core/config/*"
            ],
            "core/*": [
              "../core/src/*"
            ]
        }
    },
    "include": [
        "../core/src/**/*",
        "../core/config/**/*",
        "../core/typings/**/*"
    ]
}

So my example is

import Popup from 'core/popups/Popup';
import Interceptor from 'core/routers/interceptors/Interceptor';
import Router from 'core/routers/Router';

import 'core/plan/SomeManager';

import 'core/steps/some-step/SomeStep';
import 'core/steps/another-step/AnotherStep';

import 'core/popups/Popup1';
import 'core/popups/Popup2';

import 'core/controllers/Controller1';
import 'core/controllers/popups/PopupController';

import 'core/service/SomeService';

So I wonder why eslint argues only about first 3 rows if anything wrong, other stuff just ignores. Interesting note, I tried to debug it a bit and all that modules are correctly detected as “internal” modules. It quite looks like this plugin doesn’t support such case

UPD. The example above is expected to be like below, but linter doesn’t argue it

import 'core/controllers/Controller1';
import 'core/controllers/popups/PopupController';
import 'core/plan/SomeManager';
import Popup from 'core/popups/Popup';
import 'core/popups/Popup1';
import 'core/popups/Popup2';
import Interceptor from 'core/routers/interceptors/Interceptor';
import Router from 'core/routers/Router';
import 'core/service/SomeService';
import 'core/steps/another-step/AnotherStep';
import 'core/steps/some-step/SomeStep';

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JounQincommented, Jul 19, 2022

import 'x' can have side effects, so the order can not be changed in many cases AFAIK.

0reactions
ljharbcommented, Jul 6, 2021

It’s fine to use the notation - but it’s impossible to know if changing the ordering of a side-effecting import with respect to other imports that may implicitly depend on it will break code or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-import doesn't work when load entire module
Hello, while using this packahe found that it doesn't work correctly when try to load entire module. My configuration is // .eslintrc ...
Read more >
Failed to load plugin 'import' declared in '... » eslint-config ...
My issue turned out to be related to subdirectories. As soon as I made the project the only open project with an .eslintrc.js...
Read more >
eslint-plugin-import - npm
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import ...
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 >
eslint/eslint - Gitter
I'm trying to setup eslint-plugin-import but I can't make it work xD. I'm using parcel as a bundler, so I used eslint-import-resolver-parcel as...
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