使用自动转换时 tslint 到 eslint 转换错误

问题描述 投票:0回答:2

由于 tslint 即将被弃用,我正在尝试将 tslint 规则转换为 eslint。

这些是我对 tslint 的所有规则。

{
    "defaultSeverity": "error",
    "extends": [
        "tslint:recommended"
    ],
    "jsRules": {},
    "rules": {
      "arrow-parens": false,
      "interface-name": false,
      "interface-over-type-literal": false,
      "max-classes-per-file": false,
      "max-line-length": false,
      "member-access": false,
      "member-ordering": false,
      "no-angle-bracket-type-assertion": false,
      "no-consecutive-blank-lines": [true, 2],
      "no-var-requires": false,
      "object-literal-shorthand": false,
      "object-literal-sort-keys": false,
      "quotemark": [true, "single", "avoid-template", "avoid-escape"],
      "trailing-comma": "never"
    },
    "rulesDirectory": []
}

我已经使用

npx tslint-to-eslint-config
自动生成了 tslint 到 eslint 的转换。 这是自动转换的 eslint 规则

{
    "env": {
        "browser": true,
        "es6": true,
        "node": true
    },
    "extends": [
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "project": "tsconfig.json",
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint",
        "@typescript-eslint/tslint"
    ],
    "rules": {
        "@typescript-eslint/adjacent-overload-signatures": "error",
        "@typescript-eslint/array-type": "error",
        "@typescript-eslint/ban-types": "error",
        "@typescript-eslint/class-name-casing": "error",
        "@typescript-eslint/consistent-type-assertions": "off",
        "@typescript-eslint/consistent-type-definitions": "off",
        "@typescript-eslint/explicit-member-accessibility": [
            "off",
            {
                "accessibility": "explicit"
            }
        ],
        "@typescript-eslint/interface-name-prefix": "off",
        "@typescript-eslint/member-ordering": "off",
        "@typescript-eslint/no-empty-function": "error",
        "@typescript-eslint/no-empty-interface": "error",
        "@typescript-eslint/no-explicit-any": "off",
        "@typescript-eslint/no-misused-new": "error",
        "@typescript-eslint/no-namespace": "error",
        "@typescript-eslint/no-parameter-properties": "off",
        "@typescript-eslint/no-use-before-define": "off",
        "@typescript-eslint/no-var-requires": "off",
        "@typescript-eslint/prefer-for-of": "error",
        "@typescript-eslint/prefer-function-type": "error",
        "@typescript-eslint/prefer-namespace-keyword": "error",
        "@typescript-eslint/quotes": [
            "error",
            "single",
            {
                "avoidEscape": true
            }
        ],
        "@typescript-eslint/triple-slash-reference": "error",
        "@typescript-eslint/unified-signatures": "error",
        "arrow-parens": [
            "off",
            "as-needed"
        ],
        "camelcase": "error",
        "comma-dangle": "error",
        "complexity": "off",
        "constructor-super": "error",
        "dot-notation": "error",
        "eqeqeq": [
            "error",
            "smart"
        ],
        "guard-for-in": "error",
        "id-blacklist": [
            "error",
            "any",
            "Number",
            "number",
            "String",
            "string",
            "Boolean",
            "boolean",
            "Undefined",
            "undefined"
        ],
        "id-match": "error",
        "max-classes-per-file": "off",
        "max-len": "off",
        "new-parens": "error",
        "no-bitwise": "error",
        "no-caller": "error",
        "no-cond-assign": "error",
        "no-console": "error",
        "no-debugger": "error",
        "no-empty": "error",
        "no-eval": "error",
        "no-fallthrough": "off",
        "no-invalid-this": "off",
        "no-multiple-empty-lines": [
            "error",
            {
                "max": 2
            }
        ],
        "no-new-wrappers": "error",
        "no-shadow": [
            "error",
            {
                "hoist": "all"
            }
        ],
        "no-throw-literal": "error",
        "no-trailing-spaces": "error",
        "no-undef-init": "error",
        "no-underscore-dangle": "error",
        "no-unsafe-finally": "error",
        "no-unused-expressions": "error",
        "no-unused-labels": "error",
        "no-var": "error",
        "object-shorthand": "off",
        "one-var": [
            "error",
            "never"
        ],
        "prefer-arrow/prefer-arrow-functions": "error",
        "prefer-const": "error",
        "radix": "error",
        "spaced-comment": "error",
        "use-isnan": "error",
        "valid-typeof": "off",
        "@typescript-eslint/tslint/config": [
            "error",
            {
                "rules": {
                    "jsdoc-format": true,
                    "no-reference-import": true
                }
            }
        ]
    }
}

当我运行

npx eslint .
时,我遇到了大量错误
@typescript-eslint/parser

0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: dist/templates.js.
The file must be included in at least one of the projects provided

我对使用 tslint 或 eslint 还很陌生,我不确定如何准确解决这个问题。 只是想知道我是否遗漏了一些对此至关重要的东西?

提前非常感谢!

eslint tslint
2个回答
1
投票

这是发生的事情:

  1. typescript-eslint 使用您的
    tsconfig.json
    文件读取源文件集合
  2. ESLint 规则使用 typescript-eslint 提供的 TypeScript 功能
  3. 这些 ESLint 规则正在未包含在您的文件中运行
    tsconfig.json

这会导致崩溃,因为正在请求有关 TypeScript 不知道的文件的 TypeScript 信息。

确保您的 ESLint 文件设置为仅在您的

tsconfig.json
中包含的文件上运行,并且此错误应该会消失。


0
投票

我发现了一个在线 tslint 到 eslint 转换器工具,可以帮助您完成迁移过程。这是链接:在线转换器工具

© www.soinside.com 2019 - 2024. All rights reserved.