Skip to content

Latest commit

 

History

History
439 lines (306 loc) · 4.91 KB

no-call-expression.md

File metadata and controls

439 lines (306 loc) · 4.91 KB

@angular-eslint/template/no-call-expression

Disallows calling expressions in templates, except for output handlers

  • Type: suggestion

Rule Options

The rule accepts an options object with the following properties:

interface Options {
  /**
   * Default: `[]`
   */
  allowList?: string[];
}

Usage Examples

The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit.


❌ - Toggle examples of incorrect code for this rule

Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

❌ Invalid Code

<div>{{ getInfo()() }}</div>
        ~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

❌ Invalid Code

<a href="{{ getUrls().user }}"></a>
            ~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

❌ Invalid Code

<p [test]="test?.getInfo()"></p>
           ~~~~~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

❌ Invalid Code

<a [href]="id && createUrl() && test()($any)">info</a>
                 ~~~~~~~~~~~    ~~~~~~~~~~~~
{{ id || obj?.nested1() }}
         ~~~~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

❌ Invalid Code

<a [href]="id ? a?.createUrl() : editUrl(3)">info</a>
                ~~~~~~~~~~~~~~   ~~~~~~~~~~
{{ 1 === 2 ? 3 : obj?.nested1()() }}
                 ~~~~~~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

❌ Invalid Code

{{ obj?.nested1() }} {{ obj!.nested1() }}
   ~~~~~~~~~~~~~~       ~~~~~~~~~~~~~~
<button [type]="obj!.$any(b)!.getType()()">info</button>
                ~~~~~~~~~~~~~~~~~~~~~~~~~
<a [href]="obj.propertyA?.href()">info</a>
           ~~~~~~~~~~~~~~~~~~~~~



✅ - Toggle examples of correct code for this rule

Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

{{ info }}



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

<button type="button" (click)="handleClick()">Click Here</button>



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

{{ $any(info) }}



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

<input (change)="obj?.changeHandler()">



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

<form [formGroup]="form" (ngSubmit)="form.valid || save()"></form>



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

<form [formGroup]="form" (ngSubmit)="form.valid && save()"></form>



Default Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error"
    ]
  }
}

✅ Valid Code

<form [formGroup]="form" (ngSubmit)="id ? save() : edit()"></form>



Custom Config

{
  "rules": {
    "@angular-eslint/template/no-call-expression": [
      "error",
      {
        "allowList": [
          "nested",
          "getHref"
        ]
      }
    ]
  }
}

✅ Valid Code

{{ obj?.nested() }} {{ obj!.nested() }}
<a [href]="getHref()">info</a>