1、全局安装eslint
打开终端,运行npm install eslint -g全局安装ESLint。
2、vscode安装插件 eslint
3、vscode安装插件 chinese (汉化vscode)
4、vscode 扩展设置: 文件-首选项-拓展-eslint -在settings-json中编辑
{
"workbench.iconTheme": "material-icon-theme",
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
//配置eslint
"eslint.autoFixOnSave": true, // 启用保存时自动修复,默认只支持.js文件
"eslint.validate": [
"javascript", // 用eslint的规则检测js文件
{
"language": "vue", // 检测vue文件
"autoFix": true // 为vue文件开启保存自动修复的功能
},
{
"language": "html",
"autoFix": true
},
],
}
5、项目目录里修改.eslitrc.js配置 文件
module.exports = {
root: true,
globals: { wx: true },
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// required to lint *.wpy files
plugins: [
'html'
],
settings: {
'html/html-extensions': ['.html', '.wpy']
},
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'space-before-function-paren': 0
}
}