Skip to content

[label-has-associated-control] Allow overriding of default label inputs #2359

Open
@cprestegard

Description

@cprestegard

Description and reproduction of the issue

The [label-has-associated-control] rule hard codes the default inputs to check for on label elements. It would be great to allow users to override the defaults. This would allow projects to lint labels that rely on custom directives to hook into custom controls.

Suggestion to have the ability to declare the rule like this:

{
  "rules": {
    "@angular-eslint/template/label-has-associated-control": [
      "error",
      {
        "controlComponents": [
          "my-custom-control"
        ],
        "labelComponents": [
          {
            "inputs": [
              "for",
              "htmlFor",
              "myCustomFor"
            ],
            "selector": "label"
          }
        ]
      }
    ]
  }
}

so that the following would be valid:

<label [myCustomFor]="customId">Label</label>
<my-custom-control [id]="customId"></my-custom-control>

Versions

package version
@angular-eslint/eslint-plugin-template 19.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-plugin-templateAngular Template rulestriageThis issue needs to be looked at and categorized by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions