mgechev / codelyzer

Static analysis for Angular projects.
http://codelyzer.com/
MIT License
2.45k stars 234 forks source link

template-click-events-have-key-events throws error on anchor <a> element #996

Open fikkatra opened 3 years ago

fikkatra commented 3 years ago

Describe the bug

The rule should exclude interactive elements. Buttons are indeed excluded, however, anchor tags with click events (without key events) still cause a lint error:

<a (click)="handleClick()">My link</a>

click must be accompanied by either keyup, keydown or keypress event for accessibility

Context and configuration rule: template-click-events-have-key-events tsconfig.json:

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "types": ["jasmine"]
  },
  "include": [],
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ]
}

tsconfig.base.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "downlevelIteration": true,
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2017", "dom"],
    "baseUrl": ".",
    "paths": {
      "core-js/es7/reflect": ["node_modules/core-js/proposals/reflect-metadata"]
    },
    "rootDir": "."
  },
  "exclude": ["node_modules", "tmp"]
}

no codelyzer.js

Expected behavior

The rule should pass for anchor tags with click events, even if they don't have a key event.

Environment