React Native specific accessibility linting rules.
Installations
npm install eslint-plugin-react-native-a11y
Releases
Contributors
Developer
FormidableLabs
Developer Guide
Module System
CommonJS
Min. Node Version
>=12.0
Typescript Support
No
Node Version
18.20.4
NPM Version
10.7.0
Statistics
285 Stars
125 Commits
24 Forks
50 Watching
5 Branches
83 Contributors
Updated on 17 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
10,036,175
Last day
7.7%
14,003
Compared to previous day
Last week
11.9%
72,524
Compared to previous week
Last month
9.5%
292,130
Compared to previous month
Last year
19.9%
3,326,322
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Peer Dependencies
1
Dev Dependencies
23
Eslint-plugin-react-native-a11y is a collection of React Native specific ESLint rules for identifying accessibility issues. Building upon the foundation set down by eslint-plugin-jsx-a11y, eslint-plugin-react-native-a11y detects a few of the most commonly made accessibility issues found in react native apps. These rules make it easier for your apps to be navigable by users with screen readers.
Setup
Pre-Requisites
Before starting, check you already have ESLint as a devDependency
of your project.
Projects created using
react-native init
will already have this, but for Expo depending on your template you may need to follow ESLint's installation instructions.
Installation
Next, install eslint-plugin-react-native-a11y
:
1npm install eslint-plugin-react-native-a11y --save-dev 2 3# or 4 5yarn add eslint-plugin-react-native-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-react-native-a11y
globally.
Configuration
This plugin exposes four recommended configs.
Name | Description |
---|---|
basic | Only use basic validation rules common to both iOS & Android |
ios | Use all rules from "basic", plus iOS-specific extras |
android | Use all rules from "basic", plus Android-specific extras |
all | Use all rules from "basic", plus iOS-specific extras, plus Android-specific extras |
If your project only supports a single platform, you may get the best experience using a platform-specific config. This will both avoid reporting issues which do not affect your platform and also results in slightly faster linting for larger projects.
If you are unsure which one to use, in most cases
all
can be safely used.
Add the config you want to use to the extends
section of your ESLint config using the pattern plugin:react-native-a11y/
followed by your config name, as shown below:
1// .eslintrc.js 2 3module.exports = { 4 root: true, 5 extends: ['@react-native-community', 'plugin:react-native-a11y/ios'], 6};
Alternatively if you do not want to use one of the pre-defined configs — or want to override the behaviour of a specific rule — you can always include a list rules and configurations in the rules
section of your ESLint config.
1// .eslintrc.js 2 3module.exports = { 4 root: true, 5 extends: ['@react-native-community'], 6 rules: { 7 'react-native-a11y/rule-name': 2, 8 }, 9};
For more information on configuring behaviour of an individual rule, please refer to the ESLint docs
Supported Rules
Basic
- has-accessibility-hint: Enforce
accessibilityHint
is used in conjunction withaccessibilityLabel
- has-accessibility-props: Enforce that
<Touchable\*>
components only have either theaccessibilityRole
prop or bothaccessibilityTraits
andaccessibilityComponentType
props set - has-valid-accessibility-actions: Enforce both
accessibilityActions
andonAccessibilityAction
props are valid - has-valid-accessibility-role: Enforce
accessibilityRole
property value is valid - has-valid-accessibility-state: Enforce
accessibilityState
property value is valid - has-valid-accessibility-states: Enforce
accessibilityStates
property value is valid - has-valid-accessibility-component-type: Enforce
accessibilityComponentType
property value is valid - has-valid-accessibility-traits: Enforce
accessibilityTraits
andaccessibilityComponentType
prop values must be valid - has-valid-accessibility-value: Enforce
accessibilityValue
property value is valid - no-nested-touchables: Enforce if a view has
accessible={true}
, that there are no touchable elements inside - has-valid-accessibility-descriptors: Ensures that Touchable* components have appropriate props to communicate with assistive technologies
iOS
- has-valid-accessibility-ignores-invert-colors: Enforce that certain elements use
accessibilityIgnoresInvertColors
to avoid being inverted by device color settings.
Android
- has-valid-accessibility-live-region: Enforce
accessibilityLiveRegion
prop values must be valid - has-valid-important-for-accessibility: Enforce
importantForAccessibility
property value is valid
Rule Options
The following options are available to customize the recommended rule set.
Custom Touchables
react-native-a11y/has-accessibility-props
and react-native-a11y/no-nested-touchables
allow you to define an array of names for custom components that you may have that conform to the same accessibility interfaces as Touchables.
1"react-native-a11y/has-accessibility-props": [ 2 "error", 3 { 4 "touchables": ["TouchableCustom"] 5 } 6]
Custom Invertable Components (iOS)
react-native-a11y/has-valid-accessibility-ignores-invert-colors
allows you to optionally define an Array of component names to check in addition to <Image />
.
For more information, see the rule docs.
1"react-native-a11y/has-valid-accessibility-ignores-invert-colors": [ 2 "error", 3 { 4 "invertableComponents": [ 5 "FastImage", 6 ] 7 } 8]
Creating a new rule
If you are developing new rules for this project, you can use the create-rule
script to scaffold the new files.
$ ./scripts/create-rule.js my-new-rule
Attribution
This project started as a fork of eslint-plugin-jsx-a11y and a lot of the work was carried out by its contributors, to whom we owe a lot!
License
eslint-plugin-react-native-a11y is licensed under the MIT License.
Maintenance Status
Active: Nearform is actively working on this project, and we expect to continue for work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
Found 8/26 approved changesets -- score normalized to 3
Reason
4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'deployments' permission set to 'write': .github/workflows/release.yml:18
- Warn: jobLevel 'packages' permission set to 'write': .github/workflows/release.yml:19
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/release.yml:14
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/FormidableLabs/eslint-plugin-react-native-a11y/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/FormidableLabs/eslint-plugin-react-native-a11y/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/FormidableLabs/eslint-plugin-react-native-a11y/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/FormidableLabs/eslint-plugin-react-native-a11y/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/FormidableLabs/eslint-plugin-react-native-a11y/release.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/FormidableLabs/eslint-plugin-react-native-a11y/release.yml/master?enable=pin
- Info: 0 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 20 are checked with a SAST tool
Reason
12 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.4
/10
Last Scanned on 2024-11-25
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 MoreOther packages similar to eslint-plugin-react-native-a11y
eslint-plugin-jsx-a11y
Static AST checker for accessibility rules on JSX elements.
eslint-config-react-app
ESLint configuration used by Create React App
eslint-config-airbnb
Airbnb's ESLint config, following our styleguide
eslint-plugin-react-native
React Native specific linting rules for ESLint