vscode 插件 eslint 配置

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",

}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在VSCode中安装并配置ESLint插件,请按照以下步骤进行操作: 1. 打开VSCode,点击左侧的扩展图标(四个方块)或按下快捷键`Ctrl+Shift+X`来打开扩展面板。 2. 在搜索栏中输入"ESLint"并按下回车键,找到ESLint插件并点击安装按钮进行安装。 3. 安装完成后,点击"重新加载"按钮来重新加载VSCode。 4. 接下来,你需要在你的项目中安装ESLint。在终端中进入你的项目根目录,并执行以下命令: ``` npm install eslint --save-dev ``` 或者如果你使用的是Yarn: ``` yarn add eslint --dev ``` 5. 安装完成后,在终端中执行以下命令来初始化ESLint配置文件: ``` npx eslint --init ``` 这将引导你完成一个交互式的配置过程。你可以根据自己的需求选择一些配置选项,例如选择ESLint的规则(Airbnb、Standard等),或者手动配置自定义规则。 6. 完成配置后,ESLint将会生成一个`.eslintrc`文件,该文件存放着ESLint的规则配置。 7. 回到VSCode,点击左下角的设置图标(齿轮图标),选择"首选项"->"设置"来打开用户设置。 8. 在用户设置中搜索"eslint.autoFixOnSave"并勾选该选项,这将在保存文件时自动修复ESLint错误。 9. 在用户设置中搜索"eslint.validate",找到"ESLint: Validate"选项,并在其值中添加以下内容: ``` "javascript", "javascriptreact", "typescript", "typescriptreact" ``` 这将使ESLintJavaScriptJavaScript React、TypeScript和TypeScript React文件进行验证。 现在,你已经成功安装并配置ESLint插件。在保存文件时,ESLint将会自动运行,并根据配置的规则进行验证和修复。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值