biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
15.32k stars 475 forks source link

📎 Implement `nursery/useExplicitTypes` - `typescript-eslint/explicit-module-boundary-types` and `typescript-eslint/explicit-function-return-type` #2017

Open Conaclos opened 8 months ago

Conaclos commented 8 months ago

Description

The rule will cover:

This rule must not conflict with noInferrableTypes.

Some context here.

barthuygen commented 5 months ago

This is exactly the what I'm missing, is there any prospect on when this might be implemented?

ematipico commented 5 months ago

@barthuygen

We refrain from giving dates, deadlines and such because we aren't a company and we develop things using the small resources we have.

If you're willing to see this shipped "faster" than the others, you can always help us financially: https://github.com/biomejs/biome/blob/main/GOVERNANCE.md#financial-contributions

Or willing to implement the feature yourself.

dreamorosi commented 4 months ago

Hi @ematipico - about the sponsorship:

I can't commit to it yet, but having a discrete amount and timeline would definitely help me make a case.

ematipico commented 4 months ago

@dreamorosi I believe we document everything inside our governance document. I suggest to reach out to us in #funding

dreamorosi commented 4 months ago

Hi @ematipico thanks for the reply - None of the links to Discord in the Governance document worked for me, maybe the invite link has expired. I was able to join through another link in the Contributing doc.

RayanMoarkech commented 4 months ago

+1 for explicit-function-return-type

firxworx commented 4 months ago

No kidding the explicit-function-return-type rule is the singlemost important blocker from me not ditching eslint entirely for biomejs... that plus better monorepo support but I know that's in the works. I tried biome and it is amazingly fast and nice.

Importance

TypeScript runs better and faster with explicit return types especially in large codebases, and its been known to make unexpected random performance issues disappear.

Stylistically I love it, it brings the rigour of strong-typed languages like java and makes code much easier to review and test when every function signature is a declaration of the "data in + data out" and an explicit statement of the developer's intent.

I've even watched it prevent bugs in React components during pair sessions (where this rule is sometimes accused of being annoying) e.g. if a component may conditionally return null that has to be part of the return type in addition to JSX.Element.

Suggestions

I understand the first priority is getting this rule in.

IMHO to take it to another level would be to have some more customization capabilities for it beyond what eslint provides and perhaps a "lever or knob" to control it for trivial arrow functions.

Perhaps dreaming now: a level of React awareness would be fantastic e.g. as I don't think cleanup callbacks and the like (always void) need to be declared. While I appreciate it, others would love to turn it off for React component files e.g. tsx but keep it for ts.

Perhaps to pull some of the dream requirements off as a general feature there could be a way to configure with custom patterns/regexes.

kaykdm commented 1 month ago

I have implemented the base cases of typescript-eslint/explicit-function-return-type rule. Here are the remaining TODOs, as discussed in the PR:

nazarhussain commented 2 weeks ago

I implemented allowArrowFunctions which behaves different than allowExpressions. The later restrict the rule only for expressions, but allowArrowFunctions is wider and more general for arrow functions.

Would suggest to include it as an additional feature than eslint-rule parity. https://github.com/biomejs/biome/pull/4233 What would you think?

Conaclos commented 2 weeks ago

@nazarhussain Could you give some examples that are not covered by allowExpressions and are covered by allowArrowFunctions? Is allowArrowFunctions compatible with TypeScript's isolated declarations?

nazarhussain commented 2 weeks ago

When an object is composed with functions, the expression definition does not apply. Check this snippet.

You will notice that allowExpressions does work when a function is passed as argument, but not when a function is used as object attributes.

Conaclos commented 2 weeks ago

@nazarhussain Thanks for the details. I think it is worth adding these cases to the rule. However, this doesn't require an option, this should be the default behavior.

nazarhussain commented 2 weeks ago

@Conaclos Thanks for feedback. I will update my PR accordingly and extend the rule without adding a new option.

nazarhussain commented 1 week ago

@Conaclos I updated the PR, please review when available https://github.com/biomejs/biome/pull/4233