首页 > 解决方案 > tslint 吐出圈复杂度错误

问题描述

在我的 Angular 8 项目中

"codelyzer": "^5.1.0",
"ts-node": "~8.3.0",
"tslint": "~5.19.0",

运行后:

ng lint myapp --fix=true

我得到:

ERROR: ...html:428:106 - The cyclomatic complexity exceeded the defined limit (cost '5'). Your template should be refactored.

即使在我的tslint.js设置中:

{
  "rulesDirectory": ["node_modules/codelyzer"],
  "rules": {
    "template-i18n": false,
    "cyclomatic-complexity": [true, 20],

为什么我在设置““cyclomatic-complexity”:[true,20]”中设置的内容与我为许多文件“(成本'5')”收到的错误消息之间存在这种差异?

另外,为什么会发生这种情况?

标签: angulartslint

解决方案


模板复杂度在不同的规则内,即:

"template-cyclomatic-complexity": [true, 6]

来源https://github.com/fulls1z3/angular-tslint-rules/issues/34

"cyclomatic-complexity": [true, 20],适用于 *.ts 文件


推荐阅读