Webstorm下安裝ESLint檢測JS代碼

今天配置下Webstorm下面的Eslint。node

1,先看下本地安裝的Node,NPM版本,2017-11-23日這個節點最新版本。git

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

2,使用Webstorm快捷鍵Alt + F12,進入Terminal窗口,以下圖es6

3,執行全局安裝eslintnpm

     npm install -g eslintapp

4,執行 eslint --init測試

      初始化eslint配置文件,每一步根據本身須要選擇YES or NO,ui

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 文件,spa

5,在本身項目裏,執行 eslint learning/chap02-let.js,eslint

eslint將會根據配置的規則進行JS驗證並在控制檯打印出提示消息code

 

 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.
相關文章
相關標籤/搜索