ArnaudBarre / eslint-plugin-react-refresh

Validate that your components can safely be updated with Fast Refresh
MIT License
216 stars 14 forks source link

Consider not warning on `export *` when re-exported file is passing #24

Closed silverwind closed 1 year ago

silverwind commented 1 year ago

I think a common pattern in a library is to re-export everything in a index.jsx for convenience, for example:

export * from "./Buttons.jsx";

Currently, this plugin will error on every such line even thought the re-exported files themselves pass. Is this really an issue with the HMR or a linter bug?

ArnaudBarre commented 1 year ago

For me the issue is using .jsx for a file that is just re-exporting stuff

silverwind commented 1 year ago

Good idea, but I do currently run with checkJS so changing the extension would not change the result. I do think I should turn off checkJS because I already enforce .jsx extension via this rule.

silverwind commented 1 year ago

Ah I see the problem in my config. react/jsx-filename-extension is set to always but should be set to as-needed, in which case is will error when a .jsx file contains no jsx, after which I can turn off checkJS an both rules will be happy.

I still wonder, why is export * so problematic for this plugin. Isn't this export pretty much a noop pass-through forward to the imported file?

ArnaudBarre commented 1 year ago

Yeah but during dev, updates to a file with a React components and this export * will blocks updates from the re-exported module. If the re-exported module didn't change or also export React component this is fine, but you cannot now when running the eslint rule.

silverwind commented 1 year ago

Within the library, I don't use those * but only direct imports, so I guess I am fine in regards to HMR there.

When using the lib in an application and maybe symlinking the lib into the application's node_modules, I guess I will still be affected, so I'll evaluate whether it's worth the convenience to not have working HMR while symlinked. As far as I can tell, symlinked library with vite is hit and miss, sometimes it works, sometimes it doesn't.

Thanks for your time.