如何使用 Vim 按字母顺序对 JS es6 导入进行排序

How using Vim alphabetically sort JS es6 imports

我将 vim 用作 typescript 项目的 IDE

import { FlightInfo } from './FlightInfo'                                                                               
import { InfoBlockProps, InfoRowProps, INavigationFlightOfferDataProps } from './interfaces'                            
import { getDiscountData, formatDataByServicesType, selectAdministrationFee } from './functions'

此外,我使用 ts-lint 支票排序规则:

 ...
 ordered-imports": [                                                                                                
      true,                                                                                                             
      {                                                                                                                 
        "import-sources-order": "lowercase-first",                                                                      
        "named-imports-order": "lowercase-first"                                                                        
      }                                                                                                                 
    ],
 ...  

并得到错误:

ERROR: 11:1   ordered-imports  Import sources within a group must be alphabetized.
ERROR: 11:10  ordered-imports  Named imports must be alphabetized.
ERROR: 12:1   ordered-imports  Import sources within a group must be alphabetized.
ERROR: 12:10  ordered-imports  Named imports must be alphabetized.

我正在寻找解决此排序错误的解决方案或插件。

在这种情况下,对我来说非常有效 ts-lint --fix -c ./ts-congig.json my-file.ts 命令。