Skip to content

Commit

Permalink
feat(linter): implement useExplicitFunctionReturnType (biomejs#3990)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaykdm authored Sep 20, 2024
1 parent 83626d9 commit b76cb41
Show file tree
Hide file tree
Showing 14 changed files with 647 additions and 13 deletions.
10 changes: 10 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -151,5 +170,5 @@ fix.js format ━━━━━━━━━━━━━━━━━━━━━━
```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 error.
Found 4 warnings.
Found 5 warnings.
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ expression: content

# 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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -119,5 +138,5 @@ fix.js:4:12 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━

```block
Checked 1 file in <TIME>. No fixes applied.
Found 4 warnings.
Found 5 warnings.
```
42 changes: 31 additions & 11 deletions crates/biome_configuration/src/analyzer/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3368,6 +3368,10 @@ pub struct Nursery {
#[serde(skip_serializing_if = "Option::is_none")]
pub use_deprecated_reason:
Option<RuleConfiguration<biome_graphql_analyze::options::UseDeprecatedReason>>,
#[doc = "Require explicit return types on functions and class methods."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_explicit_function_return_type:
Option<RuleConfiguration<biome_js_analyze::options::UseExplicitFunctionReturnType>>,
#[doc = "Disallows package private imports."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_import_restrictions:
Expand Down Expand Up @@ -3431,6 +3435,7 @@ impl Nursery {
"useConsistentCurlyBraces",
"useConsistentMemberAccessibility",
"useDeprecatedReason",
"useExplicitFunctionReturnType",
"useImportRestrictions",
"useSortedClasses",
"useStrictMode",
Expand Down Expand Up @@ -3461,7 +3466,7 @@ impl Nursery {
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[21]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]),
];
const ALL_RULES_AS_FILTERS: &'static [RuleFilter<'static>] = &[
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0]),
Expand Down Expand Up @@ -3495,6 +3500,7 @@ impl Nursery {
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[30]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31]),
];
#[doc = r" Retrieves the recommended rules"]
pub(crate) fn is_recommended_true(&self) -> bool {
Expand Down Expand Up @@ -3641,31 +3647,36 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25]));
}
}
if let Some(rule) = self.use_import_restrictions.as_ref() {
if let Some(rule) = self.use_explicit_function_return_type.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26]));
}
}
if let Some(rule) = self.use_sorted_classes.as_ref() {
if let Some(rule) = self.use_import_restrictions.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27]));
}
}
if let Some(rule) = self.use_strict_mode.as_ref() {
if let Some(rule) = self.use_sorted_classes.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]));
}
}
if let Some(rule) = self.use_trim_start_end.as_ref() {
if let Some(rule) = self.use_strict_mode.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if let Some(rule) = self.use_trim_start_end.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[30]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31]));
}
}
index_set
}
pub(crate) fn get_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
Expand Down Expand Up @@ -3800,31 +3811,36 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25]));
}
}
if let Some(rule) = self.use_import_restrictions.as_ref() {
if let Some(rule) = self.use_explicit_function_return_type.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26]));
}
}
if let Some(rule) = self.use_sorted_classes.as_ref() {
if let Some(rule) = self.use_import_restrictions.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27]));
}
}
if let Some(rule) = self.use_strict_mode.as_ref() {
if let Some(rule) = self.use_sorted_classes.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]));
}
}
if let Some(rule) = self.use_trim_start_end.as_ref() {
if let Some(rule) = self.use_strict_mode.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if let Some(rule) = self.use_trim_start_end.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[30]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31]));
}
}
index_set
}
#[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"]
Expand Down Expand Up @@ -3965,6 +3981,10 @@ impl Nursery {
.use_deprecated_reason
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useExplicitFunctionReturnType" => self
.use_explicit_function_return_type
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useImportRestrictions" => self
.use_import_restrictions
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ define_categories! {
"lint/nursery/useConsistentCurlyBraces": "https://biomejs.dev/linter/rules/use-consistent-curly-braces",
"lint/nursery/useConsistentMemberAccessibility": "https://biomejs.dev/linter/rules/use-consistent-member-accessibility",
"lint/nursery/useDeprecatedReason": "https://biomejs.dev/linter/rules/use-deprecated-reason",
"lint/nursery/useExplicitFunctionReturnType": "https://biomejs.dev/linter/rules/use-explicit-function-return-type",
"lint/nursery/useImportRestrictions": "https://biomejs.dev/linter/rules/use-import-restrictions",
"lint/nursery/useJsxCurlyBraceConvention": "https://biomejs.dev/linter/rules/use-jsx-curly-brace-convention",
"lint/nursery/useSortedClasses": "https://biomejs.dev/linter/rules/use-sorted-classes",
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod use_aria_props_supported_by_role;
pub mod use_component_export_only_modules;
pub mod use_consistent_curly_braces;
pub mod use_consistent_member_accessibility;
pub mod use_explicit_function_return_type;
pub mod use_import_restrictions;
pub mod use_sorted_classes;
pub mod use_strict_mode;
Expand Down Expand Up @@ -50,6 +51,7 @@ declare_lint_group! {
self :: use_component_export_only_modules :: UseComponentExportOnlyModules ,
self :: use_consistent_curly_braces :: UseConsistentCurlyBraces ,
self :: use_consistent_member_accessibility :: UseConsistentMemberAccessibility ,
self :: use_explicit_function_return_type :: UseExplicitFunctionReturnType ,
self :: use_import_restrictions :: UseImportRestrictions ,
self :: use_sorted_classes :: UseSortedClasses ,
self :: use_strict_mode :: UseStrictMode ,
Expand Down
Loading

0 comments on commit b76cb41

Please sign in to comment.