gpt4 book ai didi

typescript - Visual Studio代码禁用对象解构的代码格式

转载 作者:行者123 更新时间:2023-12-02 03:28:01 25 4
gpt4 key购买 nike

我正在使用 Koa 和 Typescript 编写 Web 应用程序。在 vscode 中,我遇到了不需要的代码格式:当我使用对象解构方法声明变量时,vscode 将其自动格式化为多行:

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

await userService.deleteUser(userId);
}

我希望在这种情况下它保持在一行中:

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
}
}

最佳答案

您可以安装美化插件并在vscode的settings.json中添加以下配置。

"beautify.config": {
"brace_style": "collapse,preserve-inline"
}

关于typescript - Visual Studio代码禁用对象解构的代码格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52661491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com