简体   繁体   English

如何让VueJS + ESLint(Airbnb)+更漂亮的合作? (VSCode)

[英]How to get VueJS + ESLint (Airbnb) + Prettier working together? (VSCode)

I've been pulling my hair out at trying to get this to work for the past few days and have had no luck, so I hope someone here can perhaps provide some help! 在过去的几天里,我一直在试着让它发挥作用并且没有运气,所以我希望这里的人可以提供一些帮助!

Essentially, I'm using VueJS and I really like the ESLint rules that Airbnb use, but I also want to use prettier for ONLY formatting. 基本上,我正在使用VueJS,我真的很喜欢Airbnb使用的ESLint规则,但我也想使用更漂亮的ONLY格式。 (max-length, indentation, etc...) So, for example, instead of it being this; (最大长度,缩进等...)因此,例如,而不是它;

<li v-for="(item, index) in this.list" v-bind:key="index" v-if="showRandomFor">{{item}}</li>

It will be this; 就是这样; (or something along these lines) (或沿着这些方向的东西) 应该是这样的

However, I can never get it to do this. 但是,我永远无法做到这一点。 I've tried using eslint-config-prettier which has been of no help at all since even after including it to the eslint config, the prettier rules still get applied (no error messages), so I'm unsure what to do about this one. 我尝试过使用eslint-config-prettier一直没有任何帮助,因为即使将它包含在eslint配置中,仍然可以应用更漂亮的规则(没有错误消息),所以我不确定如何处理这个问题一。

Any help is greatly appreciated and let me know if I can provide any additional information or logs! 非常感谢任何帮助,如果我能提供任何其他信息或日志,请告诉我!

EDIT: Just to clarify, I've looked at other posts. 编辑:只是为了澄清,我看了其他帖子。 But I cannot seem to find one that involves VueJS. 但我似乎找不到涉及VueJS的人。 Vue causes a lot of other issues with eslint/prettier so please don't say my question is a duplicate of someone else who is asking for help with say react. Vue引起了很多其他问题,因为eslint /更漂亮,所以请不要说我的问题是其他人请求帮助的副本。

this question made me question my life choices because I swear this worked earlier. 这个问题让我对我的生活选择提出质疑,因为我发誓早些时候这样做了 Perhaps that latest vs code update that changed some things? 也许最新的vs代码更新改变了一些事情?

Anyway, here is a not-so-pretty answer for vs-code while we wait for something better: 无论如何,在我们等待更好的东西的时候,对于vs-code来说,这是一个不那么漂亮的答案:

vs-code settings, : vs-code设置,:

{
  "vetur.validation.template": false,
  "prettier.eslintIntegration": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  "eslint.run": "onType",
  "eslint.autoFixOnSave": true
}

While autoFixOnSave works, I cannot get editor.action.formatDocument to listen to my esconfig no matter what (this must have changed, right? right??) So what to do? 虽然autoFixOnSave有效,但是我无法得到editor.action.formatDocument来监听我的esconfig而不管是什么(这一定必须改变,对吧?对吗?)那该怎么办?

I rebound my formatDocument-key to use eslint.executeAutofix instead. 我将formatDocument-key反弹为使用eslint.executeAutofix It only makes one pass (even if errors remain), so you have spam the key - which is especially noticeable with html-attributes, but it is something I guess. 它只进行一次传递(即使错误仍然存​​在),所以你有垃圾邮件密钥 - 这对于html属性来说特别明显,但我猜是这样的。

And this is my .eslintrc.js: 这是我的.eslintrc.js:

module.exports = {
  root: true,
  extends: [
    "plugin:vue/recommended",
    'airbnb'
  ],
  parserOptions: {
    parser: "babel-eslint", // I guess we have prettier using eslint using babel-eslint? :(
    sourceType: "module"
  },
};

Don't forget to update when you find something better! 当你找到更好的东西时别忘了更新!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM