import-js icon indicating copy to clipboard operation
import-js copied to clipboard

append to import list?

Open cj opened this issue 6 years ago • 3 comments

When you have groupImports: false and sortImport: false, any new import is prepended to the top of the file. If this was being done manually you'd normally always append it to your imports like:

import old from 'old'
import new from 'new'

and not this, which is the current functionality:

import new from 'new'
import old from 'old'

Maybe a new option called newImportsDirection, so you can choose? i.e. newImportsDirection: 'append' would be a good way to solve this issue?

cj avatar Jul 12 '17 20:07 cj

Maybe new imports should always be added to the bottom when sorting and grouping are turned off? I can't really see a use case for adding them to the top. I probably should've done this when I added the 'sortImports' option :P

dabbott avatar Jul 14 '17 14:07 dabbott

In lib/ImportStatements.js reverse the result in the _toGroups() with .reverse()

let result = partition( importsArray, (importStatement: ImportStatement): boolean => !importStatement.isParsedAndUntouched(), ).reverse();

ivangeorgiew avatar Nov 30 '17 01:11 ivangeorgiew

@ivangeorgiew do you want to push that as a PR? I'm happy to review and merge.

trotzig avatar Nov 30 '17 08:11 trotzig