简体   繁体   English

tslint:所需的卷曲无效

[英]tslint: curly as-needed has no effect

https://palantir.github.io/tslint/rules/curly/ https://palantir.github.io/tslint/rules/curly/

I checked the document and added this in my tslint.json file. 我检查了文档并将其添加到tslint.json文件中。

"curly": [
  true, "as-needed"
],

However, when I ran tslint myapp.ts , I still got error like below. 但是,当我运行tslint myapp.ts ,仍然出现如下错误。

ERROR: express-app/app.ts[28, 5]: if statements must be braced

The statement it mentioned looks like this. 它提到的声明看起来像这样。

    if (server)
      server.close(() => console.log('closed'));

But I think with that curly configuration, tslint would allow me to write if statements like this. 但是我认为使用这种卷曲的配置, tslint可以让我编写类似if的语句。

Environment 环境

  • tslint: 4.5.1 tslint:4.5.1
  • typescript: 3.3.3333 打字稿:3.3.3333

Full tslint.json 完整的tslint.json

{
  "extends": [
    "tslint:recommended"
  ],
  "jsRules": {},
  "rules": {
    "quotemark": [
      true,
      "single"
    ],
    "curly": [
      true, "as-needed"
    ],
    "radix": [
      false
    ],
    "arrow-parens": [
      true,
      "ban-single-arg-parens"
    ],
    "no-console": [
      true,
      "error"
    ]
  },
  "rulesDirectory": []
}

It looks like the "as-needed" option was added in tslint@5.4.0 . 看起来tslint@5.4.0中添加了"as-needed"选项。

To get it to work, update tslint to that version (by running npm i -D tslint@^5.4.0 , or however else you like to update your dependencies). 要使其正常工作, tslint更新到该版本(通过运行npm i -D tslint@^5.4.0 ,否则,您希望更新依赖项)。

Note this crosses a major version bump so there may be breaking changes. 请注意,这跨越了主要版本的障碍,因此可能会有重大更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM