eslint-plugin-react-native
eslint-plugin-react-native copied to clipboard
Rules related to styles object don't work for all definition styles
Version: 3.2.1
I have noticed that rules like no-unused-styles
and no-color-literals
don't work if styles are defined as
let styles;
export default SomeComponent() {
...
}
styles = StyleSheet.create({
...
});
They start working if the definition is made as
export default SomeComponent() {
...
}
const styles = StyleSheet.create({
...
});
I want to prefer keeping the style definitions at the bottom of the file(as others also expressed in other issues) but not at the expense of disabling the no-use-before-define
rule for variables
(which is mentioned as a workaround in another issue).
Is this something that can be fixed? I would like to contribute, but might need some hints.
Hi @prithsharma,
This is possible, I guess you could modify the rule to handle variable assignments a bit more flexible
Another example where this happens is if you define them as a static variable:
class MyComponent extends Component {
static styles = StyleSheet.create({...});
}
this won't be checked also
Another example is if you have it defined on a class, that uses props to determine styles
class MyComponent extends Component {
styles = StyleSheet.create({
something: {
awesome: this.props.isAwesome ? 'orange' : 'black',
}
});
}