Ошибка разговора от tslint до eslint при использовании автоматического конвертирования - PullRequest
0 голосов
/ 04 февраля 2020

Поскольку 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": []
}

Я автоматически сгенерировал преобразование tslint в eslint, используя npx tslint-to-eslint-config. И это автоматически преобразованные правила 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, и я не уверен, как именно решить эту проблему. Просто интересно, не упускаю ли я что-то решающее для этого?

Заранее большое спасибо!

1 Ответ

0 голосов
/ 16 февраля 2020

Вот что происходит:

  1. typcript-eslint использует ваш файл tsconfig.json для чтения в коллекции исходных файлов
  2. Правила ESLint используют функции TypeScript, предоставляемые typescript-eslint
  3. Эти правила ESLint выполняются для файла, который не включен в ваш tsconfig.json

Это вызывает cra * sh, поскольку запрашивается информация TypeScript о файле, который TypeScript не знает о.

Убедитесь, что файл ESLint настроен на запуск только для файлов, включенных в tsconfig.json, и эта ошибка должна исчезнуть go.

...