amatiasq / vsc-sort-imports

Sort ES6 imports automatically.
ISC License
58 stars 24 forks source link

Can I break up long imports into multiple lines? #21

Closed natesilva closed 6 years ago

natesilva commented 6 years ago

If I have:

import { functionB, functionC, functionG, functionA, functionH, functionF, functionE, functionD, functionI } from 'somewhere';

Can I break that into separate lines when sorting, maybe based on line length?

import { functionA, functionB, functionC, functionD } from 'somewhere';
import { functionE, functionF, functionG, functionH } from 'somewhere';
fsmaia commented 6 years ago

I think this syntax is a little unusual, and it's usually blocked by ESLint's import/no-duplicates rule.

Since splitting into one member per line is not a problem, may I suggest you to use tools like EditorConfig and Prettier to handle format? These ones, specially Prettier, can enforce a code style in terms of legibility, and eliminate the need to actively care about it.

natesilva commented 6 years ago

We’re using TSLint, and we don’t have the no-duplicate-imports rule enabled. We have a database module from which we might import a dozen or more things. Either we have very long lines, or, with Prettier, we get this yuckiness:

import {
  functionA,
  functionB,
  functionC,
  functionD,
  functionE,
  functionF,
  functionG,
  functionH
} from 'somewhere';

I’ll check out the settings in EditorConfig and Prettier to see if it can be improved.

amatiasq commented 6 years ago

In my opinion having two imports for the same module is confusing, giving the idea that the imports are coming from different modules.

The multiline import is a standard solution for this situations.

Anyway I'll leave this open for discussion.

amatiasq commented 6 years ago

Closed due to lack of discussion :)