TSLINT: Remove Missing Whitespace rule on Import
Asked Answered
K

4

8

TSLint requires an import like this...

import { RouterModule } from "@angular/router";

However, my IDE imports everything like this...

import {RouterModule} from "@angular/router";

Now I am sure I can configure the IDE to change this but it would seem to be easier just to turn off this rule. However, I am new to linting and I am not sure where to find the right rule to disable. I still want some enforcement of whitespace (properties etc) but just not this one.

What is the proper setting to turn off just this rule?

Kowalewski answered 3/1, 2017 at 16:8 Comment(1)
Which IDE do you use? it can certainly be changed in some if not allChecker
C
8

There is not a rule targeting the specific case you describe, but there is a more general rule: Whitespace

And in the case you are using IntelliJ or Webstorm the editor settings can be changed at: Settings -> Editor -> Code Style -> JavaScript -> Spaces -> Within ES6 Import/export braces

Checker answered 3/1, 2017 at 16:27 Comment(0)
P
4

To deactivate a rule, you need to modify your tslint.json.

You have to remove check-module from the array in the whitespace property.

See the documentation:

"check-module" checks for whitespace in import & export statements.

So at the end you should have something like that:

tslint.json (other rules not appearing)

{
 "rules": {
   "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type",
      "check-typecast"
    ]
}
Polycotyledon answered 3/1, 2017 at 16:43 Comment(0)
D
3

I have

"whitespace": [
  true,
  "check-branch",
  "check-decl",
  "check-operator",
  "check-separator",
  "check-type",
  "check-typecast"
],
"import-destructuring-spacing": true,
"import-spacing": true

and in IJ/WebStorm, enable it in Prefs > Editor > Code Style > TypeScript > Spaces > Within > ES6 import/export braces

Dandridge answered 31/7, 2017 at 18:22 Comment(0)
K
2

I Started this before the previous responses. The first one is great for IJ but that wasn't really the question I asked. The other one Is correct and what I came to as well...

"whitespace": [
  true,
  "check-branch",
  "check-decl",
  "check-operator",
  "check-separator",
  "check-type"
]

As long as you leave out "check-module" you shouldn't get those messages.

But there is also another little nuance if you are using Angular. Angular declares this rule as well. So even if you disable this in TS lint the Angular Style guide will cause an error as well if you are using Codealyzer. Again the first response of changing IJ is still valid (Although my mind is blown IJ doesn't have proper defaults for TS). In that case you will need to make sure to include...

"import-destructuring-spacing": false,

Kowalewski answered 3/1, 2017 at 16:49 Comment(3)
Using Visual Studio Code for Typescript is a lifesaver. Basically, the same guys doing typescript have done Visual Studio Code (kind of), so you can't go wrong with it.Polycotyledon
Does Visual Studio run on Debian? I honestly don't know.Kowalewski
Visual Studio Code runs on Ubuntu 14.04 (and even is open source), unlike regular Visual StudioRubie

© 2022 - 2024 — McMap. All rights reserved.