eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Defining internal-regex and import/external-module-folders together yields unexpected errors

Open Nantris opened this issue 4 years ago • 2 comments

In our monorepo we store our internal packages under ./packages

So we tried a config like this:

rules: {
  'import/order': 'warn',
},
settings: {
  'import/internal-regex': '^internal-', //  This makes importing monorepo packages get treated as though they were 'relative-parent-imports'
  'import/external-module-folders': ['node_modules', 'packages'],
}

But that makes a non-relative import throw this unexpected error

import { foo } from 'internal-utils';
                     ^--- // Relative imports from parent directories are not allowed.

Nantris avatar Jun 25 '21 23:06 Nantris

We were able to workaround this with the following configuration in the meantime:

rules: {
  'import/order': [
    'error',
    {
      pathGroups: [
        {
          pattern: 'internal-*',
          group: 'external',
          position: 'after',
        },
      ],
      pathGroupsExcludedImportTypes: [],
    },
  ],
}, 
settings: {
  // 'import/internal-regex': '^internal-', // Disable this line
  'import/external-module-folders': ['node_modules', 'packages'],
}

Nantris avatar Jun 25 '21 23:06 Nantris

Interesting interaction between the rules.

Would be nice if anybody contributes a test case

soryy708 avatar Jan 26 '25 19:01 soryy708