Closed pburkindine closed 4 years ago
Thanks for using JS/TS Import Sorter!
My best guess is your problem has something to do with import-sources-order
:
https://palantir.github.io/tslint/rules/ordered-imports/
Possible values for "import-sources-order" are: "case-insensitive': Correct order is "Bar", "baz", "Foo". (This is the default.) "lowercase-first": Correct order is "baz", "Bar", "Foo". "lowercase-last": Correct order is "Bar", "Foo", "baz". "any": Allow any order.
The order for different options are:
case-insensitive-legacy
: _
< A
-Z
and a
-z
(not documented)case-insensitive
: A
-Z
and a
-z
< _
lowercase-first
: a
-z
< _
< A
-Z
lowercase-last
: A
-Z
< _
< a
-z
The behaviour can be explained by TSLint import path normalisation and path comparison source code.
I believe case-insensitive-legacy
is what TypeScript Import Sorter and JS/TS Import Sorter adopt.
Hope that helps!
@daidodo I appreciate the feedback, but I'm not sure' it's the best solution. case-insensitive-legacy
is an undocumented option, and deprecated behavior. The extensions should not require developers to know the option exists or to tie their codebase to legacy rules. What about adding a setting to control which sort order is used?
Update: We did try case-insensitive-legacy
as a stopgap; for whatever reason this setting is ignored by tslint and the new order (_ last) is still required:
"ordered-imports": [
true,
{
"grouped-imports": true,
"groups": ["^[A-Za-z].*$", "^@.*$", "^\\."],
"import-sources-order": "case-insensitive-legacy"
}
],
Hi @pburkindine, this issue has been resolved in JS/TS Import Sorter from v1.2.3.
Now you can customise sorting rules for import paths in the config:
{
"sortRules": { "paths": ["Aa", "_"] }
}
Some useful examples:
["Aa", "_"]
: corresponds to case-insensitive
in TSLint 6.x.["az", "_", "AZ]
: corresponds to lowercase-first
.["AZ", "_", "az]
: corresponds to lowercase-last
.More details can be found in the wiki.
Tell me if you have any questions! Thanks!
@daidodo I'm a little confused, is JS/TS Import Sorter not a different extension anymore? I thought this one (https://marketplace.visualstudio.com/items?itemName=mike-co.import-sorter) was distinct from https://marketplace.visualstudio.com/items?itemName=dozerg.tsimportsorter ?
You’re right they are different extensions. (I created TS/JS Import Sorter because this extension no longer updates.) I was just trying to finish our discussion after I implemented the new feature. I’d appreciate it if you could try it out and give me feedbacks! Thanks!
@daidodo Thanks! we were able to switch our project over to your extension and configure the sorting rules to behave the way TSLint expects.
The underscore now sorts to the bottom in tslint 6.x; different settings of
ordered-imports:ordered-imports
do not affect thisRight now we are getting by, by using TS Import Sorter to sort and group (such a great extension!), then the hotfix provided by tslint to fix the alphabetization of entries with underscores. Would be great if import-sorter could handle this!