5

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.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Octodone
  • 515
  • 6
  • 13

1 Answers1

4

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
    }
]
Alex
  • 59,571
  • 22
  • 137
  • 126
  • Hey Alex, thanks for your response. Unfortunately, I'm using the `extends` directive in my `.eslintrc.json` file and it doesn't look like I can put that in the overrides section (but I want different `extends` for my js vs ts files). – Octodone Aug 08 '19 at 03:02
  • 1
    I thought `extends` supports `overrides` https://github.com/eslint/eslint/issues/8813 – Alex Aug 08 '19 at 13:41
  • 1
    You are right. As of version 6, I was on version 5. Thanks, accepted your answer. – Octodone Aug 09 '19 at 03:10