Skip to content

no-unused-styles doesn't work with functions and vars #15

@yelled3

Description

@yelled3

when I added the rule for no-unused-styles to my project I got many errors.
most of them were due to styles dynamically loaded from functions or vars.

consider the following use cases:

class MyView extends Component {

  static propTypes = {
    isActive: React.PropTypes.bool,
    type: React.PropTypes.oneOf(['typeA', 'typeB'])
  };

  get myActiveStyle() {
     return this.props.isActive ? style.active : {}
  }

 render() {
    var typeStyle = styles[this.props.type];
    return (
      <View style={[this.activeStyle, typeStyle]} / >
    );
  }

}

// All 3 styles will be marked as unused
const styles = StyleSheet.create({
   active: {...},
   typeA: {...},
   typeB: {...},
})

my current solution is to wrap the erroring code with:

/*eslint-disable react-native/no-unused-styles */
 const styles = StyleSheet.create({...});
/*eslint-enable react-native/no-unused-styles */

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions