TypeScript - Visual Studio Codeでオブジェクトの分割代入のコードフォーマットを無効にする
私はKoaとTypeScriptを使ってウェブアプリを作っています。VSCodeで不要なコードフォーマットに直面しました:オブジェクト分割代入の方法で変数を宣言すると、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
}
}
回答 #1
Beautifyプラグインをインストールし、次の設定をVSCodeのsettings.jsonに追加できます。
"beautify.config": {
"brace_style": "collapse,preserve-inline"
}
