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

Confusing classification of .. in the import/order rule. #1797

Closed
jonathanj opened this issue Jun 2, 2020 · 2 comments
Closed

Confusing classification of .. in the import/order rule. #1797

jonathanj opened this issue Jun 2, 2020 · 2 comments

Comments

@jonathanj
Copy link

jonathanj commented Jun 2, 2020

The relevant rules I have configured:

  import/no-useless-path-segments: error

  import/order:
    - error
    - newlines-between: always
      groups:
        - builtin
        - external
        - internal
        - parent
        - sibling
        - index
      pathGroups:
        - pattern: "app/**"
          group: internal
        - pattern: "@/**"
          group: internal

This code:

import {…} from '..'
import {…} from '../context'

import {…} from './types'

produces this following error:

error  `..` import should occur after import of `./types`             import/order

Which is suggesting that my imports look like this:

import {…} from '../context'

import {…} from './types'

import {…} from '..'

If I change the import to instead be import {…} from '../' then I get only the following error:

error  Useless path segments for "../", should be ".."  import/no-useless-path-segments

On one hand .. is considered part of no order grouping (or index, I can't quite tell which), on the other hand ../ is considered a parent import, except with a "useless" segment.

I'm not sure if I'm misunderstood or missed some part of the documentation but I'm rather confused. I would like .. to group with imports like ../context, since it is equivalent to ../index.

@ljharb
Copy link
Member

ljharb commented Jun 2, 2020

.. and ../ should both be considered a parent import, for sure.

I agree that either one should be treated as the same import group as ../context, since indeed they're shorthand for ../index (or ../$packageJSONMain, etc).

@golopot
Copy link
Contributor

golopot commented Jun 14, 2020

This is fixed in #1658 and released in 2.20.2.

@ljharb ljharb closed this as completed Jun 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants