Skip to content

Commit 5b52a21

Browse files
committed
fix: undetected usage in default export Closes #4
1 parent 546fb25 commit 5b52a21

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

lib/rules/no-unused-styles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const create = Components.detect((context, components) => {
5959

6060
CallExpression: function (node) {
6161
if (astHelpers.isStyleSheetDeclaration(node, context.settings)) {
62+
// TODO
63+
// const isExported = astHelpers.isStyleSheetExported(node);
64+
// if (isExported) {
65+
// return;
66+
// }
6267
const styleSheetObjectName = astHelpers.getStyleSheetObjectName(node);
6368
const styles = astHelpers.getStyleDeclarations(node);
6469

lib/util/stylesheet.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ const astHelpers = {
110110
);
111111
},
112112

113+
// TODO check if the stylesheet is exported, and add "ignore-exported- sheets" setting
114+
// isStyleSheetExported: function (node) {
115+
// return false;
116+
// },
117+
113118
isUseStylesHook: function (node) {
114119
return Boolean(
115120
node
@@ -150,7 +155,7 @@ const astHelpers = {
150155
if (componentNode.type === 'FunctionDeclaration') {
151156
return componentNode.id.name;
152157
}
153-
if (componentNode.type === 'ExportNamedDeclaration') {
158+
if (componentNode.type === 'ExportNamedDeclaration' || componentNode.type === 'ExportDefaultDeclaration') {
154159
if (componentNode.declaration.type === 'FunctionDeclaration') {
155160
return componentNode.declaration.id.name;
156161
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-native-unistyles",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"author": "RodSarhan",
55
"license": "MIT",
66
"description": "React Native Unistyles rules for ESLint",

tests/lib/rules/no-unused-styles.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ const tests = {
316316
const MyComponent = () => {
317317
const {styles} = useStyles(styleSheet);
318318
319+
return (
320+
<Text style={styles.text}>Hello</Text>
321+
);
322+
};
323+
`,
324+
}, {
325+
code: `
326+
const styleSheet = createStyleSheet({
327+
text: {},
328+
});
329+
export default function MyComponent() {
330+
const {styles} = useStyles(styleSheet);
331+
319332
return (
320333
<Text style={styles.text}>Hello</Text>
321334
);

0 commit comments

Comments
 (0)