首页 > 其他分享 >vscode保存时自动ESLint格式化(vue)

vscode保存时自动ESLint格式化(vue)

时间:2023-04-10 13:57:05浏览次数:32  
标签:vue false vscode eslint prettier ESLint true editor

一、安装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
}

 

标签:vue,false,vscode,eslint,prettier,ESLint,true,editor
From: https://www.cnblogs.com/xzqyun/p/17302680.html

相关文章

  • vueuse cookie token使用
    <template><h1>后台首页</h1><el-button@click="set">设置</el-button><el-button@click="get">读取</el-button><el-button@click="remove">删除</el-button></template>......
  • Vue router 跳转
    useRouter(跳转),useRoute(获取路由参数)//login.vue//路由跳转-引入-01import{useRouter}from"vue-router";//路由跳转-实例化后-02//useRouter使用push方法进行跳转constrouter=useRouter()//路由跳转-跳转到后台首页-03router.push('/')......
  • vue的几个记录
    1.父组件传递子组卷数组参数props:{boxData:{type:Array,default:()=>[],//重点},2.要实现父组件传递子组卷的参数动态更新(父-》子-》子,也只需要在最后一个子组件监听即可。)需要用到监听器watch:{//监听父组件传递的参数,以动态更新boxDa......
  • 如何部署VSCODE SERVER
    tags:how-to本文指导利用微软官方的vscodeserver部署个人开发环境,并通过网页端或vscode客户端访问该环境。演示环境本教程使用debian作为演示服务器。使用'code'CLI你可以使用codeCLI创建并使用在远程机器上安装codeCLI安装前选定下载目录如mkdir/home/dev/bin......
  • ubuntu20.04下VSCode无法输入中文解决方法
    解决方法:重新安装VSCode。我一开始是在ubuntu商店下载的,结果上网查了了下,商店里的VSCode是阉割版的,想要输入中文就要重新安装。安装流程:先删除再安装。1.可以在商店里已安装界面下选择移除,或者sudosnapremovecode。删除后仍会保留已打开文件的记录,所以不用担心。2.删除完......
  • Vue2异步更新及nextTick原理
    vue官网中是这样描述nextTick的在下次DOM更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法,可以获取更新后的DOM。在学习nextTick是如何实现之前,我们要先了解下JavaScript的执行机制JavaScript执行机制浏览器是多线程的,例如GUI渲染线程、JS引擎线程......
  • vue-day2
    绑定class样式:class=""(v-bind的缩写)修改vue维护的数据,而非直接操作dom绑定style,内联样式,交给vue管理(要对象,或者数组)font-size -> fontSize  换位驼峰  ⭐⭐⭐vue条件渲染v-show底层->调整style行内样式,display:nonev-ifdom节点都没了,彻底......
  • vue之插槽
    #######################                    #########################......
  • 解决Godot使用VsCode编写C#代码,智能提示不见了[一问随笔]
    问题:我的项目采用了godot+visualstudiocode+C#,有天突然换引擎,从Godot4.0.0升级到Godot4.0.2,visualstudiocode突然不给代码提示了,甚是奇怪。查看报错发现这样一句话找不到指定的sdk“godot.net.sdk/4.0.2”糟了!不会这个版本不支持用vscode写代码吧!解决方式:......
  • vue-router
    ###################npminstallvue-router       Vue.use()方法的源代码如下:functioninstall(Vue){//避免重复安装插件if(install.installed&&_Vue===Vue)returninstall.installed=true_Vue=Vue//执行插件的安装方法const......