1

Koa と Typescript を使用して Web アプリを作成しています。vscode では、不要なコードの書式設定に直面しました。

deleteUser: async (ctx: Context) => {
  const {
    body: { userId }
  } = ctx;

  await userService.deleteUser(userId);
}

そして、この場合は1行のままにしたい:

deleteUser: async (ctx: Context) => {
  const { body: { userId } } = ctx;

  await userService.deleteUser(userId);
}

vscode がコードの書式設定を処理する方法が気に入っているので、無効にしたくありません。しかし、行の長さが80文字未満の場合、オブジェクトの構造化フォーマットを無効にする回避策を見つけたいです。

これを修正するには、どのルールを使用すればよいですか? vscode ルールまたは tslint ルールを変更する必要がありますか?

これが私の .tslint ファイルです:

{
  "rules": {
    "class-name": true,
    "comment-format": [true, "check-space"],
    "indent": ["tabs"],
    "one-line": [true, "check-open-brace", "check-whitespace"],
    "no-var-keyword": true,
    "quotemark": [true, "double", "avoid-escape"],
    "semicolon": [true, "always", "ignore-bound-class-methods"],
    "max-line-length": [true, 120],
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-module",
      "check-separator",
      "check-type",
      "check-preblock"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      },
      {
        "call-signature": "onespace",
        "index-signature": "onespace",
        "parameter": "onespace",
        "property-declaration": "onespace",
        "variable-declaration": "onespace"
      }
    ],
    "no-internal-module": true,
    "no-trailing-whitespace": true,
    "no-null-keyword": true,
    "prefer-const": true,
    "jsdoc-format": true
  }
}
4

1 に答える 1

5

beautify プラグインをインストールし、vscode の settings.json に次の構成を追加できます。

"beautify.config": {
    "brace_style": "collapse,preserve-inline"
}
于 2020-02-12T08:23:53.800 に答える