簡體   English   中英

刪除一些 tslint 規則

[英]Remove some tslint rules

我需要從我的 tslint.json 中刪除以下 tslint 規則。

  1. 文件應以換行符結尾
  2. 尾隨空格
  3. 缺少空格
  4. “ 應該 '

為了刪除空格,我通過查看這個issue刪除了check-type

但是當我在 cli 上運行ng lint命令時仍然出現錯誤。 任何人都知道如何從我的 tslint.json 文件中刪除上述規則?

tslint.json

    {
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
    "arrow-return-shorthand": true,
    "callable-types": true,
    "class-name": true,
    "comment-format": [
      false,
      "check-space"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "import-blacklist": [
      true,
      "rxjs",
      "rxjs/Rx"
    ],
    "import-spacing": true,
    "indent": [
      false,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "label-position": true,
    "max-line-length": [
      true,
      200
    ],
    "member-access": false,
    "member-ordering": [
      true,
      {
        "order": [
          "static-field",
          "instance-field",
          "static-method",
          "instance-method"
        ]
      }
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-super": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-eval": true,
    "no-inferrable-types": [
      true,
      "ignore-params"
    ],
    "no-misused-new": true,
    "no-non-null-assertion": true,
    "no-shadowed-variable": true,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": true,
    "no-unnecessary-initializer": true,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": true,
    "semicolon": [
      true,
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "typeof-compare": true,
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      false,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],
    "directive-selector": [
      true,
      "attribute",
      "app",
      "camelCase"
    ],
    "component-selector": [
      true,
      "element",
      "app",
      "kebab-case"
    ],
    "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,
    "invoke-injectable": true
  }
}

1.file 應該以新行結尾

"eofline": true,

2.尾隨空格

"no-trailing-whitespace": false,

3.缺少空格

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

4." 應該是 '

"quotemark": [
  true,
  "single"
],

這是我在我的 tslint.json 文件所在的根文件夾中執行此操作的方法:

但首先在 tslint.json 中將"no-trailing-whitespace": true更改為false

tslint 只會警告你。 Prettier 強制執行它。 您可能想查看更漂亮的文檔。 我花了一段時間來微調我的。 現在我只是在我的每個應用程序中都使用它。

  1. 在我的.editorconfig文件中,每個新的 Angular 應用程序都有以下內容:
 # Editor configuration, see http://editorconfig.org root = true [*] charset = utf-8 indent_style = space indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true [*.md] max_line_length = off trim_trailing_whitespace = false
  1. 使用更漂亮。 使用 .prettierrc 文件:
 { "arrowParens": "avoid", "bracketSpacing": true, "endOfLine": "auto", "htmlWhitespaceSensitivity": "strict", "semi": true, "singleQuote": true, "tabWidth": 2, "trailingComma": "all", "useTabs": false }
  1. extensions.json文件夾中的vscode中(每當您啟動 vs code 時,它都會提示您安裝建議:
 // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp // List of extensions which should be recommended for users of this workspace. { "recommendations": [ "Angular.ng-template", "DavidAnson.vscode-markdownlint", "eamodio.gitlens", "EditorConfig.EditorConfig", "esbenp.prettier-vscode", "mike-co.import-sorter", "ms-vscode.vscode-typescript-tslint-plugin" ], "unwantedRecommendations": [ "amatiasq.sort-imports", "eg2.tslint", "HookyQR.beautify" ] }
  1. package.json添加這些然后執行npm install
 "prettier": "1.18.2", "protractor": "5.4.2", "tslint-config-prettier": "1.18.0", "tslint-consistent-codestyle": "1.16.0", "tslint-plugin-prettier": "2.0.1",
  1. 在 tslint.json 中(使用下面的代碼,如果你沒有在上面添加#4,你會得到一個警告,指出它們丟失了,並且惱人的黃色代碼下划線:
 { "defaultSeverity": "error", "extends": [ "tslint:latest", "tslint-config-prettier", "tslint-consistent-codestyle" ], "rules": {...

在您的 tsLint 中刪除:

"no-trailing-whitespace": true,

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

"quotemark": [ true, "single" ],

"eofline": true,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM