处理eslint语法检查的vscode扩展与设置

2021-10-10  本文已影响0人  空格x

开发中为了规范自己的代码书写习惯需要eslint语法检查帮助我们,但这这扩展对于没有好的书写习惯的人简直是要命的东西,不过我们可以通过添加扩展与更改vscode保存时的格式化对我们书写的代码进行规范化。

1.先安装上我们需要的扩展



2.对vscode的格式化进行修改

3.点击设置搜索JSON

4.点击红框内的在settis.json中编辑对格式化进行自定义编辑
将原来的注释掉,将下面的代码复制进去,保存即可,需注意这个地方要写入自己的本地路径。
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", 
  // 写入自己powershell的本地存储地址
  // 如果不会那就看原来的设置里的路径

如果不清楚那就:
1、利用win+R,然后输入cmd,回车进入界面。


进入命令提示符界面
输入:where powershell 回车,就可以查看powershell安装位置。

具体的自定义配置代码
{
  // "eslint.autoFixOnSave": true,
  "prettier.semi": false, // 分号
  "prettier.singleQuote": true,
  "terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
  "files.associations": {
    "*.vue": "vue",
    "*.cjson": "jsonc",
    "*.wxss": "css",
    "*.wxs": "javascript"
  },
  // vscode默认启用了根据文件类型自动设置tabsize的选项
  // "editor.detectIndentation": false,
  // 重新设定tabsize
  // "editor.tabSize": 4,
  // #每次保存的时候自动格式化
  // "editor.formatOnSave": true,
  // #每次保存的时候将代码按eslint格式进行修复
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    },
    {
      "language": "typescript",
      "autoFix": true
    },
    {
      "language": "typescriptreact",
      "autoFix": true
    },
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.minimap.renderCharacters": false,
  "editor.suggestSelection": "first",
  "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
  "sync.gist": "20a776229bff3b00984adb31870def5d",
  "[javascript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },

  //background 的相关配置
  "background.enabled": false,
  //background 的相关配置
  // "update.enableWindowsBackgroundUpdates": true,
  // "background.customImages": [
  //   "file:///D:/WXWork/6bec5d1367cf44d29bab1f50082ff778[1].jpg"//图片地址
  // ],
  // "background.style": {
  //     "content":"''",
  //     "pointer-events":"none",
  //     "position":"absolute",//图片位置
  //     "width":"100%",
  //     "height":"100%",
  //     "z-index":"99999",
  //     "background.repeat":"no-repeat",
  //     "background-size":"25%,25%",//图片大小
  //     "opacity":0.2 //透明度
  // },
  // "background.useFront": true,
  // "background.useDefault": false,//是否使用默认图片
  // "background插件分割线-------------------------------------"
  // // #每次保存的时候自动格式化
  // "editor.formatOnSave": true,
  // // #每次保存的时候将代码按eslint格式进行修复
  // 添加 vue 支持
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  //  //  #让prettier使用eslint的代码格式进行校验
  "prettier.eslintIntegration": true,
  //  //  #去掉代码结尾的分号
  "prettier.semi": true,
  //  //  #使用带引号替代双引号
  "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": {
  //      "js-beautify-html": {
  //          "wrap_attributes": "force-aligned"
  //          // #vue组件中html代码格式化样式
  //      }
  //  },
  "fileheader.configObj": {
    // "createFileTime": true,
    "language": {
      "js": {
        "head": "/*",
        "middle": " * ",
        "end": " */"
      },
      "languagetest": {
        "head": "/*",
        "middle": " * ",
        "end": " */"
      }
    }, // 自定义语言注释符号(可选项)
    "annotationStr": {
      "head": "/*", // 自定义注释头部
      "middle": " * ", // 自定义注释中间部分(注意空格,这也是最终生成注释的一部分)
      "end": " */", // 自定义注释尾部
      "use": true // 是否使用自定义注释符号
    },
    // "beforeAnnotation": {},
    // "afterAnnotation": {},
    // "specialOptions": {},
    // "moveCursor": true, // 移动光标到`Description :`所在行
    // "dateFormat": "YYYY-MM-DD HH:mm:ss",
    "prohibitAutoAdd": ["json", "md"] // 禁止.json .md文件,自动添加头部注释
    // "autoAdd": true, // 自动添加头部注释开启才能自动添加
    // "autoAlready": true, // 默认开启
  },
  // 头部注释
  "fileheader.customMade": {
    "Author": "xiongziting",
    "Date": "",
    "LastEditors": "xiongziting",
    "LastEditTime": "",
    "Description": "",
    "FilePath": ""
  },
  // 函数注释
  "fileheader.cursorMode": {
    "description": "",
    "param": "",
    "return": ""
  },
  "sync.quietSync": true,
  "sync.autoUpload": true,
  "sync.autoDownload": true,
  "sync.forceUpload": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "launch": {},
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "gitlens.modes": {
    "zen": {
      "name": "Zen",
      "statusBarItemName": "Zen",
      "description": "for a zen-like experience, disables many visual features",
      "codeLens": false,
      "currentLine": false,
      "hovers": false,
      "statusBar": false
    },
    "review": {
      "name": "Review",
      "statusBarItemName": "Reviewing",
      "description": "for reviewing code, enables many visual features",
      "codeLens": true,
      "currentLine": true,
      "hovers": true
    }
  },
  "sync.forceDownload": true,
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "javascript.updateImportsOnFileMove.enabled": "never",
  "editor.tabSize": 2,
  "editor.rulers": [],
  // 这里的配置优先级低于.stylelintrc.js文件,适合用作编辑器的默认配置
  "stylelint.configOverrides": {
    "rules": {
      // 示例,配置支持小程序rpx单位
      "unit-no-unknown": [true, { "ignoreUnits": ["rpx"] }]
    },
    // 示例,配置忽略列表文件
    "ignoreFiles": [
      "node_modules/**/*",
      "dist/**/*",
      "**/*.js",
      "**/*.jsx",
      "**/*.tsx",
      "**/*.ts"
    ]
  },
  "tabnine.experimentalAutoImports": true,
  //   "files.autoSave": "afterDelay",
  "json.schemas": [
  
  




  
  ],
  "workbench.colorTheme": "Material Theme High Contrast",
  "google-translate.firstLanguage": "en",
  "google-translate.secondLanguage": "zh-cn",
  "diffEditor.ignoreTrimWhitespace": false,
  "emmet.includeLanguages": {
    "wxml": "html"
  },
  "minapp-vscode.disableAutoConfig": true,
  "px2rem.rootFontSize": 192,
  "prettier.jsxBracketSameLine": true,
  "prettier.jsxSingleQuote": true,
  "[scss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

5.在vscode编辑器内部点击鼠标右键更改格式化配置即可


6.有的可能改完后鼠标右键然后点击格式化文档会不生效,那样的话clter+s快捷键保存代码即可解决
上一篇下一篇

猜你喜欢

热点阅读