vscode 插件 eslint 配置
配置 settings.json
方法1
{
"editor.fontSize": 14, // 字体大小
"editor.tabSize": 2, // 设定tabsize缩进的空格,editor.detectIndentation启用时会覆盖该设置
// "http.proxyAuthorization": "false", // 关闭一些代理引发的警告
/********************************* ESLint 插件 *********************************/
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"html"
], // 配置 ESLint 检查的文件类型
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}, // 保存时按照eslint的规则格式化
"editor.formatOnSave": true, // 保存时自动格式化代码。可以实现保存时自动格式化style代码
/********************************* vetur 插件 *********************************/
"vetur.format.defaultFormatterOptions": {
"prettier": {
"semi": false, //不加分号
"singleQuote": true, //用单引号
"trailingComma": "none" // 不使用拖尾逗号
} // 重写prettier配置,与eslint保持一致
},
/********************************* KoroFileHeader 插件 *********************************/
"fileheader.customMade": {
"Descriptin": "",
"Version": "0.1",
"Autor": "Your Name",
"Date": "Do not edit",
"LastEditors": "Your Name",
"LastEditTime": "Do not edit"
}, // 文件头部注释
"fileheader.cursorMode": {
"descripton": "",
"param": "",
"return": "",
"author": "Your Name"
},
"eslint.codeAction.showDocumentation": {
"enable": true
}
}
或者配置eslint
方法2
{
// vscode默认启用了根据文件类型自动设置tabsize的选项
"editor.detectIndentation": true,
// 重新设定tabsize
"editor.tabSize": 4,
// #每次保存的时候自动格式化
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"html",
"vue"
],
// #每次保存的时候将代码按eslint格式进行修复
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// #让prettier使用eslint的代码格式进行校验
"prettier.eslintIntegration": true,
// #去掉代码结尾的分号
"prettier.semi": false,
// #使用带引号替代双引号
"prettier.singleQuote": true,
// #让函数(名)和后面的括号之间加个空格
"javascript.format.insertSpaceBeforeFunctionParenthesis": false,
// #让vue中的js按编辑器自带的ts格式进行格式化
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-aligned"
// #vue组件中html代码格式化样式
}
},
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "none",
"eslint.codeAction.showDocumentation": {
"enable": true
},
"workbench.colorTheme": "escook dark",
// 编辑器的大小
"window.zoomLevel": -0.8
}
配置保存自动格式化代码
第三种
{
"powermode.enabled": true,
"powermode.presets": "flames",
"explorer.confirmDelete": false,
"liveServer.settings.donotShowInfoMsg": true,
"px-to-rem.px-per-rem": 120,
"explorer.confirmDragAndDrop": false,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"less.compile": {
"javascriptEnabled": false
},
"cSpell.userWords": [
"abcdefghijklmnopqrstuvwxyz"
],
"eslint.codeAction.showDocumentation": {
"enable": true
},
"eslint.packageManager": "yarn",
"eslint.validate": [
"javascript", // 用eslint的规则检测js文件
{
"language": "vue", // 检测vue文件
"autoFix": true // 为vue文件开启保存自动修复的功能
},
{
"language": "html",
"autoFix": true
},
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.tabSize": 2,
"eslint.autoFixOnSave": true,
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.autoSave": "afterDelay",
"security.workspace.trust.untrustedFiles": "open",
"editor.largeFileOptimizations": false,
"merge-conflict.autoNavigateNextConflict.enabled": true,
"cSpell.customDictionaries": {
"custom-dictionary-user": {
"name": "custom-dictionary-user",
"path": "~/.cspell/custom-dictionary-user.txt",
"addWords": true,
"scope": "user"
}
},
"workbench.editorAssociations": {
"*.xml": "default"
},
"eslint.rules.customizations": [
],
"eslint.trace.server": "off",
}