我正在尝试配置我的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这样的非react match,但它不起作用。
这是我的规则
{
"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
}
]
}
]
}有人能帮我找出我做错了什么吗?
谢谢
发布于 2019-06-15 22:29:00
这对你有效吗?
{
"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
}
]
}
]
}
}两个变化:
♂️
发布于 2019-08-19 22:01:05
"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 }
]https://stackoverflow.com/questions/56441891
复制相似问题