当前位置: 移动技术网 > IT编程>开发语言>JavaScript > vscode配置setting.json文件实现eslint自动格式代码

vscode配置setting.json文件实现eslint自动格式代码

2020年08月18日  | 移动技术网IT编程  | 我要评论

一、eslint+vetur 实现eslint代码规范


二、重点----旧版本(旧版本配置在setting.json 会出现警告)

{
“eslint.autofixonsave”: true,
“eslint.validate”: [
“javascript”,
{
“language”: “vue”,
“autofix”: true
},
{
“language”: “html”,
“autofix”: true
}
]
}

三、新版配置----新版本


{
“editor.codeactionsonsave”: {
“source.fixall.eslint”: true
},
“eslint.probe”: [“javascript”, “vue”, “html”]
}

以下是对自己vscode-settings.json 做一个记录(仅供参考)

{
 //设置文字大小
 "editor.fontsize": 18,

 //设置文字行高
 "editor.lineheight": 24,

 //开启行数提示
 "editor.linenumbers": "on",

 // 在输入时显示含有参数文档和类型信息的小面板。
 "editor.parameterhints.enabled": true,

 // 调整窗口的缩放级别
 "window.zoomlevel": 0,

 // 文件目录
 "workbench.icontheme": "vscode-icons",

 // 设置字体
 "editor.fontfamily": "'droid sans mono', 'courier new', monospace, 'droid sans fallback'",

 // 自动换行
 "editor.wordwrap": "on",

 // 自定义vscode面板颜色
 "workbench.colorcustomizations": {
  "tab.activebackground": "#253046", // 活动选项卡的背景色
  "activitybar.background": "#253046", //活动栏背景色
  "sidebar.background": "#253046", //侧边栏背景色
  "activitybar.foreground": "#23f8c8", //活动栏前景色(例如用于图标)
  "editor.background": "#292a2c" //编辑器背景颜色
  // "editor.foreground":"#ff0000", 	//编辑器默认前景色
  // "editor.findmatchbackground":"#23f8c8", 	//当前搜索匹配项的颜色
  // "editor.findmatchhighlightbackground":"#ff0000", 	//其他搜索匹配项的颜色
  // "editor.linehighlightbackground":"#ff0000", 	//光标所在行高亮文本的背景颜色
  // "editor.selectionbackground":"#ff0000", 	//编辑器所选内容的颜色
  // "editor.selectionhighlightbackground":"#ff0000", 	//与所选内容具有相同内容的区域颜色
  // "editor.rangehighlightbackground":"#ff0000", 	//突出显示范围的背景颜色,例如 "quick open" 和“查找”功能
  // "editorbracketmatch.background":"#ff0000", 	//匹配括号的背景色
  // "editorcursor.foreground":"#ff0000", 	//编辑器光标颜色
  // "editorgutter.background":"#ff0000", 	//编辑器导航线的背景色,导航线包括边缘符号和行号
  // "editorlinenumber.foreground":"#ff0000", 	//编辑器行号颜色
  // "sidebar.foreground":"#ff0000", 	//侧边栏前景色
  // "sidebarsectionheader.background":"#ff0000", 	//侧边栏节标题的背景颜色
  // "statusbar.background":"#ff0000", 	//标准状态栏背景色
  // "statusbar.nofolderbackground":"#ff0000", 	//没有打开文件夹时状态栏的背景色
  // "statusbar.debuggingbackground":"#ff0000", 	//调试程序时状态栏的背景色
  // "tab.activeforeground":"#ff0000", 	//活动组中活动选项卡的前景色
  // "tab.inactivebackground":"#ff0000", 	//非活动选项卡的背景色
  // "tab.inactiveforeground":"#ff0000" // 活动组中非活动选项卡的前景色
 },
 // vscode默认启用了根据文件类型自动设置tabsize的选项
 "editor.detectindentation": false,

 // 重新设定tabsize
 "editor.tabsize": 2,

 // #每次保存的时候自动格式化
 "editor.formatonsave": true,

 // #让函数(名)和后面的括号之间加个空格
 "javascript.format.insertspacebeforefunctionparenthesis": true,

 // #这个按用户自身习惯选择
 "vetur.format.defaultformatter.html": "js-beautify-html",

 // #让vue中的js按编辑器自带的ts格式进行格式化
 "vetur.format.defaultformatter.js": "vscode-typescript",

 // 保存时运行的代码eslint操作类型。
 "editor.codeactionsonsave": {
  "source.fixall.eslint": true
 },

 // 添加emmet支持vue文件
 "emmet.includelanguages": {
  "wxml": "html",
  "vue": "html"
 },

 // 两个选择器中是否换行
 "minapp-vscode.disableautoconfig": true,

 //快速预览(右侧)
 "editor.minimap.enabled": true,

 // tab 代码补全
 "files.associations": {
  "*.wpy": "vue",
  "*.vue": "vue",
  "*.cjson": "jsonc",
  "*.wxss": "css",
  "*.wxs": "javascript"
 },

 // 用来配置如何使用eslint cli引擎api启动eslint。 默认为空选项
 "eslint.options": {
  "extensions": [".js", ".vue"]
 },

 // 在onsave还是ontype时执行linter。默认为ontype。
 "eslint.run": "onsave",

 // 启用eslint作为已验证文件的格式化程序。
 "eslint.format.enable": true,

 // 语言标识符的数组,为此eslint扩展应被激活,并应尝试验证文件。
 "eslint.probe": ["javascript", "javascriptreact", "vue-html", "vue", "html"],

 //关闭rg.exe进程 用cnpm导致会出现rg.exe占用内存很高
 "search.followsymlinks": false,

 // 给js-beautify-html设置属性隔断
 "vetur.format.defaultformatteroptions": {
  "js-beautify-html": {
   "wrap_attributes": "force-aligned",
   "max_preserve_newlines": 0
  }
 },

 // style默认偏移一个indent
 "vetur.format.styleinitialindent": true,

 // 定义匿名函数的函数关键字后面的空格处理。
 "javascript.format.insertspaceafterfunctionkeywordforanonymousfunctions": true,

 // 定义函数参数括号前的空格处理方式。
 "typescript.format.insertspacebeforefunctionparenthesis": true,

 // 新版本消息
 "vsicons.dontshownewversionmessage": true,

 // 控制资源管理器是否在把文件删除到废纸篓时进行确认。
 "explorer.confirmdelete": true,

 // 使用eslint-plugin-vue验证<template>中的vue-html
 "vetur.validation.template": false,

 // 指定用在工作台中的颜色主题。
 "workbench.colortheme": "one dark pro"
}

总结

到此这篇关于vscode配置setting.json文件实现eslint自动格式代码的文章就介绍到这了,更多相关vscode 配置eslint自动格式化内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网