zoukankan      html  css  js  c++  java
  • VsCode配置ESLint自动格式化

    VsCode配置ESLint自动格式化

    安装ESLint插件

    image-20200929181518611

    配置文件进行配置

    找到"文件" -> "首选项" -> "设置"(或者: File->Preferences->Settings ),点击右上角,切换到setting.json配置文件

    image-20200929181746539

    追加以下代码:

    {
        // vscode默认启用了根据文件类型自动设置tabsize的选项
        "editor.detectIndentation": false,
        // 重新设定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": true,
        // #让vue中的js按编辑器自带的ts格式进行格式化
        "vetur.format.defaultFormatter.js": "vscode-typescript",
        "vetur.format.defaultFormatterOptions": {
            "js-beautify-html": {
                "wrap_attributes": "force-aligned"
                // #vue组件中html代码格式化样式
            }
        },
        "window.zoomLevel": 0,
        "explorer.confirmDelete": false,
        "explorer.confirmDragAndDrop": false,
        "editor.renderControlCharacters": true,
        "editor.renderWhitespace": "all"
    }
    

    Vue项目中的EsLint配置

    一般在使用Vue-Cli生成项目的时候,ESlint就已经进行了配置,这里贴出来的是ESLint的默认配置,没有配置的可以使用这个默认配置

    module.exports = {
      root: true,
      env: {
        node: true
      },
      extends: [
        'plugin:vue/essential',
        '@vue/standard'
      ],
      parserOptions: {
        parser: 'babel-eslint'
      },
      rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
      },
      overrides: [
        {
          files: [
            '**/__tests__/*.{j,t}s?(x)',
            '**/tests/unit/**/*.spec.{j,t}s?(x)'
          ],
          env: {
            jest: true
          }
        }
      ]
    }
    
    
  • 相关阅读:
    Rain 学习自用贴
    連休計画
    091207 晴
    记下London奥运我喜欢的几首歌
    20世纪最好的10个算法(转)
    一日一美女:告诉你什么是斐波那契螺旋线
    矩阵鞍点的寻找
    日本の物語
    a new start~ s!
    Photoshop CS5运用色彩原理去除半透明水印(转)
  • 原文地址:https://www.cnblogs.com/cuianbing/p/13751132.html
Copyright © 2011-2022 走看看