FormidableLabs / eslint-plugin-react-native-a11y

React Native specific accessibility linting rules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prop value validators should allow expressions as possible valid values

jevakallio opened this issue · comments

Currently prop validators assume that the prop value is a string literal, and reports an error if it doesn't match one of the preset values.

Instead, the rule should allow expressions and variables and assume the value is valid. E.g.

<Text accessibilityLiveRegion={variable}>Click Me</Text>
<Text accessibilityLiveRegion={variable ? 'polite' : 'assertive'}>Click Me</Text>
<Text accessibilityLiveRegion={getLiveRegionValue()}>Click Me</Text>
<Text accessibilityLiveRegion={this.props.liveRegion}>Click Me</Text>

In these cases the linter cannot easily know what the value is, and attempting that is out of scope for ESLint. React PropTypes and the built-in React Native Flowtypes can provide more safety to the end user who wants to do dynamic accessibility props.

Affected rules:

I'm still experiencing this. Here's an example:

<View 
  importantForAccessibility={isHidden ? 'no-hide-descendants' : 'yes'}
/>

And this is the error:

importantForAccessibility must be one of defined valueseslint(react-native-a11y/has-valid-important-for-accessibility)

I'm using version 2.0.0

commented

reopening for reinvestigation on 2.0.0