How to upgrade the version of ESLint used in Visual Studio 2019?

折月煮酒 提交于 2020-12-06 03:48:36

问题


I am using ESLint with Visual Studio 2019. The integration works well, I can see the ESLint errors directly in the IDE.

But when I add more rules to my config file, like no-async-promise-executor, I get errors like

(ESLint) Definition for rule 'no-async-promise-executor' was not found C:\Work\GatewayServer\Multicheck.GW.Web (tsconfig or jsconfig project)

It turns out that the ESLint version is a bit outdated. In C:\Users\username\AppData\Local\Microsoft\TypeScript\ESLint\package.json, we can see "eslint": "4.19.1".

I have installed the latest (6.7.2) version of ESLint on my computer, and it is in the PATH.

How can I force Visual Studio to use an up-to-date ESLint? I am using VS2019 16.4.2.


回答1:


After some research, I was able to find specific documentation:

Visual Studio will use its installation of ESLint 4 by default. However, if you would like to use a different version, Visual Studio will pick up a local installation of ESLint and use it instead. In particular, if any parent directory of the file you want to be linted contains a package.json that lists ESLint as a dependency, as well as a node_modules folder with an installation of ESLint, then it will use that copy of the linter.

The solution was then to have a package.json file at the root of the project:

{
  ...
  "dependencies": {
    ...
    "eslint": "6.7.2"
  }
}


来源:https://stackoverflow.com/questions/59422834/how-to-upgrade-the-version-of-eslint-used-in-visual-studio-2019

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