-
-
Notifications
You must be signed in to change notification settings - Fork 442
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
feat(linter): implement useExplicitFunctionReturnType #3990
base: main
Are you sure you want to change the base?
Conversation
function test(): void { | ||
return; | ||
} | ||
|
||
var fn = function (): number { | ||
return 1; | ||
}; | ||
|
||
var arrowFn = (): string => 'test'; | ||
|
||
class Test { | ||
constructor() {} | ||
get prop(): number { | ||
return 1; | ||
} | ||
set prop() {} | ||
method(): void { | ||
return; | ||
} | ||
arrow = (): string => 'arrow'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function test(a: number, b: number) { | ||
return; | ||
} | ||
|
||
function test() { | ||
return; | ||
} | ||
|
||
var fn = function () { | ||
return 1; | ||
}; | ||
|
||
var arrowFn = () => "test"; | ||
|
||
class Test { | ||
constructor() {} | ||
get prop() { | ||
return 1; | ||
} | ||
set prop() {} | ||
method() { | ||
return; | ||
} | ||
arrow = () => "arrow"; | ||
private method() { | ||
return; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love to have this rule!
/// Leaving off the return type is less code to read or write and allows the compiler to infer it from the contents of the function. | ||
/// | ||
/// However, explicit return types do make it visually more clear what type is returned by a function. | ||
/// They can also speed up TypeScript type checking performance in large codebases with many large functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to add that explicit return types also reduce the chance of bugs by asserting the return type and it avoids surprising "action at a distance", where changing the body of one function may cause failures inside another function.
/// return; | ||
/// } | ||
/// } | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a function without any explicit return
statement? Is the type annotation required there too? If not, might be good to point out in the examples.
CodSpeed Performance ReportMerging #3990 will degrade performances by 6.15%Comparing Summary
Benchmarks breakdown
|
Summary
Related issue: #2017
This PR introduces the @typescript-eslint/explicit-function-return-type rule to Biome. Currently, it only enforces the basic cases without any additional options configured.
In future PRs, I will implement each option for this rule separately. Due to the complexity of the implementation, handling each option individually will allow for thorough testing and easier review.
original implementation
Todos
I will implement each option for this rule separately in different PRs