Skip to content

Commit

Permalink
JSX-A11Y label-has-for Configuration (#7)
Browse files Browse the repository at this point in the history
* Adjust jsx-a11y linter label-has-for rule.
Allow inputs to have sibling labels with an id associated by htmlFor rather than force labels to wrap around the input.

* Add spec for label-has-for exception.
Demonstrate example of using htmlFor with id for label and inputs for the label-has-for exception introduced in this commit: eb6e63b.
  • Loading branch information
nancynaluz committed Sep 4, 2018
1 parent 1b8e5ec commit 5cfc0fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/eslint-config/eslintrc.json
Expand Up @@ -10,7 +10,17 @@
"rules": {
"max-len": ["error", 100],
"prefer-const": "error",
"no-var": "error"
"no-var": "error",
"jsx-a11y/label-has-for": [
2,
{
"required": {
"every": [
"id"
]
}
}
]
},
"env": {
"mocha": true,
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-config/test/index.js
Expand Up @@ -54,3 +54,11 @@ test('disallows a11y violations', t => {
t.is(result.errorCount, 1)
t.is(result.messages[0].ruleId, 'jsx-a11y/alt-text')
})

test('makes exception for jsx-a11y label-has-for rule', t => {
const result = lint(
`const template = <div><label htmlFor='checkbox'>label</label>
<input id='checkbox' type='checkbox' /></div>`
)
t.is(result.errorCount, 0)
})

0 comments on commit 5cfc0fa

Please sign in to comment.