Webstorm下安装ESLint检测JS代码

时间:2023-01-30 20:36:23

今天配置下Webstorm下面的Eslint。

1,先看下本地安装的Node,NPM版本,2017-11-23日这个节点最新版本。

>node -v
v8.9.1
>npm -v
5.5.

2,使用Webstorm快捷键Alt + F12,进入Terminal窗口,如下图

Webstorm下安装ESLint检测JS代码

3,执行全局安装eslint

     npm install -g eslint

Webstorm下安装ESLint检测JS代码

4,执行 eslint --init

初始化eslint配置文件,每一步根据自己需要选择YES or NO,

C:\Users\XXXXXXX\WebstormProjects\es6tutorial>eslint --init
? How would you like to configure ESLint? Answer questions about your style
? Are you using ECMAScript features? Yes
? Are you using ES6 modules? Yes
? Where will your code run? Browser
? Do you use CommonJS? No
? Do you use JSX? No
? What style of indentation do you use? Tabs
? What quotes do you use for strings? Single
? What line endings do you use? Unix
? Do you require semicolons? Yes
? What format do you want your config file to be in? JavaScript

最后将会生成一份.eslintrc.js 文件,

5,在自己项目里,执行 eslint learning/chap02-let.js,

eslint将会根据配置的规则进行JS验证并在控制台打印出提示消息

Webstorm下安装ESLint检测JS代码

Webstorm下安装ESLint检测JS代码

PS:我在安装测试过程中,发生如下错误,大概意思是:要确保ESLint全局安装。

Oops! Something went wrong! :(

ESLint: 4.11..
ESLint couldn't find the plugin "eslint-plugin-jsx-a11y". This can happen for a couple different reasons: . If ESLint is installed globally, then make sure eslint-plugin-jsx-a11y is also installed globally. A globally-installed ESLint cannot find a
locally-installed plugin. . If ESLint is installed locally, then it's likely that the plugin isn't installed correctly. Try reinstalling by running the following: npm i eslint-plugin-jsx-a11y@latest --save-dev If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.