-
Notifications
You must be signed in to change notification settings - Fork 74
Description
Hi @lydell,
Kudos
We are trying to convert an Angular 10 application from the deprecated tsLint dependency to using eslint. There were strong recommendations to use this eslint plugin. And I agree with the recommendations - your extensive research is well documented with every reasoning and finding there is to know about sorting import statements within Javascript / TypeScript files. Good work!
Issue
However, there is one thing bothering me while using this plugin. In my opinion, your plugin seems to incorrectly sort import statements which have the same set of characters from the beginning of the "from path string" followed by:
- a hyphen character (
-a.k.a. the hyphen-minus unicode characterU+002D) - versus a period character (
.a.k.a the full-stop unicode characterU+002E).
Example from path strings
'my-package'vs'my.package'(Common part ='my)'./widget/abc-def.tsx'vs'./widget/abc.defgh.tsx'(Common part ='./widget/abc)'../notification-list-routing.module.ts'vs'../notification-list.component.ts'(Common part ='../notification-list)
According to normal string sorting, hyphens come before periods. However, the default configuration of this plugin, seems to sort the from path strings containing periods first followed by the hyphen character.
Example
The following import sequence seems to be correct in my opinion (as well as TSLint's ordered-import rule).
import { fileNameWithHyphens } from './file-with-hyphens.js';
import { fileNameWithPeriods } from './file.with.periods.js';is auto-fixed into:
import { fileNameWithPeriods } from './file.with.periods.js';
import { fileNameWithHyphens } from './file-with-hyphens.js';Sample Repository
To demonstrate this issue clearly, I have created a small sample plain-vanilla JavaScript-based NodeJS 14.x compatible application here: https://github.com/akaustav/import-order-test. The index.js file disables your plugin rule on line 1 - otherwise the simple-import-sort/imports rule keeps complaining about the order of the import lines on line 2 and 3. It even uses your documented comparator function - see this file.
Question
Is this expected behavior?
Ameet