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

邮差的信 提交于 2020-08-05 04:14:19

问题


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 to configure my .eslintrc.json file to get typescript-eslint to run on .ts files. The problem is that it also ends up running typescript-eslint on .js files, instead of plain old eslint.

This seems like it should be simple and fairly common, but I haven't been able to find a solution despite searching all over the internet.


回答1:


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



来源:https://stackoverflow.com/questions/57597142/how-to-run-typescript-eslint-on-ts-files-and-eslint-on-js-files-in-the-same-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!