eslint-plugin-react-native: no-unused-styles doesn't work when imporing from file
import styles from './styles';
Should work If I import the styles from a file instead of the same js file? Or is not implemented yet.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 19
- Comments: 15 (5 by maintainers)
Commits related to this issue
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to retyui/eslint-plugin-react-native by retyui 3 years ago
- [fix] 'no-unused-styles' doesn't work when imporing from file Issue: https://github.com/Intellicode/eslint-plugin-react-native/issues/165#issuecomment-983636750 — committed to beedeez/eslint-plugin-react-native by retyui 3 years ago
@Intellicode I would like to help out with this feature.
Could you give me some hints, as I haven’t written any eslint plugins for a while and never something that accessed multiple files.
latest version release
PR merged
Waiting to be released
Actually, it’s not merged in the main branch of this repo yet, the PR is still pending further review, but my time is too limited to wrap that up at the moment.
I guess its about time for that, sorry for the inactivity
I created a PR https://github.com/Intellicode/eslint-plugin-react-native/pull/303 to fix this issue:
Docs: https://github.com/retyui/eslint-plugin-react-native/blob/no-unused-styles-and-imports/docs/rules/no-unused-styles.md#options
If you want to test it you can install the version from Github:
Are there any updates on this?
@skovhus Cool to hear you want to give it a shot!
I suppose you would need to start by analyzing the file which uses the styles to detect which variables are used in
style
attributes. You need to follow them back to the imports, and then parse the imported files to match the imported variable against an exported variable. In this file you would also need to check which variables have a StyleSheet.create call assigned to them. Currently, I also don’t have hands-on experience with parsing an imported file, but hope this is enough for you to get started!At the moment, I do not have any roadmap and I’m also not actively developing new features. If you need it fast, you could help out by writing a PR 😃