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

Incorrect behavior of import/order in a monorepo setup - using internal package in workspace #3001

Closed
kynesis-root opened this issue Apr 12, 2024 · 4 comments

Comments

@kynesis-root
Copy link

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';
@mpellegrini
Copy link

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

@kynesis-root
Copy link
Author

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

@mpellegrini
Copy link

mpellegrini commented Apr 17, 2024

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',
      },
    ],

@kynesis-root
Copy link
Author

pathGroupsExcludedImportTypes: ["builtin", "object"]

thanks it worked

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