Prop value validators should allow expressions as possible valid values
jevakallio opened this issue · comments
Jani Eväkallio commented
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:
- https://github.com/FormidableLabs/eslint-plugin-react-native-a11y/blob/6d01b1d8d0575b27a7ed6adb4bc3b6e298b797f5/src/rules/has-valid-accessibility-component-type.js
- https://github.com/FormidableLabs/eslint-plugin-react-native-a11y/blob/6d01b1d8d0575b27a7ed6adb4bc3b6e298b797f5/src/rules/has-valid-accessibility-traits.js
- https://github.com/FormidableLabs/eslint-plugin-react-native-a11y/blob/677f4b40dd851f0dd1407bf389070a523598d6d3/src/rules/has-valid-accessibility-live-region.js
- https://github.com/FormidableLabs/eslint-plugin-react-native-a11y/blob/2487af1394d2fce4bf77a56dbe646ed4ebdaa76b/src/rules/has-valid-important-for-accessibility.js
marcelkalveram commented
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
JP commented
reopening for reinvestigation on 2.0.0