zoukankan      html  css  js  c++  java
  • vscode符合eslint的代码格式化设置

    1、安装插件

    1)ESlint:javascript代码检测工具,可以配置每次保存时格式化js,但每次保存只格式化一点点,你得连续按住Ctrl+S好几次,才格式化好,自行体会~~
    2)vetur:可以格式化html、标准css(有分号 、大括号的那种)、标准js(有分号 、双引号的那种)、vue文件,
    但是!格式化的标准js文件不符合ESlint规范,会给你加上双引号、分号等

    3)Prettier - Code formatter:只关注格式化,并不具有eslint检查语法等能力,只关心格式化文件(最大长度、混合标签和空格、引用样式等),包括JavaScript · Flow · TypeScript · CSS · SCSS · Less · JSX · Vue · GraphQL · JSON · Markdown
    4)Manta's Stylus Supremacy: 格式化stylus的插件(不用就不装),因为vetur会把css格式化有分号 、大括号的那种,此插件会把css格式化成stylus风格

    {
      "workbench.colorTheme": "Solarized Light (no bold)",
      "files.autoSave": "onFocusChange",
      "eslint.format.enable": true,
      "eslint.nodeEnv": "",
      // 重新设定tabsize
      "editor.tabSize": 2,
      "editor.fontSize": 16,
      "debug.console.fontSize": 14,
      "terminal.integrated.fontSize": 14,
      "explorer.confirmDragAndDrop": false,
      "[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
      },
      "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
      },
      "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
      },
      "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      // vscode默认启用了根据文件类型自动设置tabsize的选项
      "editor.detectIndentation": false,
      // #每次保存的时候自动格式化 
      "editor.formatOnSave": true,
      // #每次保存的时候将代码按eslint格式进行修复
      "eslint.autoFixOnSave": true,
      // 添加 vue 支持
      "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
          "language": "vue",
          "autoFix": 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": {
        "js-beautify-html": {
          "wrap_attributes": "auto"
          // #vue组件中html代码格式化样式 force-aligned
        }
      },
      // 格式化stylus, 需安装Manta's Stylus Supremacy插件
      "stylusSupremacy.insertColons": false, // 是否插入冒号
      "stylusSupremacy.insertSemicolons": false, // 是否插入分好
      "stylusSupremacy.insertBraces": false, // 是否插入大括号
      "stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行
      "stylusSupremacy.insertNewLineAroundBlocks": false,
      "[vue]": {
        "editor.defaultFormatter": "dbaeumer.vscode-eslint"
      }, // 两个选择器中是否换行
      "vetur.experimental.templateInterpolationService": true, // vue template代码中,有ts的提示
    }

     5)Auto Close Tag自动补全关闭标签

    安装即可,敲html代码,会自动补全

    6)Bracket Pair Colorizer 2

    对应括号显示同样的颜色,放置我们混淆括号

    7)JavaScript (ES6) code snippets

    es6 代码自动补全

    8) vscode-icons 为文件管理器增加文件类型图标

    9) Auto Rename Tag

    {
      "javascript.preferences.quoteStyle": "single",
      "workbench.colorTheme": "Solarized Light (no bold)",
      "files.autoSave": "onFocusChange",
      "eslint.format.enable": true,
      "eslint.nodeEnv": "",
      // 重新设定tabsize
      "editor.tabSize": 2,
      "editor.fontSize": 16,
      "debug.console.fontSize": 14,
      "terminal.integrated.fontSize": 14,
      "explorer.confirmDragAndDrop": false,
      "bracket-pair-colorizer-2.colors": [
        "Orchid",
        "YellowGreen",
        "Orange"
      ],
      "[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
      },
      "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
      },
      "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
      },
      "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
      },
      // vscode默认启用了根据文件类型自动设置tabsize的选项
      "editor.detectIndentation": false,
      // #每次保存的时候自动格式化 
      "editor.formatOnSave": true,
      // #每次保存的时候将代码按eslint格式进行修复
      "eslint.autoFixOnSave": true,
      // 添加 vue 支持
      "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
          "language": "vue",
          "autoFix": true
        }
      ],
      "indent": "off",
      "@typescript-eslint/indent": [
        "error"
      ],
      //  #让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": {
        "js-beautify-html": {
          "wrap_attributes": "auto", // #vue组件中html代码格式化样式 force-aligned
          "prettier": {
            "semi": true,
            "singleQuote": true
          }
        }
      },
      // 格式化stylus, 需安装Manta's Stylus Supremacy插件
      "stylusSupremacy.insertColons": false, // 是否插入冒号
      "stylusSupremacy.insertSemicolons": false, // 是否插入分好
      "stylusSupremacy.insertBraces": false, // 是否插入大括号
      "stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行
      "stylusSupremacy.insertNewLineAroundBlocks": false,
      "[vue]": {
        "editor.defaultFormatter": "dbaeumer.vscode-eslint"
      }, // 两个选择器中是否换行
      "vetur.experimental.templateInterpolationService": true, // vue template代码中,有ts的提示
      "editor.fontLigatures": null,
      "workbench.iconTheme": "vscode-icons",
      "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
      }
    }
  • 相关阅读:
    Odoo 库存管理-库存移动(Stock Move)新玩法
    odoo8.0+PyCharm4.5开发环境配置
    (总结)隐藏PHP版本与PHP基本安全设置
    Docker无法启动 Could not find a free IP address range for interface 'docker0' 最方便的解决办法
    MySQL Point in Time Recovery the Right Way
    The query below helps you to locate tables without a primary key:
    记一次揪心的MySQL数据恢复过程
    Linux中利用extundelete恢复误删除的数据
    Centos升级Python 2.7并安装pip、ipython
    navicat
  • 原文地址:https://www.cnblogs.com/shine-lovely/p/14275789.html
Copyright © 2011-2022 走看看