Skip to content

Commit a2f3f7e

Browse files
feat(lint): rule useExplicitReturnType (#9429)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent e0e4aac commit a2f3f7e

35 files changed

Lines changed: 3503 additions & 31 deletions

File tree

.changeset/calm-impalas-stare.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Added the new nursery lint rule [`useExplicitReturnType`](https://biomejs.dev/linter/rules/use-explicit-return-type). It reports TypeScript functions and methods that omit an explicit return type.
6+
7+
```ts
8+
function toString(x: any) { // rule triggered, it doesn't declare a return type
9+
return x.toString()
10+
}
11+
```
12+

crates/biome_configuration/src/analyzer/linter/rules.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_diagnostics_categories/src/categories.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_js_analyze/src/lint/complexity/no_excessive_lines_per_function.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::services::semantic::Semantic;
22
use biome_analyze::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule};
33
use biome_console::markup;
4-
use biome_js_syntax::{
5-
AnyFunctionLike, AnyJsFunction, JsCallExpression, JsParenthesizedExpression,
6-
};
4+
use biome_js_syntax::AnyFunctionLike;
75
use biome_rowan::AstNode;
86
use biome_rule_options::no_excessive_lines_per_function::NoExcessiveLinesPerFunctionOptions;
97

@@ -142,7 +140,7 @@ impl Rule for NoExcessiveLinesPerFunction {
142140
let options = ctx.options();
143141

144142
if let AnyFunctionLike::AnyJsFunction(func) = binding
145-
&& is_iife(func)
143+
&& func.is_iife()
146144
&& options.skip_iifes()
147145
{
148146
return None;
@@ -203,12 +201,6 @@ impl Rule for NoExcessiveLinesPerFunction {
203201
}
204202
}
205203

206-
fn is_iife(func: &AnyJsFunction) -> bool {
207-
func.parent::<JsParenthesizedExpression>()
208-
.and_then(|expr| expr.parent::<JsCallExpression>())
209-
.is_some()
210-
}
211-
212204
pub struct State {
213205
function_lines_count: usize,
214206
}

0 commit comments

Comments
 (0)