一、安装eslint
二、vscode全局配置
2.1 打开设置
2.2 打开 settings.json
2.3 在settings.json中添加eslint配置
{
"code-runner.runInTerminal": true,
"eslint.format.enable": true,
// 以下是eslint 配置
// vscode默认启用了根据文件类型自动设置tabsize的选项
"editor.detectIndentation": false,
// 重新设定tabsize
"editor.tabSize": 2,
// "editor.tabSize": 4,
// #每次保存的时候自动格式化
"editor.formatOnSave": true,
// #每次保存的时候将代码按eslint格式进行修复
"eslint.validate": [
"javascript",
"javascriptreact",
"html",
"vue"
],
// "eslint.autoFixOnSave": true, // 改成下面的"editor.codeActionsOnSave"
// #每次保存的时候将代码按eslint格式进行修复
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// #让prettier(插件)使用eslint的代码格式进行校验
"prettier.eslintIntegration": true,
// #去掉代码结尾的分号
"prettier.semi": false,
// #使用单引号替代双引号
"prettier.singleQuote": true,
// #让函数(名)和后面的括号之间加个空格
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
// #这个按用户自身习惯选择
"vetur.format.defaultFormatter.html": "js-beautify-html",
// #让vue中的js按编辑器自带的ts格式进行格式化
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatterOptions": {
// "wrap_attributes": "force-aligned",
"js-beautify-html": {
// - auto: 仅在超出行长度时才对属性进行换行。
// - force: 对除第一个属性外的其他每个属性进行换行。
// - force-aligned: 对除第一个属性外的其他每个属性进行换行,并保持对齐。
// - force-expand-multiline: 对每个属性进行换行。
// - aligned-multiple: 当超出折行长度时,将属性进行垂直对齐。
"wrap_attributes": "force-aligned"
// #vue组件中html代码格式化样式
}
},
// "window.zoomLevel": 1,
"window.zoomLevel": 0,
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "all",
"workbench.sideBar.location": "left",
"files.autoGuessEncoding": true,
"editor.formatOnType": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
// 格式化stylus, 需安装Manta's Stylus Supremacy插件
"stylusSupremacy.insertColons": false, // 是否插入冒号
"stylusSupremacy.insertSemicolons": false, // 是否插入分好
"stylusSupremacy.insertBraces": false, // 是否插入大括号
"stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行
"stylusSupremacy.insertNewLineAroundBlocks": false // 两个选择器中是否换行
//"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
// "editor.defaultFormatter": "esbenp.prettier-vscode",
// "[javascript]": {
// "editor.defaultFormatter": "esbenp.prettier-vscode"
// },
// "vs-code-prettier-eslint.enabled":true,
// "vs-code-prettier-eslint.eslintFileName":".eslintrc",
// "vs-code-prettier-eslint.eslintFileType":"json",
// "vs-code-prettier-eslint.prettierFileName":".prettierrc",
// "vs-code-prettier-eslint.prettierFileType": "json",
// "prettier.printWidth": null
}