Skip to content

Commit

Permalink
feat(linter): implement unicorn/no-useless-undefined (#4079)
Browse files Browse the repository at this point in the history
Resolves #3870

Hey there, thought I'd give this a try as it's tagged "good first issue"
:) Let me know if there's anything that needs to change

Another part of the code also needs modification:

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/no-useless-undefined.js#L95

I tried to modify it. If there are any issues with these modifications,
please let me know.
```
fn is_has_function_return_type(node: &AstNode, ctx: &LintContext<'_>) -> bool {
    let Some(parent_node) = ctx.nodes().parent_node(node.id()) else {
        return false;
    };
    match parent_node.kind() {
        AstKind::ArrowFunctionExpression(arrow_func_express) => {
            arrow_func_express.return_type.is_some()
        }
        AstKind::Function(func) => func.return_type.is_some(),
        _ => is_has_function_return_type(parent_node, ctx),
    }
}
```
  • Loading branch information
cblh authored Jul 11, 2024
1 parent bc2631c commit bbe6137
Show file tree
Hide file tree
Showing 3 changed files with 811 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ mod unicorn {
pub mod no_useless_promise_resolve_reject;
pub mod no_useless_spread;
pub mod no_useless_switch_case;
pub mod no_useless_undefined;
pub mod no_zero_fractions;
pub mod number_literal_case;
pub mod numeric_separators_style;
Expand Down Expand Up @@ -650,6 +651,7 @@ oxc_macros::declare_all_lint_rules! {
unicorn::no_useless_promise_resolve_reject,
unicorn::no_useless_spread,
unicorn::no_useless_switch_case,
unicorn::no_useless_undefined,
unicorn::no_zero_fractions,
unicorn::number_literal_case,
unicorn::numeric_separators_style,
Expand Down
Loading

0 comments on commit bbe6137

Please sign in to comment.