如何在Vue JS项目中消除Delete `··` (prettier/prettier)错误

12

我正在尝试解决与@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'}]

我已经从以下内容中删除了制表符间距;

Translated:

I tried "endOfLine":"auto" within the rules section, but this caused more problems, and also 'prettier/prettier': ['error', {endOfLine: 'auto'}].

I have removed tabbed spacing from the below:

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

以这样的格式进行排版;

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

虽然它可以消除警告,但现在它却产生了更多的错误,并且对于工作完全不切实际。


npm run lint --fix - Lameck Meshack
5个回答

21

结尾行

如果您不关心行尾,将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)
  },

如果您喜欢使用四个空格作为制表符,请将Prettier的tabWidth配置为4

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

5
如果您在endOfLine处出现错误:"off",可以尝试以下方法:
rules: { "prettier/prettier": ["error", { endOfLine: "auto" }] }

5
我在我的代码中遇到了一些错误,错误信息是 "error Delete prettier/prettier",问题出现在多行上。我通过以下步骤解决了这个问题:
打开你的项目:
cd "项目文件夹"
这个命令可以修复所有的错误:
npm run lint --fix
接着:
npm run lint
最初会报错,但应该会在 nuxt/create-nuxt-app#100 发布后得到解决。

3
如果你想禁用 (prettier/prettier),请使用以下代码。在 .eslintrc.json 文件中:
rules: { 'prettier/prettier': 'off' },

enter image description here


0
如果你正在使用Visual Studio Code,可能是因为VS Code自动为你添加了回车符。你可以通过点击屏幕右下角蓝色栏中的CRLF来禁用此功能。将其设置为LF可以解决我的问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接