likes
comments
collection
share

eslint在vscode里的配置问题

作者站长头像
站长
· 阅读数 307

一、下载安装

首先在项目中安装eslint插件,在项目里面把他进行install

npm install eslint --save-dev #如果项目没有安装eslint依赖

然后把他重新设置为全局应用安装成功后会在package.json里看到关于eslint的版本号

二、创建eslint rule config文件

建议使用npx进行安装,因为npx可以比npm更能专注于模块,npm主要用于installnpx eslint --init #生成eslint文档

三、学习eslint配置规则

rules: no-console: 2 # 禁止使用console,如果使用了console则编译错误 no-debugger: 1 # 禁止使用debugger,如果使用了debugger则警告

从上面可以知道,规则就是 属性:规则选项no-console: 2

规则选项有0,1,2;或off、warn、error。 "off" or 0 - turn the rule off "warn" or 1 - turn the rule on as a warning (doesn't affect exit code) "error" or 2 - turn the rule on as an error (exit code will be 1)这样可以进行eslint的配置需要什么样的规则就

属性:规则

就完事了。