gpt4 book ai didi

typescript - TSLint:有序导入配置

转载 作者:行者123 更新时间:2023-12-04 02:09:55 26 4
gpt4 key购买 nike

我正在尝试配置我的TSLint规则ordered-imports以使导入顺序如下所示:

// React
import React from 'react';
import { View } from 'react-native';

// Libs
import * as _ from 'lodash';
import * as moment from 'moment';

// Internal libs
import Bar from '@app/bar';
import Foo from '@app/foo';

// Relative paths
import { Element } from './my-element';
import MyFunction from './my-function';


这是我尝试创建的规则,但仍然无法达到上述要求。

我似乎无法与 react以外的绝对导入匹配,我尝试使用 null以及像 ^!react这样的非响应式(Reactive)匹配,但它不起作用。

这是我的规矩
{
"ordered-imports": [
true,
{
"module-source-path": "full",
"grouped-imports": true,
"groups": [
{
"name": "react",
"match": "^react",
"order": 1
},
{
"name": "node_modules",
"match": null,
"order": 2
},
{
"name": "internal modules",
"match": "^@app",
"order": 3
},
{
"name": "relative dir",
"match": "^[.]",
"order": 4
}
]
}
]
}


有人可以帮我弄清楚我在做什么错吗?

谢谢

最佳答案

这对您有用吗?

{
"rules": {
"ordered-imports": [
true,
{
"module-source-path": "full",
"grouped-imports": true,
"groups": [
{
"name": "react",
"match": "^react.*",
"order": 1
},
{
"name": "internal modules",
"match": "^@app.*",
"order": 3
},
{
"name": "relative dir",
"match": "^[.].*",
"order": 4
},
{
"name": "node_modules",
"match": ".*",
"order": 2
}
]
}
]
}
}

两项更改:
  • 将'null'匹配器移到列表的末尾,因此仅当没有其他匹配项时,它始终匹配
  • 在所有匹配器的末尾添加了.*。 oji‍♂️
  • 关于typescript - TSLint:有序导入配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56441891/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com