-
-
Notifications
You must be signed in to change notification settings - Fork 474
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
💅 Possibly a false positive in handling useArrowFunction #4464
Comments
Actually I am not sure if we can consider this as a false positive. Here is the rule docs:
Why should we treat this case as a false positive ? |
I believe this is not a function expression but a function |
There are two kinds of default exports:
Because you use a cast, you fell in the second one. You can check this in the TypeScript Playground: export default <Plugin> function() {} is converted to: export default (function () {}); |
Looks like technically you are right. In practice, let's think whether this rule makes sense in this particular case. It's a top-level, exported function, I don't really see the benefit in converting it to an arrow function. For the reference here is the rule description: https://biomejs.dev/linter/rules/use-arrow-function/ Maybe this should be a special case that doesn't fall within this rule. I'm not sure what would that technically be. |
I think we should stay on the technical side for this one. Treating a function expression as it was a function declaration is technically wrong, and if people mistake this case, I am sure they will learn something new. You can check the CST of the playground you shared, or even the TypeScript one. There are other ways to export a default function using an arrow function, users should be encouraged to use those ones. |
Moreover, this cast syntax is considered as obsolete by the TypeScript team. Using the new cast syntax makes it clear that the function is a function expression. |
Environment information
Rule name
useArrowFunction
Playground link
https://biomejs.dev/playground/?lintRules=all&code=aQBtAHAAbwByAHQAIAB0AHkAcABlACAAewAgAFAAbAB1AGcAaQBuACAAfQAgAGYAcgBvAG0AIAAnAEAAbgB1AHgAdAAvAHQAeQBwAGUAcwAnADsACgAKAGUAeABwAG8AcgB0ACAAZABlAGYAYQB1AGwAdAAgADwAUABsAHUAZwBpAG4APgAgAGYAdQBuAGMAdABpAG8AbgAoACkAIAB7AAoAfQA7AAoA&jsx=false
Expected result
When exported function uses typescript type assertion (I think that's what it's called but not sure, maybe it's just a type cast) then Biome seems to think that it's function expression and suggests converting it to an arrow function. I think it's a false positive.
Code of Conduct
The text was updated successfully, but these errors were encountered: