TSLINT: Remove Missing Whitespace rule on Import

一曲冷凌霜 提交于 2019-12-06 01:15:01

问题


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?


回答1:


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




回答2:


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"
    ]
}



回答3:


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,




回答4:


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



来源:https://stackoverflow.com/questions/41447602/tslint-remove-missing-whitespace-rule-on-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!