3

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

为了进行交流,我使用了此处提供的提示:https ://github.com/typescript-eslint/tslint-to-eslint-config 。此链接位于 typescript-eslint 页面内,用于指导从 tslint 到 eslint 的切换。

但是,在进行切换后,Visual Studio 代码不再显示错误标记和警告。我卸载了 tslint 扩展并更新了 eslint。但我无法让它工作。如果我运行 eslint check 命令,它可以完美运行。但是好像视觉代码忽略了项目中的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
        }
    ]
}
4

2 回答 2

1

这可能只是因为 ESLint 配置产生了错误。VSCode 插件不会一直默默地工作,但你可以在 shell 中运行 ESLint 来查看错误输出:

eslint . --ext .ts

您的环境中可能没有它,因此您必须将其作为 npm 脚本运行:

package.json

...
"lint": "eslint . --ext .ts",
...
npm run lint
于 2021-01-06T11:46:30.627 回答
-1

我发现当我在同一个存储库中有多个项目时出现问题,因为我在这里计算:https ://github.com/microsoft/vscode-eslint/issues/856#issuecomment-567952628

最后问题是vscode中的eslint版本错误。

于 2019-12-20T16:59:08.497 回答