codelyzer
codelyzer copied to clipboard
Cannot disable template rules
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
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.
@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
The suggested workaround does not work for me as well. It gets rid of 90% of rule violation, but not all.