eslint-plugin-react-native icon indicating copy to clipboard operation
eslint-plugin-react-native copied to clipboard

no-unused-styles does not work when React Native imported as whole module

Open aeirola opened this issue 6 years ago • 1 comments

Our project conventions prefer namespaced imports of libraries, meaning that we import React Native with import RN from 'react-native'; instead of import {Long, List, Of, Things} from 'react-native';. Unfortunately for us, it seems as if the no-unused-styles rule is not compatible with this type of import usage.

For example, the following code

import RN from 'react-native';

const styles = RN.StyleSheet.create({
 unusedStyle: {},
});

does not trigger the rule.

I tried configuring the react-native/style-sheet-object-names setting to ["RN.StyleSheet"], but this didn't seem to help the situation.

I wonder if it would be possible to improve the rule so that it is able to identify the cases where the StyleSheet isn't imported individually.

aeirola avatar Apr 23 '19 08:04 aeirola

I made a PR to fix this at #228

aeirola avatar May 03 '19 05:05 aeirola