简体   繁体   中英

Using a different .eslintrc config file for typescript and javascript in VSCode?

I have a project with both JS and TS files (and JSX/TSX). I have a separate .eslintrc.json file for JS vs. TS. I'd like to be able to tell VSCode which eslint config file to use depending on the file extension.

Tried putting the settings in settings.json under the [typescript] field but that didn't work.

I think it should be possible to use 1 file and overrides option:

.eslintrc.js

module.exports = {
    "root": true,
    "plugins": ["@typescript-eslint"],
    "rules": {
        // JavaScript rules
    },
    "overrides": [
        {
            "files": ["*.ts", "*.tsx"],
            "parser": "@typescript-eslint/parser",
            "parserOptions": {
                "project": "./tsconfig.json"
            },
            "plugins": [
                "@typescript-eslint"
            ],
            "rules": {
                // TypeScript rules
            }
        }
    ]
}

And changing workspace settings:

"eslint.validate": [
    {
        "language": "typescript",
        "autoFix": true
    },
    {
        "language": "typescriptreact",
        "autoFix": true
    }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM