TSLint: Too many spaces before 'from' (import-spacing)
Asked Answered
B

1

8

I'm using WebStorm and trying to keep such code style:

enter image description here

But when I do that, TSLint underlines my spaces and gives me the hint:

"Too many spaces before 'from' (import-spacing)".

My question is: Is there a way to keep this code style without underlying? I also googled the problem, but with no success.

And I don't want to disable TSLint totally, just this rule for spaces.

Butanone answered 22/8, 2017 at 22:33 Comment(7)
You can disable the TSLint rule, but have fun maintaining that. They will get out of alignment eventually, you're probably better off breaking on the braces like import {\n Component \n} from 'foo'.Exine
@ssube, thanks for your answer! But how can i disable this rule? "better off breaking on the braces...". I don't trying to break off something between braces, i'm trying to fix underlying spaces after bracesButanone
It is a bad indenting style, plain and simple. Every time an import is added that is longer than what you already have, you need to update all import lines. Every time you remove an import from the longest import line, you also need to change all import lines. My suggestion: adopt a coding style that survives modification and refactoring.Oceania
@Laoujin, you're right. Isn't there a plugin/extension to automate this routine?Butanone
One would hope that a commercial product like Webstorm would offer this kind of functionality. Perhaps it's possible to do with a tool like Prettier (github.com/prettier/prettier)Oceania
I believe it allows extra spaces before the closing brace. At least it does for me.Pyrotechnics
Also, Leonardo Machado Carreiro's Smart Column Indenter for TypeScript appears to know that it can insert spaces before the closing braces.Pyrotechnics
D
12

In your tslint.json file, add this rule:

{
  "rules": {
    "import-spacing": false
  }
}

See also: https://palantir.github.io/tslint/rules/import-spacing/

enter image description here

Detestable answered 23/8, 2017 at 0:11 Comment(1)
People from the future, webstorm has a setting so you don't need to forgo that rule, i.imgur.com/ROL7PcX.pngGrainy

© 2022 - 2024 — McMap. All rights reserved.