簡體   English   中英

如何擺脫 Vue JS 項目中的 Delete `··` (prettier/prettier) 錯誤

[英]How to get rid of Delete `··` (prettier/prettier) errors in a Vue JS project

我正在嘗試消除與@vue/prettier相關的錯誤。 我嘗試了一些東西,但似乎拋出更多錯誤。

我的.eslintrc.js如下:

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "@vue/prettier"],
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
  },
  parserOptions: {
    parser: "babel-eslint"
  }
};

我在規則部分嘗試"endOfLine":"auto"但這會導致更多和'prettier/prettier': ['error', {endOfLine: 'auto'}]

我已經從下面刪除了制表符間距;

    events_filtered_monthsNews: function() {
        return this.news.filter(u => u.monthsNews)
    },

像這樣格式化;

        events_filtered_monthsNews: function() {return this.news.filter(u => u.monthsNews)},

這消除了警告,但現在會產生更多錯誤,並且完全不切實際。

endOfLine

如果您不關心行尾,請將endOfLine設置為off

// .eslintrc.js
module.exports = {
  rules: {
    "prettier/prettier": ["error", { endOfLine: "off" }],
  },
};

tabWidth

您當前的文本使用 4 個空格的制表符,但 Prettier 默認需要 2 個空格的制表符。

所以這個輸入:

    events_filtered_monthsNews: function() {
        return this.news.filter(u => u.monthsNews)
    },

應該是這樣的:

  events_filtered_monthsNews: function() {
    return this.news.filter(u => u.monthsNews)
  },

如果您更喜歡 4 空格制表符,請將 Prettier 的tabWidth配置為4

// .eslintrc.js
module.exports = {
  rules: {
    "prettier/prettier": ["error", { tabWidth: 4 }],
  },
};

我在代碼的多行中遇到了一些錯誤,“error Delete /prettier”,然后我按照以下步驟解決了這個問題:

打開你的項目:

cd "項目文件夾"

此命令可以修復所有錯誤

npm 運行 lint --fix

然后:

npm 運行棉絨

最初報告錯誤,但應在 nuxt/create-nuxt-app#100 發布后修復。

如果您收到 endOfLine: "off" 的錯誤,以下對我有用:

rules: { "prettier/prettier": ["error", { endOfLine: "auto" }] }

如果您想禁用(更漂亮/更漂亮),請使用此代碼。 在.eslintrc.json文件中

規則:{'更漂亮/更漂亮':'關閉'},

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM