SoominHan / import-sorter

MIT License
87 stars 28 forks source link

Prettier multiline imports #85

Open Xarli9 opened 3 years ago

Xarli9 commented 3 years ago

Multi-line amounts I think are not very nice. The import { is always in an isolated line and it is difficult to identify where an amount begins and ends.

import {
    css, CSSResult, customElement, html, property,
    TemplateResult,
} from 'lit-element';
import {
    css, CSSResult, customElement, html, property,
    TemplateResult,
} from 'lit-element';
import {
    css, CSSResult, customElement, html, property,
    TemplateResult,
} from 'lit-element';

I think it would be prettier to allow the elements be started to the first line, and allow the } from '../path/foler/filnema not be on a new line.

import { css, CSSResult, customElement, html, property,
         TemplateResult, } from 'lit-element';
import { css, CSSResult, customElement, html, property,
         TemplateResult, } from 'lit-element';
import { css, CSSResult, customElement, html, property,
         TemplateResult, } from 'lit-element';

or

import { css, CSSResult, customElement, 
         html, property, TemplateResult, 
         } from 'lit-element';
import { css, CSSResult, customElement, 
         html, property, TemplateResult, 
         } from 'lit-element';
import { css, CSSResult, customElement, 
         html, property, TemplateResult, 
         } from 'lit-element';

In this cases, it is easier to identify each of the imports, as there is indentation until the next import. And we save lines of code.

I propose to use the following configuration options to indicate whether the line break should be added, in the first and last line, to the multi-line imports.

{
  "importSorter.importStringConfiguration.newLineAfterStartingBracket": false,
  "importSorter.importStringConfiguration.newLineBeforeEndingBracket": false,
  "importSorter.importStringConfiguration.tabSizeInNewLineBeforeEndingBracket": 9,
}
Navipro70 commented 2 years ago

Add next property: "importSorter.importStringConfiguration.maximumNumberOfImportExpressionsPerLine.type": "newLineEachExpressionAfterCountLimitExceptIfOnlyOne",