ale*_*ngn 10 typescript tslint
我正在尝试配置我的 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';
Run Code Online (Sandbox Code Playgroud)
这是我试图创建的规则,但我仍然无法达到上述工作的程度。
我似乎无法匹配绝对导入以外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
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄清楚我做错了什么吗?
谢谢
Jos*_*osh 12
这对你有用吗?
{
"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
}
]
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
两个变化:
.*
到所有匹配器的末尾。??? 归档时间: |
|
查看次数: |
2841 次 |
最近记录: |