prettier 和ESlint格式冲突问题解决-Unexpected space before function parentheses

问题描述

在气的极度肝疼的情况下,描述一下问题:
1.本来prettier和eslint 用的好好的,今天做黑马头条的案例,写到一个匿名函数,prettier又开始加空格了,但是eslint只能设置忽略空格或者不忽略空格,没办法做到两全,我这里改了规则怕是前面的都要翻了天
在这里插入图片描述

2.妄想通过修改rules或者settings.json来实现,未遂

解决:装插件 prettier-eslint

1.安装插件prettier-eslint
2.配置:

"editor.defaultFormatter": "esbenp.prettier-vscode", //自动格式化程序为prettier
  "javascript.updateImportsOnFileMove.enabled": "always", //js重命名文件自动更新路径
  //js自动格式化程序为prettier-eslint
  "[javascript]": {
    
    
    "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
  },
  "[vue]": {
    
    
    "editor.defaultFormatter": "octref.vetur"
  },
  // #让vue中的js按"prettier"格式进行格式化
  "vetur.format.defaultFormatter.html": "prettier",
  "vetur.format.defaultFormatter.js": "prettier-eslint", //主要是这一行解决冲突

  "editor.suggestSelection": "first", //tab优先选第一个建议
  "editor.formatOnPaste": true, //自动格式化粘贴内容
  // "editor.formatOnType": true, //键入一行后自动格式化

说明
1.首先原来的eslint和prettier属于是开发者都很傲娇,谁也不惯着谁,不妥协不将就,所以目前没有找到特别完美的解决方法。
2.prettier-eslint原理是先prettier,再eslint fix 原来的是相反的过程,而且根据不同的代码类型进行格式化,因此经常可以看到修改了又闪现出错的现象,从最后的解决方案看来,害得是eslint 赢了,毕竟给你报错难受死你
3.附eslint rules:

 rules: {
    
    
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'vue/multi-word-component-names': 0,
    'space-before-function-paren': ['error', 'never']
  }

就这个格式化就离谱,我分分钟想听彬哥的辞职不干了!

猜你喜欢

转载自blog.csdn.net/qq_36722315/article/details/125108332