Gathering detailed insights and metrics for eslint-plugin-jsx-a11y
Gathering detailed insights and metrics for eslint-plugin-jsx-a11y
Gathering detailed insights and metrics for eslint-plugin-jsx-a11y
Gathering detailed insights and metrics for eslint-plugin-jsx-a11y
@types/eslint-plugin-jsx-a11y
TypeScript definitions for eslint-plugin-jsx-a11y
eslint-plugin-styled-components-a11y
This plugin adds the ability to lint styled components according to the rules outlined in eslint-plugin-jsx-a11y.
eslint-plugin-jsx-ally
Wrong repo, please install eslint-plugin-jsx-a11y
eslint-config-react-app
ESLint configuration used by Create React App
Static AST checker for a11y rules on JSX elements.
npm install eslint-plugin-jsx-a11y
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3,425 Stars
1,121 Commits
638 Forks
43 Watching
157 Branches
130 Contributors
Updated on 27 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-3%
2,895,779
Compared to previous day
Last week
3.8%
15,598,010
Compared to previous week
Last month
11.8%
64,610,836
Compared to previous month
Last year
16.2%
675,659,612
Compared to previous year
15
1
28
Get professional support for eslint-plugin-jsx-a11y on Tidelift
Static AST checker for accessibility rules on JSX elements.
This plugin does a static evaluation of the JSX to spot accessibility issues in React apps. Because it only catches errors in static code, use it in combination with @axe-core/react to test the accessibility of the rendered DOM. Consider these tools just as one step of a larger a11y testing process and always test your apps with assistive technology.
If you are installing this plugin via eslint-config-airbnb
, please follow these instructions.
You'll first need to install ESLint:
1# npm 2npm install eslint --save-dev 3 4# yarn 5yarn add eslint --dev
Next, install eslint-plugin-jsx-a11y
:
1# npm 2npm install eslint-plugin-jsx-a11y --save-dev 3 4# yarn 5yarn add eslint-plugin-jsx-a11y --dev
Note: If you installed ESLint globally (using the -g
flag in npm, or the global
prefix in yarn) then you must also install eslint-plugin-jsx-a11y
globally.
.eslintrc
)Add jsx-a11y
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
1{ 2 "plugins": ["jsx-a11y"] 3}
Then configure the rules you want to use under the rules section.
1{ 2 "rules": { 3 "jsx-a11y/rule-name": 2 4 } 5}
You can also enable all the recommended or strict rules at once.
Add plugin:jsx-a11y/recommended
or plugin:jsx-a11y/strict
in extends
:
1{ 2 "extends": ["plugin:jsx-a11y/recommended"] 3}
As you are extending our configuration, you can omit
"plugins": ["jsx-a11y"]
from your.eslintrc
configuration file.
1{ 2 "settings": { 3 "jsx-a11y": { 4 "polymorphicPropName": "as", 5 "components": { 6 "CityInput": "input", 7 "CustomButton": "button", 8 "MyButton": "button", 9 "RoundButton": "button" 10 }, 11 "attributes": { 12 "for": ["htmlFor", "for"] 13 } 14 } 15 } 16}
eslint.config.js
)The default export of eslint-plugin-jsx-a11y
is a plugin object.
1const jsxA11y = require('eslint-plugin-jsx-a11y'); 2 3module.exports = [ 4 … 5 { 6 files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'], 7 plugins: { 8 'jsx-a11y': jsxA11y, 9 }, 10 languageOptions: { 11 parserOptions: { 12 ecmaFeatures: { 13 jsx: true, 14 }, 15 }, 16 }, 17 rules: { 18 // ... any rules you want 19 'jsx-a11y/alt-text': 'error', 20 }, 21 // ... others are omitted for brevity 22 }, 23 … 24];
There are two shareable configs, provided by the plugin.
flatConfigs.recommended
flatConfigs.strict
1const jsxA11y = require('eslint-plugin-jsx-a11y'); 2 3export default [ 4 jsxA11y.flatConfigs.recommended, 5 { 6 // Your additional configs and overrides 7 }, 8];
1import jsxA11y from 'eslint-plugin-jsx-a11y'; 2 3export default [ 4 jsxA11y.flatConfigs.recommended, 5 { 6 // Your additional configs and overrides 7 }, 8];
Note: Our shareable configs do NOT configure files
or languageOptions.globals
.
For most of the cases, you probably want to configure some of these properties yourself.
1const jsxA11y = require('eslint-plugin-jsx-a11y'); 2const globals = require('globals'); 3 4module.exports = [ … { files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'], 5 ...jsxA11y.flatConfigs.recommended, 6 languageOptions: { 7 ...jsxA11y.flatConfigs.recommended.languageOptions, 8 globals: { 9 ...globals.serviceworker, 10 ...globals.browser, 11 }, 12 }, 13 }, 14 … 15];
To enable your custom components to be checked as DOM elements, you can set global settings in your configuration file by mapping each custom component name to a DOM element type.
To configure the JSX property to use for attribute checking, you can set global settings in your configuration file by mapping each DOM attribute to the JSX property you want to check.
For example, you may want to allow the for
attribute in addition to the htmlFor
attribute for checking label associations.
You can optionally use the polymorphicPropName
setting to define the prop your code uses to create polymorphic components.
This setting will be used determine the element type in rules that require semantic context.
For example, if you set the polymorphicPropName
setting to as
then this element:
<Box as="h3">Configurations </Box>
will be evaluated as an h3
. If no polymorphicPropName
is set, then the component will be evaluated as Box
.
To restrict polymorphic linting to specified components, additionally set polymorphicAllowList
to an array of component names.
⚠️ Polymorphic components can make code harder to maintain; please use this feature with caution.
💼 Configurations enabled in.
🚫 Configurations disabled in.
☑️ Set in the recommended
configuration.
🔒 Set in the strict
configuration.
💡 Manually fixable by editor suggestions.
❌ Deprecated.
Name | Description | 💼 | 🚫 | 💡 | ❌ |
---|---|---|---|---|---|
accessible-emoji | Enforce emojis are wrapped in <span> and provide screen reader access. | ❌ | |||
alt-text | Enforce all elements that require alternative text have meaningful information to relay back to end user. | ☑️ 🔒 | |||
anchor-ambiguous-text | Enforce <a> text to not exactly match "click here", "here", "link", or "a link". | ☑️ | |||
anchor-has-content | Enforce all anchors to contain accessible content. | ☑️ 🔒 | |||
anchor-is-valid | Enforce all anchors are valid, navigable elements. | ☑️ 🔒 | |||
aria-activedescendant-has-tabindex | Enforce elements with aria-activedescendant are tabbable. | ☑️ 🔒 | |||
aria-props | Enforce all aria-* props are valid. | ☑️ 🔒 | |||
aria-proptypes | Enforce ARIA state and property values are valid. | ☑️ 🔒 | |||
aria-role | Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role. | ☑️ 🔒 | |||
aria-unsupported-elements | Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes. | ☑️ 🔒 | |||
autocomplete-valid | Enforce that autocomplete attributes are used correctly. | ☑️ 🔒 | |||
click-events-have-key-events | Enforce a clickable non-interactive element has at least one keyboard event listener. | ☑️ 🔒 | |||
control-has-associated-label | Enforce that a control (an interactive element) has a text label. | ☑️ 🔒 | |||
heading-has-content | Enforce heading (h1 , h2 , etc) elements contain accessible content. | ☑️ 🔒 | |||
html-has-lang | Enforce <html> element has lang prop. | ☑️ 🔒 | |||
iframe-has-title | Enforce iframe elements have a title attribute. | ☑️ 🔒 | |||
img-redundant-alt | Enforce <img> alt prop does not contain the word "image", "picture", or "photo". | ☑️ 🔒 | |||
interactive-supports-focus | Enforce that elements with interactive handlers like onClick must be focusable. | ☑️ 🔒 | 💡 | ||
label-has-associated-control | Enforce that a label tag has a text label and an associated control. | ☑️ 🔒 | |||
label-has-for | Enforce that <label> elements have the htmlFor prop. | ☑️ 🔒 | ❌ | ||
lang | Enforce lang attribute has a valid value. | ||||
media-has-caption | Enforces that <audio> and <video> elements must have a <track> for captions. | ☑️ 🔒 | |||
mouse-events-have-key-events | Enforce that onMouseOver /onMouseOut are accompanied by onFocus /onBlur for keyboard-only users. | ☑️ 🔒 | |||
no-access-key | Enforce that the accessKey prop is not used on any element to avoid complications with keyboard commands used by a screen reader. | ☑️ 🔒 | |||
no-aria-hidden-on-focusable | Disallow aria-hidden="true" from being set on focusable elements. | ||||
no-autofocus | Enforce autoFocus prop is not used. | ☑️ 🔒 | |||
no-distracting-elements | Enforce distracting elements are not used. | ☑️ 🔒 | |||
no-interactive-element-to-noninteractive-role | Interactive elements should not be assigned non-interactive roles. | ☑️ 🔒 | |||
no-noninteractive-element-interactions | Non-interactive elements should not be assigned mouse or keyboard event listeners. | ☑️ 🔒 | |||
no-noninteractive-element-to-interactive-role | Non-interactive elements should not be assigned interactive roles. | ☑️ 🔒 | |||
no-noninteractive-tabindex | tabIndex should only be declared on interactive elements. | ☑️ 🔒 | |||
no-onchange | Enforce usage of onBlur over onChange on select menus for accessibility. | ❌ | |||
no-redundant-roles | Enforce explicit role property is not the same as implicit/default role property on element. | ☑️ 🔒 | |||
no-static-element-interactions | Enforce that non-interactive, visible elements (such as <div> ) that have click handlers use the role attribute. | ☑️ 🔒 | |||
prefer-tag-over-role | Enforces using semantic DOM elements over the ARIA role property. | ||||
role-has-required-aria-props | Enforce that elements with ARIA roles must have all required attributes for that role. | ☑️ 🔒 | |||
role-supports-aria-props | Enforce that elements with explicit or implicit roles defined contain only aria-* properties supported by that role . | ☑️ 🔒 | |||
scope | Enforce scope prop is only used on <th> elements. | ☑️ 🔒 | |||
tabindex-no-positive | Enforce tabIndex value is not greater than zero. | ☑️ 🔒 |
The following rules have extra options when in recommended mode:
1'jsx-a11y/no-interactive-element-to-noninteractive-role': [ 2 'error', 3 { 4 tr: ['none', 'presentation'], 5 }, 6]
1'jsx-a11y/no-noninteractive-element-interactions': [ 2 'error', 3 { 4 handlers: [ 5 'onClick', 6 'onMouseDown', 7 'onMouseUp', 8 'onKeyPress', 9 'onKeyDown', 10 'onKeyUp', 11 ], 12 }, 13]
1'jsx-a11y/no-noninteractive-element-to-interactive-role': [ 2 'error', 3 { 4 ul: [ 5 'listbox', 6 'menu', 7 'menubar', 8 'radiogroup', 9 'tablist', 10 'tree', 11 'treegrid', 12 ], 13 ol: [ 14 'listbox', 15 'menu', 16 'menubar', 17 'radiogroup', 18 'tablist', 19 'tree', 20 'treegrid', 21 ], 22 li: ['menuitem', 'option', 'row', 'tab', 'treeitem'], 23 table: ['grid'], 24 td: ['gridcell'], 25 }, 26]
1'jsx-a11y/no-noninteractive-tabindex': [ 2 'error', 3 { 4 tags: [], 5 roles: ['tabpanel'], 6 }, 7]
1'jsx-a11y/no-noninteractive-element-interactions': [ 2 'error', 3 { 4 handlers: [ 5 'onClick', 6 'onMouseDown', 7 'onMouseUp', 8 'onKeyPress', 9 'onKeyDown', 10 'onKeyUp', 11 ], 12 }, 13]
If you are developing new rules for this project, you can use the create-rule
script to scaffold the new files.
1./scripts/create-rule.js my-new-rule
An operating system will provide an accessibility API that maps application state and content onto input/output controllers such as a screen reader, braille device, keyboard, etc.
These APIs were developed as computer interfaces shifted from buffers (which are text-based and inherently quite accessible) to graphical user interfaces (GUIs). The first attempts to make GUIs accessible involved raster image parsing to recognize characters, words, etc. This information was stored in a parallel buffer and made accessible to assistive technology (AT) devices.
As GUIs became more complex, the raster parsing approach became untenable. Accessibility APIs were developed to replace them. Check out NSAccessibility (AXAPI) for an example. See Core Accessibility API Mappings 1.1 for more details.
Browsers support an Accessibility API on a per operating system basis. For instance, Firefox implements the MSAA accessibility API on Windows, but does not implement the AXAPI on OSX.
From the W3 Core Accessibility API Mappings 1.1
The accessibility tree and the DOM tree are parallel structures. Roughly speaking the accessibility tree is a subset of the DOM tree. It includes the user interface objects of the user agent and the objects of the document. Accessible objects are created in the accessibility tree for every DOM element that should be exposed to assistive technology, either because it may fire an accessibility event or because it has a property, relationship or feature which needs to be exposed. Generally, if something can be trimmed out it will be, for reasons of performance and simplicity. For example, a
<span>
with just a style change and no semantics may not get its own accessible object, but the style change will be exposed by other means.
Browser vendors are beginning to expose the AX Tree through inspection tools. Chrome has an experiment available to enable their inspection tool.
You can also see a text-based version of the AX Tree in Chrome in the stable release version.
chrome://accessibility/
in Chrome.accessibility off
link for any tab that you want to inspect.show accessibility tree
will appear; click this link.A browser constructs an AX Tree as a subset of the DOM. ARIA heavily informs the properties of this AX Tree. This AX Tree is exposed to the system level Accessibility API which mediates assistive technology agents.
We model ARIA in the aria-query project. We model AXObjects (that comprise the AX Tree) in the axobject-query project. The goal of the WAI-ARIA specification is to be a complete declarative interface to the AXObject model. The in-draft 1.2 version is moving towards this goal. But until then, we must consider the semantics constructs afforded by ARIA as well as those afforded by the AXObject model (AXAPI) in order to determine how HTML can be used to express user interface affordances to assistive technology users.
eslint-plugin-jsx-a11y is licensed under the MIT License.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
27 commit(s) and 12 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
Found 16/29 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More