删除一些 tslint 规则

Remove some tslint rules

我需要从 tslint.json 中删除以下 tslint 规则。

  1. 文件应以换行符结尾
  2. 尾随空格
  3. 缺少空格
  4. " 应该是 '

为了删除空格,我通过查看 .

删除了 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
  }
}

在你的 tsLint 中删除:

"no-trailing-whitespace": true,

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

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

"eofline": true,

1.file 应该换行结束

"eofline": true,

2.trailing 空格

"no-trailing-whitespace": false,

3.Missing 空格

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

4." 应该是 '

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

以下是我在 tslint.json 文件所在的根文件夹中执行此操作的方法:

但是先把"no-trailing-whitespace": true改成false在tslint.json

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代码时它都会提示你安装推荐:
// 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": {...