Skip to content

Latest commit

 

History

History
412 lines (281 loc) · 4.19 KB

File metadata and controls

412 lines (281 loc) · 4.19 KB

@angular-eslint/template/button-has-type

Ensures that a button has a valid type specified

  • Type: suggestion

Rule Options

The rule does not have any configuration options.


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/button-has-type": [
      "error"
    ]
  }
}

❌ Invalid Code

<button></button>
~~~~~~~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

❌ Invalid Code

<button (click)="onClick()"></button>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

❌ Invalid Code

<button type="whatever"></button>
        ~~~~~~~~~~~~~~~



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

❌ Invalid Code

<button [attr.type]="'whatever'"></button>
        ~~~~~~~~~~~~~~~~~~~~~~~~



✅ - Toggle examples of correct code for this rule

Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button [attr.type]="'button'"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button [attr.type]="'submit'"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button [attr.type]="'reset'"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button type="button"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button type="submit"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button type="reset"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button class="primary" type="submit"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button (click)="onClick()" type="button"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button [class.primary]="true" [attr.type]="'submit'"></button>



Default Config

{
  "rules": {
    "@angular-eslint/template/button-has-type": [
      "error"
    ]
  }
}

✅ Valid Code

<button [disabled]="true" [attr.type]="'button'"></button>