Skip to content

feat: update unused styles docs #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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