facebook / facebook/stylex

[eslint-plugin] no-unused reports every style as unused when the styles object is exported via an export specifier

Open
#1,786 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
10.3k
Forks
481
Avg merge
3d 8h
Merged PRs (30d)
13

Description

### 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

```js
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:

```js
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.