mgechev / mgechev/codelyzer

Cannot disable template rules

Open
#821 8 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.5k
Forks
232
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with ng lint using the shown tsconfig.json setting and the template-cyclomatic-complexity comment in the component. Trace how the Angular template rule receives disable directives and verify the expected result: all diagnostics for that rule disappear when it is disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.