Open elawad opened 2 days ago
Hi! You can explicitly set a global using the javascript.globals
configuration.
We did try globals, though that introduces other issues.
// biome.json
"javascript": {
"globals": ["React"]
}
For instance, in a non-TS .jsx file you can add this without an import.
// App.jsx
function App() {
const [count, setCount] = React.useState(0);
}
Biome will allow it due to globals, but the app will error during runtime.
One other option was just to disable noUndeclaredVariables
in Biome overrides
for *.tsx
files.
Have you suggestions to solve the issue? We could add metadata to globals (if it is a type, a writable flobal, ...).
Also, we have a jsxRuntime
configuration. i am unsure if we could leverage it in some way.
I think the jsxRuntime
should apply here indeed, but not sure if it does π
Iβm also used to just disabling this rule, since itβs kinda redundant if you also use tsc
.
I don't have any suggestions unfortunately. But disabling it seems to be ok, since TypeScript will handle undeclared issues on its own in .tsx files.
We do run biome check
and tsc --noEmit
in git hooks already. So that will find both types of issues.
This one of the reason noUndeclaredVariabels
is still not recommended. It reports too much false positive. We hope to improve it once we have proper type info.
Thanks @Conaclos, it does help in .js/.jsx files. As we're used to it coming from ESLint.
But using overrides
was the perfect solution here.
It seems that there are more false positives with types than variables. We could add an option to ignore undeclared types. We could allow the option by default and allow the rule by default in Biome 2.0.
Whar do you think?
That's a good idea. Since types are already checked by TypeScript tsc.
Environment information
Rule name
noUndeclaredVariables
Playground link
https://biomejs.dev/playground/?lintRules=all&code=ZgB1AG4AYwB0AGkAbwBuACAATQB5AEEAcABwACgAKQAgAHsACgAgACAAZgB1AG4AYwB0AGkAbwBuACAAaABhAG4AZABsAGUAcgAoAGUAOgAgAFIAZQBhAGMAdAAuAEYAbwByAG0ARQB2AGUAbgB0ACkAIAB7AAoAIAAgACAAIAByAGUAdAB1AHIAbgAgAGUACgAgACAAfQAKAAoAIAAgAHIAZQB0AHUAcgBuACAAKAAKACAAIAAgACAAPABmAG8AcgBtACAAbwBuAFMAdQBiAG0AaQB0AD0AewAoAGUAKQAgAD0APgAgAGgAYQBuAGQAbABlAHIAKABlACkAfQA%2BAAoAIAAgACAAIAA8AC8AZgBvAHIAbQA%2BAAoAIAAgACkACgB9AAoACgBlAHgAcABvAHIAdAAgAHsAIABNAHkAQQBwAHAAIAB9AA%3D%3D
Expected result
Hello, we're migrating a few React 18/TS/EsLint projects into Biome. With React 18 you could use global React Types as
React.JSX.Element
,React.FormEvent
, etc without an import statement.But when we enable
noUndeclaredVariables
in Biome to check for possible bugs, we're getting a false positive onThe React variable is undeclared
.A workaround is to explicitly add an
import type React from 'react'
on every file with React types. But we have hundreds of files that would need this. And it was working before migrating over.Is there a better solution for this issue?
Thanks, and we love Biome!
Code of Conduct