Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot disable template rules #821

Open
crushjz opened this issue Apr 30, 2019 · 8 comments
Open

Cannot disable template rules #821

crushjz opened this issue Apr 30, 2019 · 8 comments
Labels

Comments

@crushjz
Copy link

crushjz commented Apr 30, 2019

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

@mgechev mgechev added the bug label May 1, 2019
@rafaelss95
Copy link
Collaborator

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?

@mgechev
Copy link
Owner

mgechev commented May 2, 2019

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

@Plondrein
Copy link

Any update on this?

@SebasG22
Copy link

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

@mgechev @rafaelss95 @crushjz

@mgechev
Copy link
Owner

mgechev commented Sep 25, 2019

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>

@crushjz
Copy link
Author

crushjz commented Oct 8, 2019

@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)

@usmanmustafa33
Copy link

usmanmustafa33 commented Mar 19, 2020

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

@tsvetkovv
Copy link

tsvetkovv commented Feb 13, 2023

The suggested workaround does not work for me as well. It gets rid of 90% of rule violation, but not all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants