feiyue-zh

今天配置下Webstorm下面的Eslint,

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

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

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

 执行全局安装eslint

npm install -g eslint

执行 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 6 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 文件,

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

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

 

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

Oops! Something went wrong! :(

ESLint: 4.11.0.
ESLint couldn't find the plugin "eslint-plugin-jsx-a11y". This can happen for a couple different reasons:

1. 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.

2. 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.

 

相关文章: