eslint 导入/排序合并路径组

问题描述 投票:0回答:1

这是我的

.eslintrc.json
的相关部分:

    "import/order": [
                    "error",
                    {
                        "pathGroups": [
                            {
                                "pattern": "@/**",
                                "group": "internal",
                                "position": "after"
                            }
                        ],
                        "groups": [
                            "builtin",
                            "external",
                            "internal",
                            "unknown",
                            "parent",
                            "sibling",
                            "index",
                            "object",
                            "type"
                        ],
                        "newlines-between": "always-and-inside-groups",
                        "alphabetize": {
                            "order": "asc"
                            "caseInsensitive": true
                        }
                    }
                ],

我不想确保 eslint 不会注意到:

There should be at least one empty line between import groups (eslint import/order)

导入时如下:

import { FeedbackService } from '@/shared/services/FeedbackService.service';
import { UserService } from './user.service';

为了简单起见,我仍然希望允许

./direct-file.ts
而不是使用导入别名,因为导入路径可能会更长。

这个规则可以吗?

我尝试了以下方法来调整我的路径组,如下所示:

"pathGroups": [
    {
        "pattern": ["@/**", "./**"],
        "group": "internal",
        "position": "after"
    }
],

像这样

"pathGroups": [
    {
        "pattern": "@/**",
        "group": "internal",
        "position": "after"
    },
    {
        "pattern": "./**,
        "group": "internal",
        "position": "after"
    }
],

但这并不能解决我的问题。是否有我在文档中找不到的内置解决方案:https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md

javascript import eslint
1个回答
0
投票

添加

"pathGroupsExcludedImportTypes":  ["internal"], 

它对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.