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

如何消除这个错误?


当前回答

对我有用的是:

按照Roberto LL的建议,更新到2.2.1版本(目前的最新版本)。要执行它

NPM更新更漂亮

按照Hakan的建议执行lint修复(这将修改项目中的所有文件,将行结束转换为LF)。

NPM运行lint -- --fix

没有必要更改.eslintrc和.prettierrc文件!

其他回答

这是我的工作

步骤1 React js根目录找到.eslintrc文件

步骤2 在.eslintrc找到

"prettier/prettier": [
  2,
  {
    "printWidth": 100,
    "singleQuote": true,
    "trailingComma": "none",
    "tabWidth": 2
  }
]

替换为

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

保存文件,然后运行

npm start

在我的windows机器中,我通过在我当前项目目录中的.eslintrc.js文件的规则对象中添加以下代码片段来解决这个问题。

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

这在我的Mac上也能运行

从. pretierrc文件中删除这一行

 "endOfLine": "crlf"

执行eslint进行检测和修复解决了我的问题。

eslint。, ext .vue . js .jsx、.cjs .mjs, .ts, .tsx .cts,。MTS—fix—ignore-path .gitignore

或者如果你有lint脚本:NPM运行lint

我知道这是旧的,但我刚刚在我的团队(一些mac,一些linux,一些windows,所有的vscode)遇到了这个问题。

解决方案是在vscode的设置中设置行结束:

.vscode/settings.json

{
    "files.eol": "\n",
}

https://qvault.io/2020/06/18/how-to-get-consistent-line-breaks-in-vs-code-lf-vs-crlf/