TypeScript在Visual Studio Code中的ESLint错误和警告不起作用

8

我在我的项目中使用了eslint,但是我决定迁移到@typescript-eslint,并使用它进行了迁移。

为了进行迁移,我使用了这里提供的提示:https://github.com/typescript-eslint/tslint-to-eslint-config。这个链接在typescript-eslint页面内提供了从tslint迁移到eslint的指导。

然而,在进行完迁移之后,Visual Studio Code不再显示错误标记和警告。我卸载了tslint扩展并更新了eslint,但还是无法解决问题。如果我运行eslint检查命令,它可以完美地工作。但好像Visual Studio Code忽略了项目中的eslint。

如果有人能帮助我,我将不胜感激。

我的软件包版本:

"eslint": "^6.7.2",
"@typescript-eslint/eslint-plugin": "^2.12.0"
"@typescript-eslint/eslint-plugin-tslint": "^2.11.0",
"@typescript-eslint/parser": "^2.12.0",
"prettier-eslint": "^9.0.1",
"typescript": "^3.4.5"

我的eslint.js:
module.exports = {
    "env": {
        "browser": true,
        "es6": true,
        "node": true
    },
    "extends": [],
    "ignorePatterns": [],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "project": "tsconfig.json",
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint",
        "@typescript-eslint/tslint"
    ],
    "rules": {
        "@typescript-eslint/class-name-casing": "error",
        "@typescript-eslint/consistent-type-definitions": "error",
        "@typescript-eslint/explicit-member-accessibility": [
            "off",
            {
                "accessibility": "explicit"
            }
        ],
        "@typescript-eslint/indent": "warn",
        "@typescript-eslint/member-ordering": [
            "error",
            {
                "default": [
                    "public-static-field",
                    "private-static-field",
                    "public-instance-field",
                    "private-instance-field",
                    "public-static-method",
                    "private-static-method",
                    "public-instance-method",
                    "private-instance-method"
                ]
            }
        ],
        "@typescript-eslint/no-empty-function": "off",
        "@typescript-eslint/no-empty-interface": "error",
        "@typescript-eslint/no-explicit-any": "warn",
        "@typescript-eslint/no-inferrable-types": "error",
        "@typescript-eslint/no-misused-new": "error",
        "@typescript-eslint/no-non-null-assertion": "error",
        "@typescript-eslint/prefer-function-type": "error",
        "@typescript-eslint/quotes": [
            "error",
            "single", { "allowTemplateLiterals": true }
        ],
        "@typescript-eslint/semi": [
            "error",
            "always"
        ],
        "@typescript-eslint/type-annotation-spacing": "error",
        "@typescript-eslint/unified-signatures": "error",
        "camelcase": "off",
        "constructor-super": "error",
        "curly": "error",
        "dot-notation": "off",
        "eol-last": "error",
        "eqeqeq": [
            "error",
            "smart"
        ],
        "guard-for-in": "error",
        "id-blacklist": "off",
        "id-match": "off",
        "max-len": [
            "error",
            {
                "code": 200
            }
        ],
        "no-bitwise": "error",
        "no-caller": "error",
        "no-console": [
            "error",
            {
                "allow": [
                    "log",
                    "dirxml",
                    "warn",
                    "error",
                    "dir",
                    "timeLog",
                    "assert",
                    "clear",
                    "count",
                    "countReset",
                    "group",
                    "groupCollapsed",
                    "groupEnd",
                    "table",
                    "Console",
                    "markTimeline",
                    "profile",
                    "profileEnd",
                    "timeline",
                    "timelineEnd",
                    "timeStamp",
                    "context"
                ]
            }
        ],
        "no-debugger": "error",
        "no-empty": "off",
        "no-eval": "error",
        "no-fallthrough": "error",
        "no-new-wrappers": "error",
        "no-shadow": [
            "error",
            {
                "hoist": "all"
            }
        ],
        "no-throw-literal": "error",
        "no-trailing-spaces": "error",
        "no-undef-init": "error",
        "no-underscore-dangle": "off",
        "no-unused-expressions": "error",
        "no-unused-labels": "error",
        "no-var": "error",
        "prefer-const": "error",
        "radix": "error",
        "spaced-comment": ["error", "always", { "markers": ["#region", "#endregion"] }],
        "valid-typeof": "error",
        "@typescript-eslint/tslint/config": [
            "error",
            {
                "rules": {
                    "component-class-suffix": true,
                    "component-selector": [
                        true,
                        "element",
                        "app",
                        "kebab-case"
                    ],
                    "directive-class-suffix": true,
                    "directive-selector": [
                        true,
                        "attribute",
                        "app",
                        "camelCase"
                    ],
                    "import-blacklist": true,
                    "import-spacing": true,
                    "no-host-metadata-property": true,
                    "no-input-rename": true,
                    "no-inputs-metadata-property": true,
                    "no-output-rename": true,
                    "no-outputs-metadata-property": true,
                    "one-line": true,
                    "use-lifecycle-interface": true,
                    "use-pipe-transform-interface": true,
                    "whitespace": true
                }
            }
        ]
    },
    "settings": {
        "import/parsers": {
            "@typescript-eslint/parser": [".ts", ".tsx"],
        },
        "import/resolver": {
            "typescript": {},
        },
    }
};

我的settings.json文件:

{
    "git.ignoreMissingGitWarning": true,
    "editor.minimap.enabled": false,
    "workbench.colorTheme": "Monokai",
    "editor.autoIndent": false,
    "editor.detectIndentation": false,
    "[html]": {
        "editor.defaultFormatter": "vscode.html-language-features"
    },
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "typescript.updateImportsOnFileMove.enabled": "always",
    "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
    "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
    "eslint.autoFixOnSave": true,
    "editor.formatOnSave": true,
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
            "language": "typescript",
            "autoFix": true
        },
        {
            "language": "typescriptreact",
            "autoFix": true
        }
    ]
}
2个回答

2
这可能是因为 ESLint 配置出现了错误。VSCode 插件将保持无声地不工作,但您可以在 shell 中运行 ESLint 来查看有关错误的详细输出:
eslint . --ext .ts

您可能没有它在您的环境中,所以您需要将其作为npm脚本运行:

package.json

...
"lint": "eslint . --ext .ts",
...

npm run lint

-1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接