首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Visual Studio代码禁用对象析构的代码格式

Visual Studio代码禁用对象析构的代码格式
EN

Stack Overflow用户
提问于 2018-10-05 16:31:27
回答 1查看 579关注 0票数 1

我正在使用Koa和Typescript编写web应用程序。在vscode中,我遇到了不必要的代码格式化:当我使用对象描述方法声明变量时,vscode会在多行中自动格式化变量:

代码语言:javascript
复制
deleteUser: async (ctx: Context) => {
  const {
    body: { userId }
  } = ctx;

  await userService.deleteUser(userId);
}

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

代码语言:javascript
复制
deleteUser: async (ctx: Context) => {
  const { body: { userId } } = ctx;

  await userService.deleteUser(userId);
}

我喜欢vscode处理代码格式化的方式,所以我不想禁用它。但是我想找到一个解决方法,如果行长度小于80个字符,就禁用对象解构格式化。

我应该使用什么规则来解决这个问题?我应该更改vscode规则还是tslint规则?

这是我的.tslint文件:

代码语言:javascript
复制
{
  "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
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-02-12 16:23:54

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

代码语言:javascript
复制
"beautify.config": {
    "brace_style": "collapse,preserve-inline"
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52661491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档