Skip to content

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

Description

@trofim-samusev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions