简体   繁体   English

VSCode (Angular) - EsLint Prettier 问题

[英]VSCode (Angular) - EsLint Prettier issue

I have a super annoying problem EsLint and Prettier are doing different things... Prettier on format is formatting the code different then expected by EsLint I have prettier as default formatter enabled on save我有一个超级烦人的问题 EsLint 和 Prettier 正在做不同的事情... Prettier on format 格式化的代码与 EsLint 预期的不同 我在保存时启用了 prettier 作为默认格式化程序

Eg this line of code比如这行代码

   const actionAbove = findNodeInForm(this.form, (nodeAbove.data as FlowChartData).key.replace('Group', '').replace('Root', ''));

is marked red with a lint error when I resolve it it looks like:当我解决它时,它被标记为红色并带有 lint 错误,它看起来像:

 const actionAbove = findNodeInForm(
      this.form,
      (nodeAbove.data as FlowChartData).key.replace('Group', '').replace('Root', '')
    );

On save it is formatted back to be in on line保存时它被格式化回在线

Prettier Config:更漂亮的配置:

    {
  "singleQuote": true,
  "printWidth": 120
}

EsLint Config EsLint 配置

    {
  "root": true,
  "ignorePatterns": ["projects/**/*", "src/models/*"],
  "plugins": ["prettier"],

  "overrides": [
    {
      "files": ["*.ts"],
      "parserOptions": {
        "project": ["tsconfig.json", "e2e/tsconfig.e2e.json"],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates",
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking",
        "plugin:prettier/recommended",
        "prettier"
      ],
      "rules": {
        "prettier/prettier": [
          "error",
          {
            "endOfLine": "auto"
          }
        ],
        "@typescript-eslint/array-type": [
          "error",
          {
            "default": "array"
          }
        ],
        "@typescript-eslint/consistent-type-definitions": "error",
        "@typescript-eslint/dot-notation": "off",
        "@typescript-eslint/explicit-member-accessibility": [
          "off",
          {
            "accessibility": "explicit"
          }
        ],
        "@typescript-eslint/no-empty-function": "error",
        "@typescript-eslint/no-this-alias": "error",
        "@typescript-eslint/no-unused-vars": "error",
        "@typescript-eslint/no-var-requires": "error",
        "arrow-parens": ["off", "always"],
        "brace-style": ["error", "1tbs"],
        "id-blacklist": "off",
        "id-match": "off",
        "import/no-extraneous-dependencies": "off",
        "import/no-internal-modules": "off",
        "linebreak-style": "off",
        "max-classes-per-file": ["error", 1],
        "new-parens": "off",
        "newline-per-chained-call": "off",
        "no-duplicate-case": "error",
        "no-duplicate-imports": "error",
        "no-empty": "error",
        "no-extra-bind": "error",
        "no-extra-semi": "off",
        "no-irregular-whitespace": "off",
        "no-new-func": "error",
        "no-redeclare": "error",
        "no-return-await": "error",
        "no-sequences": "error",
        "no-sparse-arrays": "error",
        "no-template-curly-in-string": "error",
        "no-underscore-dangle": "off",
        "prefer-object-spread": "error",
        "quote-props": "off",
        "react/jsx-curly-spacing": "off",
        "react/jsx-equals-spacing": "off",
        "react/jsx-wrap-multilines": "off",
        "space-before-function-paren": "off",
        "space-in-parens": ["off", "never"]
      }
    },
    {
      "files": ["*.html"],
      "extends": ["plugin:@angular-eslint/template/recommended", "prettier"],
      "rules": {}
    }
  ]
}

Installeslint-config-prettier安装eslint-config-prettier

From: https://prettier.io/docs/en/install.html#eslint-and-other-linters来自: https://prettier.io/docs/en/install.html#eslint-and-other-linters

If you use ESLint, install eslint-config-prettier to make ESLint and Prettier play nice with each other.如果您使用 ESLint,请安装 eslint-config-prettier 以使 ESLint 和 Prettier 相互配合。 It turns off all ESLint rules that are unnecessary or might conflict with Prettier.它会关闭所有不必要或可能与 Prettier 冲突的 ESLint 规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM