简体   繁体   English

TSLINT:删除导入时丢失的空格规则

[英]TSLINT: Remove Missing Whitespace rule on Import

TSLint requires an import like this... TSLint需要像这样导入......

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

However, my IDE imports everything like this... 但是,我的IDE会导入这样的所有内容......

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. 现在我确信我可以配置IDE来改变它,但是关闭这个规则似乎更容易。 However, I am new to linting and I am not sure where to find the right rule to disable. 但是,我是linting的新手,我不知道在哪里可以找到正确的禁用规则。 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? 关闭此规则的正确设置是什么?

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 在使用IntelliJ或Webstorm的情况下,可以在以下位置更改编辑器设置:设置 - >编辑器 - >代码样式 - > JavaScript - >空格 - >在ES6内导入/导出括号

To deactivate a rule, you need to modify your tslint.json. 要停用规则,您需要修改tslint.json。

You have to remove check-module from the array in the whitespace property. 您必须从whitespace属性中的数组中删除check-module

See the documentation: 查看文档:

"check-module" checks for whitespace in import & export statements. “check-module”检查导入和导出语句中的空格。

So at the end you should have something like that: 所以最后你应该有类似的东西:

tslint.json (other rules not appearing) tslint.json (其他规则没有出现)

{
 "rules": {
   "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type",
      "check-typecast"
    ]
}

I Started this before the previous responses. 我是在之前的回复之前开始的。 The first one is great for IJ but that wasn't really the question I asked. 第一个对IJ很有用,但那不是我问的问题。 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. 只要您省略"check-module" ,就不应该收到这些消息。

But there is also another little nuance if you are using Angular. 但是如果你使用Angular,还有一点细微差别。 Angular declares this rule as well. Angular也宣布了这条规则。 So even if you disable this in TS lint the Angular Style guide will cause an error as well if you are using Codealyzer. 因此,即使您在TS lint中禁用此功能,如果您使用的是Codealyzer,Angular Style指南也会导致错误。 Again the first response of changing IJ is still valid (Although my mind is blown IJ doesn't have proper defaults for TS). 同样,改变IJ的第一个响应仍然有效(虽然我的想法很糟糕,IJ没有适当的TS默认值)。 In that case you will need to make sure to include... 在这种情况下,您需要确保包括......

"import-destructuring-spacing": false,

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 在IJ / WebStorm中,在Prefs> Editor> Code Style> TypeScript> Spaces> Within> ES6 import / export braces中启用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM