-
-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 noUnusedImports removes React import unsafely #571
Comments
In many cases, this is due to a lack of bundler or transpiler settings. If you use vitest with React, you need to use If you use jest, you need to set some options for transpiler Babel: https://babeljs.io/docs/babel-preset-react#both-runtimes So, as you say, removing react is not safe and has side effects, |
I am unsure about the course of action here. I think we will wait to gather more feedbacks. |
Ah! That's a great point. That works for me. I think I'll close this issue now as my specific problem is resolved with that solution. |
@Conaclos we hit this today too. It is safer for us not to be forced to remove the imports. Can there be an option setting for the rule to ignore this import? |
I am going to enable jsx=automatic in esbuild and work around this. We dont have any other imports to ignore AFAIK at this time. |
We have a non-editable company-wide webpack and TS configs, and we can't remove React import. |
Environment information
What happened?
The
nursery.noUnusedImports
rule currently removes theimport React from 'react'
import in React projects (.tsx/.jsx files) when it's not directly used. This is not a safe thing to do. Although some postprocessors (like Next.js) handle this fine, others likejest
andvitest
will fail with:This is because JSX syntax is transpiled to
React.createClass
under-the-hood.Expected result
Ideally Biome would leave
import React from 'react'
imports alone if there is JSX syntax in the file. If that's not possible, maybe it's better to add an exception to thereact
module for now?Code of Conduct
The text was updated successfully, but these errors were encountered: