首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用自动转换技术实现tslint到eslint会话错误

使用自动转换技术实现tslint到eslint会话错误
EN

Stack Overflow用户
提问于 2020-02-03 22:14:46
回答 1查看 2.1K关注 0票数 1

由于tslint很快就会被废弃,我正在尝试将tslint规则转换为eslint。

,这些都是我对tslint.的规则

代码语言:javascript
复制
{
    "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规则

代码语言:javascript
复制
{
    "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会产生大量错误

代码语言:javascript
复制
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非常陌生,而且我也不知道如何确切地解决这个问题。只是想知道我是不是错过了对这件事至关重要的东西?

提前谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-16 04:47:26

下面是正在发生的事情:

  1. typescript-eslint使用您的tsconfig.json文件来读取源文件集合中的
  2. ESLint rules使用由类型记录-ESLint
  3. 提供的TypeScript特性这些ESLint规则正在运行在不包含在tsconfig.json

中的文件上。

这会导致崩溃,因为TypeScript信息是关于TypeScript不知道的文件的。

确保您的ESLint文件仅在包含在tsconfig.json中的文件上运行,此错误应该消失。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60047917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档