簡體   English   中英

用於刪除行的 ESLint Lint 縮進配置

[英]ESLint Lint Indent Config for dropped lines

因此,隨着 Angular 11 棄用 TSLint,我切換到 ESLint(目前對它不太滿意)。
現在我有這個煩人的間距問題,我正在嘗試在 .eslintrc.js 配置中解決。

拿這幾行代碼(這是我擁有的,也是我想要保留的):

readonly DELETE_DIALOG_MESSAGE = "This message doesn't exceed the width limit & is 1 line.";
readonly RETURN_TO_DRAFT_MESSAGE =
  "This message is supper long, like really loooong. So it exceeds my width limit and is dropped a line.";

您看到較長消息的刪除線后的縮進嗎? 我想保留它。 但是 ESLint 正在刪除它。
ESLint 使它看起來像這樣:

readonly DELETE_DIALOG_MESSAGE = "This message doesn't exceed the width limit & is 1 line.";
readonly RETURN_TO_DRAFT_MESSAGE =
"This message is supper long, like really loooong. So it exceeds my width limit and is dropped a line.";

看? 沒有縮進。 這更令人沮喪,因為(我使用 prettier 進行格式化)我的格式化程序會將空間添加回來。

我試圖找到切換規則/配置會在超出寬度限制時刪除行時添加縮進。
任何幫助,將不勝感激!

我的縮進規則是: "@typescript-eslint/indent": ["error", 2],
這是我的 whole.eslintrc.js 配置文件:

module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true
  },
  extends: ["prettier", "prettier/@typescript-eslint"],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "tsconfig.json",
    sourceType: "module"
  },
  plugins: [
    "eslint-plugin-import",
    "eslint-plugin-jsdoc",
    "@angular-eslint/eslint-plugin",
    // "eslint-plugin-react",
    "@typescript-eslint",
    "@typescript-eslint/tslint"
  ],
  rules: {
    "@angular-eslint/component-class-suffix": "error",
    "@angular-eslint/directive-class-suffix": "error",
    "@angular-eslint/no-host-metadata-property": "error",
    "@angular-eslint/no-input-rename": "error",
    "@angular-eslint/no-inputs-metadata-property": "error",
    "@angular-eslint/no-output-on-prefix": "error",
    "@angular-eslint/no-output-rename": "error",
    "@angular-eslint/no-outputs-metadata-property": "error",
    "@angular-eslint/use-lifecycle-interface": "error",
    "@angular-eslint/use-pipe-transform-interface": "error",
    "@typescript-eslint/consistent-type-definitions": "error",
    "@typescript-eslint/dot-notation": "off",
    "@typescript-eslint/explicit-member-accessibility": [
      "off",
      {
        accessibility: "explicit"
      }
    ],
    "@typescript-eslint/indent": ["error", 2],
    "@typescript-eslint/member-delimiter-style": [
      "error",
      {
        multiline: {
          delimiter: "semi",
          requireLast: true
        },
        singleline: {
          delimiter: "semi",
          requireLast: false
        }
      }
    ],
    "@typescript-eslint/member-ordering": "off",
    "@typescript-eslint/naming-convention": "off",
    "@typescript-eslint/no-empty-function": "off",
    "@typescript-eslint/no-empty-interface": "error",
    "@typescript-eslint/no-inferrable-types": [
      "error",
      {
        ignoreParameters: true
      }
    ],
    "@typescript-eslint/no-misused-new": "error",
    "@typescript-eslint/no-non-null-assertion": "error",
    "@typescript-eslint/prefer-function-type": "error",
    "@typescript-eslint/quotes": "off",
    "@typescript-eslint/semi": ["error", "always"],
    "@typescript-eslint/type-annotation-spacing": "error",
    "@typescript-eslint/unified-signatures": "error",
    "arrow-body-style": ["off"],
    "arrow-parens": ["off", "always"],
    "brace-style": ["error", "1tbs"],
    "comma-dangle": "off",
    "constructor-super": "error",
    curly: "error",
    "eol-last": "error",
    eqeqeq: ["error", "smart"],
    "guard-for-in": "error",
    "id-blacklist": "off",
    "id-match": "off",
    "import/no-deprecated": "warn",
    "jsdoc/no-types": "error",
    "linebreak-style": "off",
    "max-len": [
      "error",
      {
        code: 140
      }
    ],
    "new-parens": "off",
    "newline-per-chained-call": "off",
    "no-bitwise": "error",
    "no-caller": "error",
    "no-console": [
      "error",
      {
        allow: [
          "log",
          "dirxml",
          "warn",
          "error",
          "dir",
          "timeLog",
          "assert",
          "clear",
          "count",
          "countReset",
          "group",
          "groupCollapsed",
          "groupEnd",
          "table",
          "Console",
          "markTimeline",
          "profile",
          "profileEnd",
          "timeline",
          "timelineEnd",
          "timeStamp",
          "context"
        ]
      }
    ],
    "no-debugger": "error",
    "no-empty": "off",
    "no-eval": "error",
    "no-extra-semi": "off",
    "no-fallthrough": "error",
    "no-irregular-whitespace": "off",
    "no-multiple-empty-lines": "off",
    "no-new-wrappers": "error",
    "no-restricted-imports": ["error", "rxjs/Rx"],
    "no-shadow": [
      "off",
      {
        hoist: "all"
      }
    ],
    "@typescript-eslint/no-shadow": ["error"],
    "no-throw-literal": "error",
    "no-trailing-spaces": "error",
    "no-undef-init": "error",
    "no-underscore-dangle": "off",
    "no-unused-labels": "error",
    "no-var": "error",
    "prefer-const": "error",
    "quote-props": "off",
    radix: "error",
    "react/jsx-curly-spacing": "off",
    "react/jsx-equals-spacing": "off",
    "react/jsx-wrap-multilines": "off",
    "space-before-function-paren": "off",
    "space-before-blocks": "error",
    "space-in-parens": ["off", "never"],
    "spaced-comment": [
      "error",
      "always",
      {
        markers: ["/"]
      }
    ],
    "@typescript-eslint/tslint/config": [
      "error",
      {
        rules: {
          "import-spacing": true,
          whitespace: [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"]
        }
      }
    ]
  }
};

這是 ESLint 和 Prettier 格式之間的沖突,是一個眾所周知的問題

解決方案是讓 Prettier 處理格式化,而 ESLint 處理代碼質量問題: https://prettier.io/docs/en/integrating-with-linters.html

最快最全面的解決方案是: eslint-config-prettier 它的作用是關閉 ESLint 中的格式化規則,讓 ESLint 只關心代碼質量。 然后您將在保存時、預提交掛鈎(首選)或預推送以重新格式化代碼庫時運行 Prettier。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM