Skip to content

label-has-associated-control doesn't work with global functions (like a translation function) #633

Open
@wuz

Description

@wuz

Hey there!

In our codebase we have a global translation function that is shared around components. When using label-has-associated-control the linter doesn't seem to be able to determine what that function returns and assumes that it could be an input. Is there a way to add an option for translationFunctions or similar, where a function name could be passed?

Example

// rule config
'jsx-a11y/label-has-associated-control': [
  'error',
  {
    assert: 'either',
  }
],
// t() is a global function that returns a translation string
<label>
{t('some.translation')}
</label>
<input type="text" id="id" />

The above JSX won't fail the rule, even though there isn't an htmlFor attribute and there isn't a nested input in the label.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions