Tslint.json之配置解決WebStrom中的紅色問題

一 : 前言
程序員

最近從新學習了一下Web , 學習的新框架Angular . 由於本人比較喜歡用WebStrom . 可是因爲一個潔癖 , 引起了一系列的操做.先看看工程:express

B01.png

都在飄紅啊 , 但這些紅色的真不是Bug , 我在VS Code中打開本本項目 , 以下:json

B02.png

程序員都有潔癖 , 爆紅是很差的.....................框架

二 : 解決之路curl

Ⅰ ,  使用VS Codeide

VS Code存在一個坑爹的問題 , 自動引入 ( import ) 問題 , 搜了半天的百度 , 終於知道有一個叫 "Auto Import"的插件 , 安裝上了.學習

可是發現了一個始料未及的Bug:ui

雖然自定義的類可使用Auto Import自動添加引用 , 可是發現了FormsModule等無法自動引用 , 這插件是我不會用 , 仍是咋的 , 請知曉此玄機的讀者不吝賜教.url

Ⅱ , 繼續WebStromspa

WebStrom中的Alt_Enter一直是個人最愛 , 能夠自動引用 . 在搜索百度後 , 終於一個個的知道爆紅的緣由了.

一部分出在 Tslint.json配置文件中 , 一部分出在Git(版本)控制中.

① , Tslint.json(Angular項目根目錄下)

規定了Tslint.json的各類代碼規範 , 也是有心了 . 可是規定的太嚴格 , 致使了各類不自在啊. 現逐一解決:

1 , 類型報紅 , 以下

B03.png

說的是 , 能夠根據變量words的值"Aoaudly"來肯定words就是一個string , 因此程序員將words定義爲string類型 (words : string)那是畫蛇添足!

解決 : 

B04.png


2 , 單/雙引號報紅 , 以下

B05.png

TSlint.json默認嚴格限制了單/雙引號的使用

解決 :

B06.png


3 , 空格報紅 , 以下

B07.png

TsLint.json默認嚴格規定了空格的使用

解決:

B08.png

4 , 特殊類型報紅 , 以下

B09.png

解決:

B10.png


看看結果:

B11.png

② , Git(版本)控制

在 settings -> Version Control中

B12.png


三 : 大結局

B13.png


四 : Tslint.json的配置

{
  "extends": "tslint:recommended",
  "rulesDirectory": [
    "codelyzer"
  ],
  "rules": {
    "array-type": false,
    "arrow-parens": false,
    "deprecation": {
      "severity": "warn"
    },
    "import-blacklist": [
      true,
      "rxjs/Rx"
    ],
    "interface-name": false,
    "max-classes-per-file": false,
    "max-line-length": [
      true,
      140
    ],
    "member-access": false,
    "member-ordering": [
      false,
      {
        "order": [
          "static-field",
          "instance-field",
          "static-method",
          "instance-method"
        ]
      }
    ],
    "no-consecutive-blank-lines": false,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-empty": false,
    "no-inferrable-types": [
      true,
      "ignore-params",
      "ignore-properties"
    ],
    "no-non-null-assertion": true,
    "no-redundant-jsdoc": true,
    "no-switch-case-fall-through": true,
    "no-use-before-declare": true,
    "no-var-requires": false,
    "object-literal-key-quotes": [
      true,
      "as-needed"
    ],
    "object-literal-sort-keys": false,
    "ordered-imports": false,
    "quotemark": [
      false,
      "single"
    ],
    "trailing-comma": false,
    "no-output-on-prefix": true,
    "use-input-property-decorator": true,
    "use-output-property-decorator": true,
    "use-host-property-decorator": true,
    "no-input-rename": true,
    "no-output-rename": true,
    "use-life-cycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": true,
    "directive-class-suffix": true,
    "class-name" : false,
    "variable-name" : false,
    "one-line" : true,
    "no-boolean-literal-compare" : false,
    "no-angle-bracket-type-assertion" : false,
    "binary-expression-operand-order" : false,
    "arrow-return-shorthand" : false,
    "jsdoc-format" : false,
    "interface-over-type-literal" : false,
    "no-irregular-whitespace" : false,
    "number-literal-format" : false,
    "whitespace" : false,
    "curly" : false,
    "typedef-whitespace":[
      false,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      },
      {
      "call-signature": "onespace",
      "index-signature": "onespace",
      "parameter": "onespace",
      "property-declaration": "onespace",
      "variable-declaration": "onespace"
      }
    ],
    "ban-types": [
      false,
      [
        "Object",
        "Use {} instead."
      ],
      ["String"]
    ],
    "prefer-const": false,
    "no-trailing-whitespace": false,
    "comment-format": false
  }
}
相關文章
相關標籤/搜索