Skip to content

Commit

Permalink
Enable some eslint-plugin-jsx-a11y rules
Browse files Browse the repository at this point in the history
- `jsx-a11y/click-events-have-key-events` as a warning
- `jsx-a11y/mouse-events-have-key-events` as a warning
- `jsx-a11y/no-onchange` as an error
- `jsx-a11y/onclick-has-focus` as an error
- `jsx-a11y/onclick-has-role` as an error
  • Loading branch information
wyze committed Mar 21, 2017
1 parent c7fd855 commit 63f1686
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rules/__tests__/react-a11y.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { rules } from '../react-a11y'

describe('react-a11y rules', () => {
it('contains only react-a11y rules', () => {
const keys = Object.keys(rules)
const expected = Array.from(
keys, () => expect.stringMatching(/^jsx-a11y\/.+$/),
)

expect(keys).toEqual(expected)
})
})
19 changes: 19 additions & 0 deletions rules/react-a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
rules: {
// require onClick be accompanied by onKeyUp/onKeyDown/onKeyPress
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/click-events-have-key-events.md
'jsx-a11y/click-events-have-key-events': 'warn',
// require that mouseover/out come with focus/blur, for keyboard-only users
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md
'jsx-a11y/mouse-events-have-key-events': 'warn',
// require onBlur instead of onChange
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md
'jsx-a11y/no-onchange': 'error',
// Enforce that elements with onClick handlers must be focusable.
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/onclick-has-focus.md
'jsx-a11y/onclick-has-focus': 'error',
// require things with onClick to have an aria role
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/onclick-has-role.md
'jsx-a11y/onclick-has-role': 'error',
},
}

0 comments on commit 63f1686

Please sign in to comment.