eslint排序按软件包名称

问题描述 投票:0回答:2
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser';

上面的代码失败,因为它希望

BrowserModule

在第一行上。但是我希望这是正确的,因为我想按包名称订购。
这里是我的eslintconfig.

"sort-imports": [ "error", { "ignoreCase": true, "ignoreDeclarationSort": false, "ignoreMemberSort": false, "memberSyntaxSortOrder": [ "none", "all", "multiple", "single" ], "allowSeparatedGroups": true } ],

I正在使用

Eslint-Plugin-import
并支持此类功能。发布我的配置以供参考。它将强制执行React Imports始终是首先的,然后以
@my_org
typescript eslint typescript-eslint
2个回答
13
投票
"import/order": [ "error", { "alphabetize": { caseInsensitive: true, order: "asc", }, "groups": ["external", "builtin", "parent", ["sibling", "index"]], "newlines-between": "never", "pathGroups": [ { group: "external", pattern: "react", position: "before", }, { group: "external", pattern: "@my_org/**", position: "after", }, ], "pathGroupsExcludedImportTypes": ["builtin"], }, ],

基本ESLINT规则只是不支持它 - 它按名称为单位。
您可以像这里一样使用其他分类规则。

https://www.npmjs.com/package/eslint-plugin-simple-import-sort

    

3
投票
您可以使用

ESLINT-PLUGIN-IMPORT-GROUP

它仅用于特定的进口和支持分类。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.