Eslint & Prettier & prettier-eslint

 

关于vscode代码格式化,有没有发现突然之前的配置不能用了呢

比如"prettier.eslintIntegration"

"prettier.eslintIntegration": true

突然提示改为用prettier-eslint

于是乎开始了各种更改配置,安装插件,查找配置项。。。但依然没有能恢复我之前的配置

在使用了prettier-eslint之后,才发现,原来每次格式化是先执行eslint再执行prettier

导致eslint有些配置被覆盖了

 

。。。。

最后发现prettier我根本用不着啊

一个eslint足矣,解放了。。。。

把prettier相关setting.json,配置文件全部拿掉,prettier,prettier-eslint全部卸载

到此结束了。。。

eslint配置项足够我用了。。。。eslint配置文件.eslintrc.js

rules: {
    // allow async-await
    "generator-star-spacing": "off",
    // allow debugger during development
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
    "vue/html-self-closing": "off",
    'vue/html-closing-bracket-newline': [2, { "multiline": "never" }],
    "vue/max-attributes-per-line": [
      "error",
      {
        multiline: {
          max: 1,
          allowFirstLine: true
        }
      }
    ],
    "vue/valid-v-for": 0,
    "vue/attributes-order": 0,
    "vue/require-default-prop": 0,
    "no-undef": "off",
    "no-unused-vars": 0,
    "no-useless-escape": 0,
    "no-console": 0,
    "no-control-regex": 0,
    camelcase: "off",
    "newline-per-chained-call": 2,
    semi: ["error", "never"], //其实是never,这里可以清晰看到prettier又把分号加回来了
    quotes: ['error', 'single'],
    'space-before-function-paren': ['error', 'never'],
    'func-call-spacing': ["error", "never"]
  },

关于setting.json的配置坑

"eslint.validate"变动

"eslint.validate": [
        "javascript",
        "javascriptreact",
        {
            "language": "html",
            "autoFix": true
        },
        {
            "language": "vue",
            "autoFix": true
        }
    ],


"eslint.validate": [
    "javascript",
    "vue"
  ],

"editor.formatOnSave"变动

"editor.formatOnSave": true,
 

 "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
  },
{
  // vscode默认启用了根据文件类型自动设置tabsize的选项
  "editor.detectIndentation": false,
  // 重新设定tabsize
  "editor.tabSize": 2,
  // #每次保存的时候自动格式化
  "editor.formatOnSave": true,
  // #每次保存的时候将代码按eslint格式进行修复
  //"eslint.autoFixOnSave": true,   改成下面的"editor.codeActionsOnSave"
  "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
  },
  // 添加 vue 支持
  "eslint.validate": [
    "javascript",
    "vue"
  ],
  //  #让prettier使用eslint的代码格式进行校验
  //"prettier.eslintIntegration": true,
  //  #去掉代码结尾的分号
  //"prettier.semi": false,
  //  #使用带引号替代双引号
  //"prettier.singleQuote": true,
  //  #让函数(名)和后面的括号之间加个空格
  //"javascript.format.insertSpaceBeforeFunctionParenthesis": false,
  // #这个按用户自身习惯选择
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  // #让vue中的js按编辑器自带的ts格式进行格式化
  //"vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  //"vetur.format.defaultFormatter.html": "prettyhtml",
  //"vetur.format.defaultFormatter.js": "prettier",
  "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代码格式化样式
    }
  },
  // 格式化stylus, 需安装Manta's Stylus Supremacy插件
  // "stylusSupremacy.insertColons": false, // 是否插入冒号
  // "stylusSupremacy.insertSemicolons": false, // 是否插入分好
  // "stylusSupremacy.insertBraces": false, // 是否插入大括号
  // "stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行
  // "stylusSupremacy.insertNewLineAroundBlocks": false,
  "workbench.sideBar.location": "left",
  "files.autoGuessEncoding": true,
  "window.zoomLevel": 1,
  "editor.formatOnType": true,
  "editor.defaultFormatter": "dbaeumer.vscode-eslint",
  //"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
}

 

你可能感兴趣的:(vscode)