Codelyzer: Cannot disable template rules

Created on 30 Apr 2019  路  7Comments  路  Source: mgechev/codelyzer

Describe the bug

Can't disable the template-cyclomatic-complexity rule.

Context and configuration

I'm using tslint in an Angular project.

tsconfig.json setting: "template-cyclomatic-complexity": [true, 10],

Following this readme (https://github.com/mgechev/codelyzer/blob/master/README.md#disable-a-rule-that-validates-template-or-styles) in order to disable a rule, I have to write the tslint:disable:rule in the ts file that references the template.

When I execute the ng lint command _without_ the tslint:disable:rule comment, I can see this output:

ERROR: /project/src/app/module/components/temp/temp.component.html:7:2 - The cyclomatic complexity exceeded the defined limit (cost '10'). Your template should be refactored.
ERROR: /project/src/app/module/components/temp/temp.component.html:48:6 - The cyclomatic complexity exceeded the defined limit (cost '10'). Your template should be refactored.
ERROR: /project/src/app/module/components/temp/temp.component.html:59:16 - The cyclomatic complexity exceeded the defined limit (cost '10'). Your template should be refactored.

If I _add_ the tslint:disable:rule comment, this is the output:

ERROR: /project/src/app/module/components/temp/temp.component.html:7:2 - The cyclomatic complexity exceeded the defined limit (cost '10'). Your template should be refactored.

__Seems that the rule is not entirely disabled.__

To Reproduce

ng lint on the root of the project.

Expected behavior

The rule should be disabled entirely.

Code

/* tslint:disable:template-cyclomatic-complexity */
@Component({
  selector: 'temp',
  templateUrl: './temp.component.html',
  styleUrls: ['./temp.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})

Environment

  • OS: MacOS
  • Node.js version: 8.11.3
  • npm version: 6.9.0
  • Angular version: "@angular/core": "^7.2.0"
  • tslint version: "tslint": "^5.15.0" "tslint-angular": "^1.1.2"

Additional context

N/A

bug

Most helpful comment

@mgechev
Unfortunately it does not work if you have multiple pieces of code violating that rule.

The rule I'm using is template-no-call-expression.

I cannot test the rule template-cyclomatic-complexity right now because we have disabled it completely from our project.

(I have also updated codelyzer to 5.1.2 and tslint to 5.20.0)

All 7 comments

Additional fact: the disable like comment works if you use _inline_ template.

I took a quick look and could not find where this error might be (btw, we have no test for this). Any thoughts, @mgechev?

I will take a look at this right after I/O.

Any update on this?

Hi guys, any updates?
This happens when you get the value of a reactive form in the template.
image

@mgechev @rafaelss95 @crushjz

The following workaround would work (I know it's not ideal):

/* tslint:disable:template-cyclomatic-complexity */
@Component({
  selector: 'temp',
  templateUrl: './temp.component.html',
  styleUrls: ['./temp.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class Foo {}

And in your template:

<!-- tslint:disable:template-cyclomatic-complexity -->
<div>
  ...
</div>

@mgechev
Unfortunately it does not work if you have multiple pieces of code violating that rule.

The rule I'm using is template-no-call-expression.

I cannot test the rule template-cyclomatic-complexity right now because we have disabled it completely from our project.

(I have also updated codelyzer to 5.1.2 and tslint to 5.20.0)

Any update on this?

I am facing the same problem for tslint:disable:template-i18n, We need to disable template-i18n rule for some templates in our project but it's not working.

@rafaelss95 @mgechev

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wKoza picture wKoza  路  6Comments

lazarljubenovic picture lazarljubenovic  路  4Comments

rolandjitsu picture rolandjitsu  路  5Comments

jamesbirtles picture jamesbirtles  路  3Comments

marbug picture marbug  路  3Comments