Describe the issue
@stylexjs/no-unused treats a stylex.create() object as entirely unused when it is
exported with the specifier form (export { styles };), even though another module may
consume any of its keys.
The rule already exempts the other export forms — export const styles = stylex.create({...}),
export default styles — so the specifier form looks like an oversight rather than intent.
Because the rule is fixable: 'code', running ESLint with --fix deletes the style keys
from the source file. So this is not just noise: it silently removes working styles.
Expected behavior
No report. An exported styles object may have its keys used by another module, so the rule
cannot know whether they are unused — which is exactly why the other export forms are
already exempt.
Behaviour by export form
| Source |
Reported? |
Correct? |
export const styles = stylex.create({...}) |
no |
✅ |
export default styles |
no |
✅ |
const styles = stylex.create({...}); export { styles }; |
yes |
❌ false positive |
const styles = stylex.create({...}); export { styles as s }; |
yes |
❌ false positive |
Steps to reproduce
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { color: 'red' },
secondary: { color: 'blue' },
});
export { styles };
With '@stylexjs/no-unused': 'error':
error Unused style detected: styles.main @stylexjs/no-unused
error Unused style detected: styles.secondary @stylexjs/no-unused
eslint --fix strips both keys, rewriting the file to:
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
});
export { styles };
Same behaviour for the renamed form, export { styles as sharedStyles };.
Test case
No response
Additional comments
No response
Describe the issue
@stylexjs/no-unusedtreats astylex.create()object as entirely unused when it isexported with the specifier form (
export { styles };), even though another module mayconsume any of its keys.
The rule already exempts the other export forms —
export const styles = stylex.create({...}),export default styles— so the specifier form looks like an oversight rather than intent.Because the rule is
fixable: 'code', running ESLint with--fixdeletes the style keysfrom the source file. So this is not just noise: it silently removes working styles.
Expected behavior
No report. An exported styles object may have its keys used by another module, so the rule
cannot know whether they are unused — which is exactly why the other export forms are
already exempt.
Behaviour by export form
export const styles = stylex.create({...})export default stylesconst styles = stylex.create({...}); export { styles };const styles = stylex.create({...}); export { styles as s };Steps to reproduce
With
'@stylexjs/no-unused': 'error':eslint --fixstrips both keys, rewriting the file to:Same behaviour for the renamed form,
export { styles as sharedStyles };.Test case
No response
Additional comments
No response