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

Paths having more than two constructs ../ #2662

Closed
TheAlexGo opened this issue Jan 11, 2023 · 8 comments
Closed

Paths having more than two constructs ../ #2662

TheAlexGo opened this issue Jan 11, 2023 · 8 comments

Comments

@TheAlexGo
Copy link

TheAlexGo commented Jan 11, 2023

Hello! I have the following problem: when trying to sort, those paths that have more than two "../" constructs do not fall into the parent category, but fall into the internal. How to solve this problem?

Expectation:

import { cfg } from 'path/path/path/src/Cfg';
import { l10n } from 'path/src/l10n';
import { helpers } from 'path/path/path/helpers';
import { tip } from 'path/path/tip';

import { controller } from '../../../../path/path/path/controller';
import { component } from '../../../../path/path/path/component';
import { component } from '../../../../path/path/path/component';

Reality:

import { controller } from '../../../../path/path/path/controller';
import { component } from '../../../../path/path/path/component';
import { component } from '../../../../path/path/path/component';
import { cfg } from 'path/path/path/src/Cfg';
import { l10n } from 'path/src/l10n';
import { helpers } from 'path/path/path/helpers';
import { tip } from 'path/path/tip';

Config:

"import/order": [
              2,
              {
                  "groups": [
                      ["builtin", "external"],
                      "internal",
                      ["sibling", "parent"],
                      "object",
                      "type"
                  ],
                  "pathGroups": [
                      {
                          "pattern": "react",
                          "group": "builtin",
                          "position": "before",
                          "patternOptions": {
                              "matchBase": true
                          }
                      },
                      {
                          "pattern": "*.+(css|svg)",
                          "group": "type",
                          "position": "after",
                          "patternOptions": {
                              "matchBase": true
                          }
                      }
                  ],
                  "pathGroupsExcludedImportTypes": ["react"],
                  "alphabetize": {
                      "order": "asc"
                  },
                  "newlines-between": "always"
              }
          ]
@TheAlexGo

This comment was marked as spam.

@ljharb
Copy link
Member

ljharb commented Jan 17, 2023

I'm confused; your code snippet fails to parse because you have two imports of component.

@ljharb
Copy link
Member

ljharb commented Jan 17, 2023

Additionally, you've configured alphabetical sorting, so component comes before controller, and helpers comes before src.

@ljharb
Copy link
Member

ljharb commented Jan 17, 2023

This is the code that passes the test case (with the duplicate component import removed):

import { helpers } from 'path/path/path/helpers';
import { cfg } from 'path/path/path/src/Cfg';
import { tip } from 'path/path/tip';
import { l10n } from 'path/src/l10n';
        
import { component } from '../../../../path/path/path/component';
import { controller } from '../../../../path/path/path/controller';

What about that isn't correct for you?

ljharb added a commit to ljharb/eslint-plugin-import that referenced this issue Jan 17, 2023
@ljharb ljharb closed this as completed in defcf08 Jan 17, 2023
@TheAlexGo
Copy link
Author

I'm confused; your code snippet fails to parse because you have two imports of component.

Yes, it was an example

@TheAlexGo
Copy link
Author

This is the code that passes the test case (with the duplicate component import removed):

import { helpers } from 'path/path/path/helpers';
import { cfg } from 'path/path/path/src/Cfg';
import { tip } from 'path/path/tip';
import { l10n } from 'path/src/l10n';
        
import { component } from '../../../../path/path/path/component';
import { controller } from '../../../../path/path/path/controller';

What about that isn't correct for you?

Hm... It's strange. With these options, I have a "Reality" case, which I cited in the description

@TheAlexGo
Copy link
Author

TheAlexGo commented Jan 18, 2023

Oh, i'm sorry. I misspelled the regex for "import/internal-regex". Thx!
One more question: Is there a way to place imports with more "../" on the bottom?

Expectation:

import { Service } from './path/Service';
import { Controller } from '../../../../path/Controller';
import { DisplayMode } from '../../../../path/DisplayMode';
import { Location } from '../../../../path/Location';

Reality:

import { Controller } from '../../../../path/Controller';
import { DisplayMode } from '../../../../path/DisplayMode';
import { Location } from '../../../../path/Location';
import { Service } from './path/Service';

I know alphabetical sorting puts special characters above letters. Is it possible to somehow change this behavior?

@ljharb
Copy link
Member

ljharb commented Jan 18, 2023

You might be referring to a regression described in #2682.

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