Giter VIP home page Giter VIP logo

eslint-plugin-react-native-a11y's Introduction

Eslint-plugin-react-native-a11y — Formidable, We build the modern web

Maintenance Status

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:

npm install eslint-plugin-react-native-a11y --save-dev

# or

yarn 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:

// .eslintrc.js

module.exports = {
  root: true,
  extends: [
    '@react-native-community',
    'plugin:react-native-a11y/ios'
  ]
};

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.

// .eslintrc.js

module.exports = {
  root: true,
  extends: [
    '@react-native-community',
  ],
  rules: {
    'react-native-a11y/rule-name': 2
  }
};

For more information on configuring behaviour of an individual rule, please refer to the ESLint docs

Supported Rules

Basic

iOS

Android

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.

"react-native-a11y/has-accessibility-props": [
  "error",
  {
    "touchables": ["TouchableCustom"]
  }
]

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.

"react-native-a11y/has-valid-accessibility-ignores-invert-colors": [
  "error",
  {
    "invertableComponents": [
      "FastImage",
    ]
  }
]

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: Formidable 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.

eslint-plugin-react-native-a11y's People

Contributors

jpdriver avatar alex-saunders avatar draperunner avatar imranolas avatar gabts avatar cpresler avatar virtualdominic avatar jevakallio avatar knitcodemonkey avatar aryanj-nyc avatar dylmye avatar gksander avatar fawcilize avatar mattvot avatar boygirl avatar grgr-dkrk avatar philihp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.