I'm trying to configure my TSLint rule ordered-imports
to get the import order looking like this:
// 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';
This is the rule I've tried to create but I still can't get to a point where the above works.
I don't seem to be able to match with absolute imports other than react
ones, I've tried to use null
as well as non-react match like ^!react
but it doesn't work.
This is my rules
{
"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
}
]
}
]
}
Can someone help me figuring out what I'm doing wrong?
Thanks
Does this work for you?
{
"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
}
]
}
]
}
}
Two changes:
.*
to the end of all the matchers. 🤷♂️ "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 }
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With