React Native Accessibility ESLint Rules

3.5.1 · active · verified Sun Apr 19

eslint-plugin-react-native-a11y is an ESLint plugin specifically designed to identify common accessibility issues within React Native applications. It extends the principles of web accessibility linters like `eslint-plugin-jsx-a11y` by providing rules tailored to React Native's unique component structure and accessibility APIs. The plugin offers real-time feedback during development, helping teams create more inclusive and navigable experiences for users with screen readers and other assistive technologies. Currently stable at version `3.5.1`, it sees an active development pace with frequent patch and minor releases addressing bug fixes and new features. A key differentiator is its ability to offer platform-specific configurations (`basic`, `ios`, `android`, `all`) to optimize linting for projects targeting particular environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates installing the plugin via npm and configuring it in a `.eslintrc.js` file to extend the `all` recommended accessibility rules for a React Native project. It also shows where to include `eslint` as a dev dependency in `package.json`.

{
  "name": "my-react-native-app",
  "version": "1.0.0",
  "private": true,
  "devDependencies": {
    "eslint": "^8.0.0",
    "eslint-plugin-react-native-a11y": "^3.5.1"
  }
}

// .eslintrc.js
module.exports = {
  root: true,
  extends: [
    // Assuming you have an existing React Native ESLint config
    // e.g., '@react-native-community'
    // 'plugin:react-native-a11y/basic', // For basic rules common to both platforms
    // 'plugin:react-native-a11y/ios',   // For iOS-specific rules
    // 'plugin:react-native-a11y/android', // For Android-specific rules
    'plugin:react-native-a11y/all'    // For all rules (most comprehensive)
  ],
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    }
  },
  rules: {
    // Example of overriding a rule or adding a specific one
    // 'react-native-a11y/has-valid-accessibility-role': 'error',
    // 'react-native-a11y/has-accessibility-props': ['warn', {
    //   touchableComponents: ['TouchableOpacity', 'TouchableHighlight', 'TouchableWithoutFeedback', 'Pressable']
    // }]
  }
};

view raw JSON →