Skip to content

Commit

Permalink
feat(linter/eslint): implement func-names
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Aug 4, 2024
1 parent 711d992 commit 3cbdf8e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/oxc_linter/src/rules/eslint/func_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ impl Rule for FuncNames {
// when yes remove it from invalid_funcs because recursion are always named
AstKind::CallExpression(expression) => {
if let Expression::Identifier(identifier) = &expression.callee {
// check at first if the callee calls an invalid function
if invalid_funcs
.iter()
.find(|(func, _)| get_function_name(func) == Some(&identifier.name))
.is_none()
{
continue;
}

// a function which is calling itself inside is always valid
let ast_span = ctx.nodes().iter_parents(node.id()).skip(1).find_map(|p| {
match p.kind() {
AstKind::Function(func) => {
Expand All @@ -421,6 +431,7 @@ impl Rule for FuncNames {
}
});

// we found a recursive function, remove it from the invalid list
if let Some(span) = ast_span {
invalid_funcs.retain(|(func, _)| func.span != span);
}
Expand Down

0 comments on commit 3cbdf8e

Please sign in to comment.