Skip to main content
Skip to Content
interlace
Plugin: react-a11yRules

label-has-for

Deprecated no-op kept so eslint-plugin-jsx-a11y configs naming it load; it reports nothing.

Next step

label-has-for ships in eslint-plugin-react-a11y, with 37 of its 40 rules in the recommended preset.

Install
npm install -D eslint-plugin-react-a11y
eslint.config.js
import { configs } from 'eslint-plugin-react-a11y';

export default [configs.recommended];

Plugin pagenpmSource on GitHub

Upstream's rule asked for a label to have htmlFor or a nested control. jsx-a11y 6.10.2 deprecates it in favour of label-has-associated-control. This rule is a no-op: enable label-has-associated-control instead.

Quick Summary

AspectDetails
StatusDeprecated (meta.deprecated: true), replaced by label-has-associated-control
ReportsNothing
In presetsNo preset enables it
Optionscomponents, required and allowChildren are accepted, as in upstream's schema, and not read

Why it exists

eslint-plugin-jsx-a11y 6.10.2 still exports this rule, deprecated, and sets it to off in both of its presets. A config that registers this plugin under the jsx-a11y key and names label-has-for, or a // eslint-disable-next-line jsx-a11y/label-has-for comment, would otherwise stop ESLint with "Could not find rule". With this entry it loads and does nothing.

Configuration

// eslint.config.js
import reactA11y from 'eslint-plugin-react-a11y';

export default [
  {
    plugins: { 'jsx-a11y': reactA11y },
    rules: { 'jsx-a11y/label-has-for': 'off' },
  },
];

Further Reading

Use this rule

npm install -D eslint-plugin-react-a11y
eslint.config.js
import reactA11y from 'eslint-plugin-react-a11y';export default [  {    plugins: { 'react-a11y': reactA11y },    rules: {      'react-a11y/label-has-for': 'error'    },  },];
npm install -D oxlint-plugin-react-a11y
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-react-a11y"],  "rules": {    "react-a11y/label-has-for": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-react-a11y'],    rules: {      'react-a11y/label-has-for': 'error',    },  },});

oxlint-plugin-react-a11y re-exports eslint-plugin-react-a11y/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.