Skip to content
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

Closed
1 task done
rchl opened this issue Nov 4, 2024 · 6 comments
Closed
1 task done

💅 Possibly a false positive in handling useArrowFunction #4464

rchl opened this issue Nov 4, 2024 · 6 comments
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Needs discussion Status: needs a discussion to understand criteria

Comments

@rchl
Copy link
Contributor

rchl commented Nov 4, 2024

Environment information

v1.9.4

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

  • I agree to follow Biome's Code of Conduct
@rchl rchl added the S-Needs triage Status: this issue needs to be triaged label Nov 4, 2024
@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug and removed S-Needs triage Status: this issue needs to be triaged S-Bug-confirmed Status: report has been confirmed as a valid bug labels Nov 4, 2024
@Conaclos
Copy link
Member

Conaclos commented Nov 4, 2024

Actually I am not sure if we can consider this as a false positive.

Here is the rule docs:

This rule proposes turning all function expressions that are not generators (function*) and don't use this into arrow functions.

Why should we treat this case as a false positive ?

@Conaclos Conaclos added the S-Needs discussion Status: needs a discussion to understand criteria label Nov 4, 2024
@rchl
Copy link
Contributor Author

rchl commented Nov 4, 2024

I believe this is not a function expression but a function declaration definition. And the linter error goes away when removing the type cast/assertion which I believe should have nothing to do with that rule.

@Conaclos
Copy link
Member

Conaclos commented Nov 4, 2024

I believe this is not a function expression but a function declaration. And the linter error goes away when removing the type cast/assertion which I believe should have nothing to do with that rule.

There are two kinds of default exports:

  1. Default Function declaration exports;
  2. Default expression 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 () {});

@rchl
Copy link
Contributor Author

rchl commented Nov 4, 2024

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.

@ematipico
Copy link
Member

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.

@Conaclos
Copy link
Member

Conaclos commented Nov 5, 2024

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.
I am closing the issue because I think we should keep things as they are here.

@Conaclos Conaclos closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Needs discussion Status: needs a discussion to understand criteria
Projects
None yet
Development

No branches or pull requests

3 participants