import-js / import-js/eslint-plugin-import

Glob Pattern Help

Open
#2,900 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

I am having significant issues getting the import order to accept my glob patterns for my internal import paths. I have the following 10 scenarios for what my imports look like when coming from libraries (im using NX tooling for my monorepo)

@lob/client-glist-menu-feature
@lob/client-glist-menu-data-access
@lob/client-glist-menu-ui
@lob/client-glist-menu-util
@lob/client-glist-menu-data
@lob/shared-feature-menu
@lob/shared-data-access-menu
@lob/shared-ui-menu
@lob/shared-util-menu
@lob/shared-data-menu

my import/order rules look like so:

"import/order": [
          1,
          {
            "groups": ["external", "builtin", "internal", "sibling", "parent", "index"],
            "pathGroups": [
              {
                "pattern": "**/*-feature-**",
                "group": "internal"
              },
              {
                "pattern": "**/*-data-access-*",
                "group": "internal"
              },
              {
                "pattern": "**/*-ui-*",
                "group": "internal"
              },
              {
                "pattern": "**/*-util-*",
                "group": "internal"
              },
              {
                "pattern": "**/*-data-!(access)*",
                "group": "internal"
              },
              {
                "pattern": "**/*-feature",
                "group": "internal"
              },
              {
                "pattern": "**/*-data-access",
                "group": "internal"
              },
              {
                "pattern": "**/*-ui",
                "group": "internal"
              },
              {
                "pattern": "**/*-util",
                "group": "internal"
              },
              {
                "pattern": "**/*-data",
                "group": "internal"
              }
            ],
            "newlines-between": "always",
            "alphabetize": {
              "order": "asc",
              "caseInsensitive": true
            }
          }
        ]

i have even used a Quokka scratchpad using the minimatch library to confirm that these minimatch patterns should seemingly be matching against my paths but the only thing thats actually happening in my files is the alphabetizing. For example this file's imports:

import { GlistFacadeService } from '@lob/client-glist-glists-data-access';
import { favoritedRecipeText, Recipe, unfavoritedRecipeText } from '@lob/client-glist-recipes-data';
import { RecipeFacadeService } from '@lob/client-glist-recipes-data-access';
import { ArrayUtils } from '@lob/client-shared-helpers-util';
import { ConfirmActionComponent } from '@lob/client-shared-user-actions-ui';
import { Ingredient } from '@lob/shared-ingredients-data';

I would expect to look like:

import { GlistFacadeService } from '@lob/client-glist-glists-data-access';
import { RecipeFacadeService } from '@lob/client-glist-recipes-data-access';
import { ConfirmActionComponent } from '@lob/client-shared-user-actions-ui';
import { favoritedRecipeText, Recipe, unfavoritedRecipeText } from '@lob/client-glist-recipes-data';
import { ArrayUtils } from '@lob/client-shared-helpers-util';
import { Ingredient } from '@lob/shared-ingredients-data';

I know eslint is set up correctly and running since the alphabetizing is working. Anyone have any suggestions as to why this is not working? Thank you!

Oddly enough i did previously have this set up correctly and it was working fine when i was using / instead of - in the import paths, but in an attempt to make my package.json names be valid i have changed all but the first / into -. my old (working) rules with my old import paths are below:

@lob/client/glist/menu/feature
@lob/client/glist/menu/data/access
@lob/client/glist/menu/ui
@lob/client/glist/menu/util
@lob/client/glist/menu/data
@lob/shared/feature/menu
@lob/shared/data/access/menu
@lob/shared/ui/menu
@lob/shared/util/menu
@lob/shared/data/menu

"import/order": [
          1,
          {
            "groups": ["external", "builtin", "internal", "sibling", "parent", "index"],
            "pathGroups": [
              {
                "pattern": "**/data",
                "group": "internal"
              },
              {
                "pattern": "**/data/**",
                "group": "internal"
              },
              {
                "pattern": "**/data-access",
                "group": "internal"
              },
              {
                "pattern": "**/data-access/**",
                "group": "internal"
              },
              {
                "pattern": "**/ui",
                "group": "internal"
              },
              {
                "pattern": "**/ui/**",
                "group": "internal"
              },
              {
                "pattern": "**/feature",
                "group": "internal"
              },
              {
                "pattern": "**/feature/**",
                "group": "internal"
              },
              {
                "pattern": "**/util",
                "group": "internal"
              },
              {
                "pattern": "**/util/**",
                "group": "internal"
              }
            ],
            "newlines-between": "always",
            "alphabetize": {
              "order": "asc",
              "caseInsensitive": true
            }
          }
        ]

something with the minimatch has stopped working when replacing the / with -

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown import/order configuration and sample dash-separated imports, then compare it with the older slash-separated patterns. Trace how the rule matches pathGroups patterns against these imports; done when the configured feature, data-access, UI, util, and data ordering is applied consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.