我使用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,
}

如何消除这个错误?


当前回答

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

或一组

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

在eslintrc文件的rules对象中。

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

其他回答

最好的解决方案是使用.editorconfig。特别是当您与不同类型操作系统的团队一起工作时。因此,在.eslintrc中禁用prettier根本不是一个好的选择。

从vscode扩展安装.editorconfig。在你的项目根目录下创建一个。editorconfig文件,并把它放到你的。gitignore文件中,这样就不会打扰你的队友了。

将其添加到您的.editorconfig文件中,或者从文档中选择您需要的工作流设置。

[*]
end_of_line = lf

这将自动保存您的文件到EOL类型lf,而不是在windows中的crlf。反之亦然,如果使用mac。或取决于项目工作流程设置。

根本原因是windows默认为crlf。所以每次你尝试创建一个文件,你将面对这个漂亮的删除'cr'错误。

除了

如果你从git中获得的所有文件都包含删除'cr'。

删除项目 重新安装git并选择按原样结帐,提交unix风格的行结束符 再次从回购中克隆您的项目 使用上面设置的.editorconfig

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

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

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

或一组

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

在eslintrc文件的rules对象中。

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

如果你需要使用.prettierrc.js:

module.exports = {
    ...[config params],
    endOfLine: 'auto',
};

注意!不是在规则或更漂亮。

信息在这里https://prettier.io/docs/en/options.html#end-of-line

解决方案

1. 禁用自动转换git设置

Git——全局配置核心。autocrlf假

2. 删除旧的缓存数据

Git rm——cached -r。

3.重置git文件

Git重置——很难