我正在尝试配置我的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
之类的非反应性匹配,但它不起作用。
这是我的规则
{
"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
}
]
}
]
}
有人可以帮我弄清楚我在做什么错吗?
谢谢
答案 0 :(得分:0)
这对您有用吗?
{
"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
}
]
}
]
}
}
两项更改:
.*
。 ?♂️ 答案 1 :(得分:0)
"groups": [
{ "name": "react", "match": "^react.*", "order": 1 },
{ "name": "pacakges", "match": "^app.*", "order": 20 },
{ "name": "components", "match": "^@.*", "order": 30 },
{ "name": "parent_dir", "match": "^\\.\\.", "order": 40 },
{ "name": "current_dir", "match": "^\\.", "order": 50 },
{ "name": "extra", "match": ".*", "order": 5 }
]