-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[question] Enforce internal/parent import order with alias #2540
Comments
I'm unclear on what you're asking. Wouldn't folderA and folderB both be internal? |
Maybe I'm just totally wrong but based on my understanding being in 'import/order': [
2,
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'never'
},
], I would like to enforce
With the above given config and (I believe) since I'm using alias the linter doesn't care about the order so: import { bar } from '@src/folderB/fileB1'
import { foo } from '@src/folderA/fileA1' is still valid. |
oh right, you're in fileC at that point. Yes, folderB would be a parent and folderA would be internal. So what you're saying is, you WANT them to be sorted so that folderA comes first (because it's internal), but because it's using a TS alias, it's recognizing it as a parent? Can you share your eslint config? Hopefully you're using the TS eslint resolver. |
You got it! (btw I don't really know if it's
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint/eslint-plugin', 'unused-imports'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:prettier/recommended',
"plugin:@dword-design/import-alias/recommended",
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/explicit-function-return-type': 1,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-inferrable-types': 0,
'@typescript-eslint/no-shadow': 1,
'@typescript-eslint/no-unused-vars': [1, { ignoreRestSiblings: true }],
'import/namespace': 0,
'import/no-extraneous-dependencies': [2, { devDependencies: ['**/test/**'] }],
'import/order': [
2,
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'never'
},
],
'lines-between-class-members': [2, 'always', { exceptAfterSingleLine: true }],
'unused-imports/no-unused-imports': 2,
},
overrides: [
{
files: ['*.decorator.ts'],
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
},
},
],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
}; |
cc @JounQin if the TS resolver is reporting |
@ljharb Sorry I didn't notice the mention previously, but I'm not quite sure to understand why it's related to the TS resolver, does it resolve a incorrect absolute path? |
I'm not certain, but it seems like it's resolving it as a relative path (a parent) rather than a bare specifier (in node_modules). |
I'm still confused, it's using TS alias, and Besides, @andreafspeziale can you please provide a minimal reproduction? |
Right, but a TS alias should still report as if it's |
@andreafspeziale Can you try
@ljharb I don't think that's possible, ts resolver returns absolute paths, it's not |
@JounQin Sure I'll try to ship a sample ASAP |
@JounQin @ljharb As promised. So we can also be sure that the issue is not me messing-up something or just not understanding that it's simply not possible since |
Hello!
I can't find a way to enforce import order to internal / parent using aliases. Maybe it is just not possible.
Example:
Set an alias in my
tsconfig.json
In
fileC1.ts
I would really love to be able to enforce the import from
B
(parent) to happen after importA
(internal) but I'm not sure it is possible since I believe thatalias
would "hide" it.Thanks in advance!
The text was updated successfully, but these errors were encountered: