[eslint-plugin] Fix no-unused false positive for styles exported via export specifier - #1787
Open
trofim-samusev wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
|
||
| // Exempt used styles: export const exportStyles = stylex.create({}); | ||
| ExportNamedDeclaration(node: ExportNamedDeclaration) { | ||
| // Exempt used styles: export { exportStyles }; |
Collaborator
There was a problem hiding this comment.
This is an edge case but should we make sure there are no false positives for
export type { styles }; or export { type styles }; by checking the exportKind on the declaration and specifiers?
Author
There was a problem hiding this comment.
Added support for those cases. Can you please check again when you'll have some time?
…export specifier
`no-unused` only inspected `node.declaration` in its `ExportNamedDeclaration`
visitor, so `export { styles };` (where the exported bindings live in
`node.specifiers`) never exempted the styles object and every key was reported
as unused. Because the rule is fixable, `--fix` then deleted the style keys
from the source.
Exempt specifier exports too, skipping re-exports (`export { styles } from './x'`),
which refer to another module's binding rather than a local variable.
trofim-samusev
force-pushed
the
fix/no-unused-export-specifier
branch
from
July 30, 2026 03:13
b608b0e to
ce12c1f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1786
What changed / motivation ?
@stylexjs/no-unusedreports every key of astylex.create()object as unused when theobject is exported using the specifier form:
The rule already exempts
export const styles = stylex.create({...})andexport default styles, on the basis that an exported styles object may have its keys usedby another module.
export { styles };andexport { styles as s };are the same situationbut were not covered.
The rule is
fixable: 'code', soeslint --fixacted on the false positive and deletedthe style keys from the source file, emptying the
create()call in the example above tostylex.create({\n});.Cause: the
ExportNamedDeclarationvisitor only looked atnode.declaration. Forexport { styles };that isnulland the exported bindings live innode.specifiers[],so the variable was never removed from
stylexPropertiesandProgram:exitreported all ofits keys.
The fix iterates
node.specifiersand exempts eachlocalname. Re-exports(
export { styles } from './other-styles') are skipped via thenode.source == nullguard,because they export another module's binding and must not exempt a same-named local
variable.
Linked PR/Issues
Fixes # (issue)
Additional Context
Tests added to
packages/@stylexjs/eslint-plugin/__tests__/stylex-no-unused-test.js:export { styles };export { styles as sharedStyles };export { theme, styles };(specifier list with an unrelated binding)export { styles as default };export { styles } from './other-styles';— still reports the locally unused key,covering the re-export guard
No documentation change: neither the plugin README nor the docs site describes the rule's
export handling.
Pre-flight checklist