From b76cb416dac0de8712c0236aa2832a824df5b1d5 Mon Sep 17 00:00:00 2001 From: kaykdm <34934746+kaykdm@users.noreply.github.com> Date: Sat, 21 Sep 2024 05:37:29 +0900 Subject: [PATCH] feat(linter): implement useExplicitFunctionReturnType (#3990) --- .../migrate/eslint_any_rule_to_biome.rs | 10 + .../top_level_all_down_level_not_all.snap | 21 +- ..._level_all_true_group_level_all_false.snap | 21 +- .../src/analyzer/linter/rules.rs | 42 ++- .../src/categories.rs | 1 + crates/biome_js_analyze/src/lint/nursery.rs | 2 + .../use_explicit_function_return_type.rs | 178 ++++++++++++ crates/biome_js_analyze/src/options.rs | 1 + .../useExplicitFunctionReturnType/invalid.ts | 40 +++ .../invalid.ts.snap | 256 ++++++++++++++++++ .../useExplicitFunctionReturnType/valid.ts | 34 +++ .../valid.ts.snap | 42 +++ .../@biomejs/backend-jsonrpc/src/workspace.ts | 5 + .../@biomejs/biome/configuration_schema.json | 7 + 14 files changed, 647 insertions(+), 13 deletions(-) create mode 100644 crates/biome_js_analyze/src/lint/nursery/use_explicit_function_return_type.rs create mode 100644 crates/biome_js_analyze/tests/specs/nursery/useExplicitFunctionReturnType/invalid.ts create mode 100644 crates/biome_js_analyze/tests/specs/nursery/useExplicitFunctionReturnType/invalid.ts.snap create mode 100644 crates/biome_js_analyze/tests/specs/nursery/useExplicitFunctionReturnType/valid.ts create mode 100644 crates/biome_js_analyze/tests/specs/nursery/useExplicitFunctionReturnType/valid.ts.snap diff --git a/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs b/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs index c6b73733a964..9a39b95c073b 100644 --- a/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs +++ b/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs @@ -73,6 +73,16 @@ pub(crate) fn migrate_eslint_any_rule( let rule = group.use_literal_keys.get_or_insert(Default::default()); rule.set_level(rule_severity.into()); } + "@typescript-eslint/explicit-function-return-type" => { + if !options.include_nursery { + return false; + } + let group = rules.nursery.get_or_insert_with(Default::default); + let rule = group + .use_explicit_function_return_type + .get_or_insert(Default::default()); + rule.set_level(rule_severity.into()); + } "@typescript-eslint/explicit-member-accessibility" => { if !options.include_nursery { return false; diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/top_level_all_down_level_not_all.snap b/crates/biome_cli/tests/snapshots/main_commands_check/top_level_all_down_level_not_all.snap index 8319f49f84cf..eb7ace276198 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_check/top_level_all_down_level_not_all.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_check/top_level_all_down_level_not_all.snap @@ -40,6 +40,25 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━ # Emitted Messages +```block +fix.js:1:1 lint/nursery/useExplicitFunctionReturnType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Missing return type on function. + + > 1 │ + │ + > 2 │ function f() {arguments;} + │ ^^^^^^^^^^ + 3 │ const FOO = "FOO"; + 4 │ var x, y; + + i Declaring the return type makes the code self-documenting and can speed up TypeScript type checking. + + i Add a return type annotation. + + +``` + ```block fix.js:2:14 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -151,5 +170,5 @@ fix.js format ━━━━━━━━━━━━━━━━━━━━━━ ```block Checked 1 file in