-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESLint与WebStorm、VSCode的集成 #8
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ESLint与WebStorm、VSCode的集成
ESLint属于一种QA工具,是一个ECMAScript/JavaScript语法规则和代码风格的检查工具,可以用来保证写出语法正确、风格统一的代码。
ESLint旨在完全可配置,它的目标是提供一个插件化的javascript代码检测工具。详细配置去官网
ESLint可以和多种IDE进行集成,下面只介绍常用WebStorm和VSCode。支持的集成列表
准备条件
不管跟哪种IDE集成,第一步都是要先安装ESLint,可以本地或全局安装。
npm install eslint --save-dev
或npm install eslint -g
eslint --init
用来生成规则文件。WebStorm
WebStorm有两种方式来配置ESLint,一种是自带的ESLint,一种是ESLint插件。下面只说自带的ESLint配置,插件配置可以看参考文献,写的比较好。
启用ESLint
WebStrom -> Preferences -> Languages and Frameworks -> JavaScript -> Code Quality Tools -> ESLint
在弹出的对话框中勾选Enable,可以看到要填写 Node Interpreter 和 ESLint Package 两项,分别是Node.js和ESLint的可执行文件路径,这也是前面要先安装ESLint的原因。
在编辑器激活ESLint
我想要的效果是在编辑器编码的时候就进行代码检查,而前面一步只是启用了ESLint,还需要在编辑器激活ESLint。WebStrom -> Preferences -> Editor -> Inspections
在弹出的对话框继续JavaScript -> Code quality tools -> ESLint,勾选后Apply生效。
规则文件
ESLint的检查策略依赖于规则文件。
经过上面配置之后ESLint就可以正常使用了。
VSCode
VSCode的集成完全依靠ESLint扩展,ESLint Extension。
参考
The text was updated successfully, but these errors were encountered: