How to run typescript-eslint on .ts files and eslint on .js files in the same project in VSCode

前端 未结 1 782
暗喜
暗喜 2021-02-20 01:18

I have a mixed codebase with javascript and typescript files. I\'d like to have eslint run on .js files and typescript-eslint run on .ts files in VSCode.

I\'ve managed t

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-20 01:41

    You need to override the configuration to use separate parsers for js and ts files. you can configure .eslintrc.js as below

    module.exports = {
        root: true,    
        extends: [
          'eslint:recommended'
        ],
        "overrides": [
          {
            "files": ["**/*.ts", "**/*.tsx"],
            "env": { "browser": true, "es6": true, "node": true },
            "extends": [
              "eslint:recommended",
              "plugin:@typescript-eslint/eslint-recommended",
              "plugin:@typescript-eslint/recommended"
            ],
            "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" },
            "parser": "@typescript-eslint/parser",
            "parserOptions": {
              "ecmaFeatures": { "jsx": true },
              "ecmaVersion": 2018,
              "sourceType": "module",
              "project": "./tsconfig.json"
            },
            "plugins": ["@typescript-eslint"],
            "rules": {
              "indent": ["error", 2, { "SwitchCase": 1 }],
              "linebreak-style": ["error", "unix"],
              "quotes": ["error", "single"],
              "comma-dangle": ["error", "always-multiline"],
              "@typescript-eslint/no-explicit-any": 0
            }
          }
        ]
      };
    

    Sample Project is here

    0 讨论(0)
提交回复
热议问题