Webstorm下安裝ESLint檢測JS代碼


今天配置下Webstorm下面的Eslint。

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

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

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

3,執行全局安裝eslint

     npm install -g eslint

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

5,在自己項目里,執行 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.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM