Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/rules/no-unused-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ const Hello = React.createClass({
}
});
```

Dynamic styles are marked as used only if you use a local variable with the same name as the variable in the actual component .

```js
const getStyles = () => {
const styles = StyleSheet.create({
name: {}
})
return styles;
}
const Hello = React.createClass({
render: function() {
const styles = getStyles();
return <Text textStyle={styles.name}>Hello {this.props.name}</Text>;
}
});
```
Rules are also marked as used when they are used in tags that contain the word `style`.

```js
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/rules/no-unused-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ const tests = {
}
});
`,
}, {
code: `
const getStyles = () => {
const styles = StyleSheet.create({
name: {}
})
return styles;
}
const Hello = React.createClass({
render: function() {
const styles = getStyles();
return <Text textStyle={styles.name}>Hello {this.props.name}</Text>;
}
});
`,
}, {
code: `
const Hello = React.createClass({
Expand Down Expand Up @@ -231,6 +246,23 @@ const tests = {
errors: [{
message: 'Unused style detected: styles.text',
}],
}, {
code: `
const getStyles = () => {
return OtherStyleSheet.create({
text: {}
})
}
const Hi = React.createClass({
render: function() {
const globalStyles = getStyles();
return <Text textStyle={globalStyles.text}>Hi {this.props.name}</Text>;
}
});
`,
errors: [{
message: 'Unused style detected: undefined.text',
}],
}, {
code: `
const styles = StyleSheet.create({
Expand Down