biome icon indicating copy to clipboard operation
biome copied to clipboard

[Wip] fix(useComponentExportOnlyModules): Proper evaluation of the hook

Open GunseiKPaseri opened this issue 1 year ago • 2 comments

Summary

Close #4424

This rule is designed to determine whether an exported item is a component or not and to enforce exporting according to specific guidelines. Exceptionally, components wrapped with standard React hooks like memo or forwardRef are also recognized as components. However, until now, only variables specified as arguments were permitted, which led to an issue where declaring a function directly as an argument to memo resulted in it being misclassified as a non-component. This update aligns with the original rule by prioritizing variable names and ensuring that no hook-related errors occur outside of default exports.

Concerns:

The modification now allows functions specified as arguments to be treated as components. However, for strict evaluation, it may also be necessary to check whether the export is anonymous. This addition, however, would deviate from the rule's original purpose.

Options:

  • During the nursery phase, rename to useReactRefresh to align closely with its function, though concerns remain about rule bloat and potential instability.
  • Develop a separate rule specifically for anonymous exports in default exports, although it’s unclear how to handle this alongside the noDefaultExport rule.
  • Create a plugin. However, I am uncertain of GritQL’s potential, as replicating the conditional logic of the current rule in a query language seems challenging.

Test Plan

GunseiKPaseri avatar Oct 29 '24 19:10 GunseiKPaseri

CodSpeed Performance Report

Merging #4429 will not alter performance

Comparing GunseiKPaseri:4424-allow-memo (bac6c02) with main (fe792ed)

Summary

✅ 92 untouched benchmarks

codspeed-hq[bot] avatar Oct 29 '24 20:10 codspeed-hq[bot]

@GunseiKPaseri are you still interested in this PR?

ematipico avatar Feb 07 '25 15:02 ematipico