Incorrect behavior of import/order in a monorepo setup - using internal package in workspace
kynesis-root opened this issue · comments
Hi, I have configured import/order
:
'import/order': [
'error',
{
'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
'pathGroups': [
{
pattern: '@workspace/**',
group: 'external',
position: 'after',
},
{
pattern: '@/**',
group: 'external',
position: 'after',
},
],
'distinctGroup': true,
'newlines-between': 'always',
},
],
But yet, eslint-plugin-import
won't throw for:
import SftpClient from 'ssh2-sftp-client';
import LoggerService from '@workspace/logger';
I want these 2 imports to be separate (newlines-between
). And just to clarify, it won't throw for this as well:
import LoggerService from '@workspace/logger';
import SftpClient from 'ssh2-sftp-client';
The plugin doesn't know that '@workspace/*` is internal unless you tell it to treat as internal.
can solve one of two ways:
- via eslint settings config
settings: {
'import/internal-regex': '^@workspace/',
},
or via path group in this rules config see: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#pathgroups-array-of-objects
The plugin doesn't know that '@workspace/*` is internal unless you tell it to treat as internal.
can solve one of two ways:
1. via eslint settings config
settings: { 'import/internal-regex': '^@workspace/', },
or via path group in this rules config see: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#pathgroups-array-of-objects
But I already did the second option,
{
pattern: '@workspace/**',
group: 'external',
position: 'after',
},
You can see it in the main post
Apologies, I missed that in your config. You are using group: 'external' and using the default set of values for pathGroupsExcludedImportTypes
. The default values are ["builtin", "external", "object"]. so if you add the following config it will group as you are expecting. I normally treat these workspace dependencies as internal so normally don't have an issue.
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
pathGroupsExcludedImportTypes: ["builtin", "object"]
pathGroups: [
{
pattern: '@workspace/**',
group: 'external',
position: 'after',
},
{
pattern: '@/**',
group: 'external',
position: 'after',
},
],
distinctGroup: true,
'newlines-between': 'always',
},
],
pathGroupsExcludedImportTypes: ["builtin", "object"]
thanks it worked