ESLintの仕様上?によるものだと思うのですが、以下のようなコードだとUnused style detected: styles.containerStyle (react-native/no-unused-styles)
ESLintに怒られてしまいます
JS
1import React from 'react'; 2import { StyleSheet, View, Text } from 'react-native'; 3 4class Home extends React.Component { 5 render() { 6 7 // styles.containerStyleとやればエラーはでないけど 8 // この書き方をするとエラーが出る 9 const { containerStyle, textStyle } = styles; 10 11 return ( 12 <View style={containerStyle}> 13 <Text style={textStyle}>Home</Text> 14 </View> 15 ); 16 } 17} 18 19const styles = StyleSheet.create({ 20 containerStyle: { // ここ 21 flex: 1, 22 alignItems: 'center', 23 justifyContent: 'center' 24 }, 25 textStyle: { // ここも 26 fontSize: 20 27 } 28}); 29 30export default Home;
ESLintの設定は現在はこうなっています
json
1{ 2 "env": { 3 "browser": true, 4 "node": true, 5 "es6": true 6 }, 7 "extends": "eslint:recommended", 8 "parserOptions": { 9 "ecmaVersion": 6, 10 "ecmaFeatures": { 11 "experimentalObjectRestSpread": true, 12 "jsx": true 13 }, 14 "sourceType": "module" 15 }, 16 "plugins": [ 17 "react", 18 "react-native" 19 ], 20 "rules": { 21 "indent": [ 22 "error", 23 2, 24 { "SwitchCase": 1 } 25 ], 26 "linebreak-style": [ 27 "error", 28 "unix" 29 ], 30 "quotes": [ 31 "error", 32 "single" 33 ], 34 "semi": [ 35 "error", 36 "always" 37 ], 38 "react-native/no-unused-styles": 2, 39 "react-native/split-platform-components": 2, 40 "react-native/no-inline-styles": 2, 41 "react-native/no-color-literals": 2, 42 "react/jsx-uses-vars": 1 43 } 44}
上のような書き方ではエラーは避けられないものなのでしょうか?
よろしくお願いいたします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/21 02:23