【发布时间】:2017-08-14 18:53:25
【问题描述】:
有没有办法在基于 React 的项目中自动找到未使用的样式定义,就像这个例子一样?
之前:
const styles = StyleSheet.create({
name: {
color: '#e5e5e5'
}
});
const Hello = React.createClass({
render: function() {
return <Text style={styles.name}>Hello {this.props.name}</Text>;
}
});
之后:
开发者更改了样式,不再需要“名称”。这种死气沉沉的代码怎么能自动找到呢?
const styles = StyleSheet.create({
name: { // Redundant now!
color: '#e5e5e5'
},
foo: {
color: '#e2e3b5'
}
});
const Hello = React.createClass({
render: function() {
return <Text style={styles.foo}>Hello {this.props.name}</Text>;
}
});
【问题讨论】:
-
你试过 ESLint 吗?我不确定它是否会检测到这个特定示例,但它通常有助于识别未使用的变量和定义。
-
@MartinMihaylov 对 styles.name 的引用在 JSX/HTML 中,所以我很确定 Linter 将无法捕捉到它 =/
-
CSS 模块看起来很有前途medium.com/@pioul/…