我使用VS Code与漂亮的1.7.2和ESLint 1.7.0。 在每个换行符之后:

[eslint] Delete `CR` [prettier/prettier]

这是.eslintrc.json:

{
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "env": {
    "jest": true,
    "browser": true
  },
  "rules": {
    "import/no-extraneous-dependencies": "off",
    "import/prefer-default-export": "off",
    "no-confusing-arrow": "off",
    "linebreak-style": "off",
    "arrow-parens": ["error", "as-needed"],
    "comma-dangle": [
      "error",
      {
        "arrays": "always-multiline",
        "objects": "always-multiline",
        "imports": "always-multiline",
        "exports": "always-multiline",
        "functions": "ignore"
      }
    ],
    "no-plusplus": "off"
  },
  "parser": "babel-eslint",
  "plugins": ["react"],
  "globals": {
    "browser": true,
    "$": true,
    "before": true,
    "document": true
  }
}

. pretierrc文件:

{
  "printWidth": 80,
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
}

如何消除这个错误?


当前回答

如果您已经签出了代码

git config --global core.autocrlf input 


git rm --cached -r . 


git reset --hard

其他回答

解决方案

git config --global core.autocrlf false

在全局配置之后,您需要再次拉出代码。

问题的根本原因:

罪魁祸首是git, core. selff的配置属性

由于历史原因,windows和linux下文本文件的换行方式不同。

在换行时,换行符同时使用CR(换行符)和LF(换行符) Mac和Linux只使用换行符LF 旧版本的Mac使用回车CR

因此,在不同的系统中创建和使用文本文件时会出现不兼容问题。

当我在Windows上克隆代码时,默认为true,然后文件的每一行都自动转换为CRLF。如果你没有对文件做任何改变,eslint通过预提交删除CR,因为git会自动将CRLF转换为LF。

参考

https://developpaper.com/solution-to-delete-%E2%90%8Deslint-prettier-prettier-error/

尝试在你的. pretierrc(或. pretierrc .json)文件中设置" endoline ":"auto"(在对象内部)

或一组

'prettier/prettier': [
  'error',
  {
    'endOfLine': 'auto',
  }
]

在eslintrc文件的rules对象中。

如果你使用的是windows机器,endoline可以“crlf”基于你的git配置。

我升级到“更漂亮”:“^2.2.0”,错误消失了

没有必要忽视林特法则。只需要自动修复

npm install -g prettier
prettier -w .\webpack.config.js # or other file

上面所有的答案都是正确的,但当我使用窗口并禁用更漂亮的ESLint扩展投资。Vs-code-prettier-eslint的问题将被修复。