Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(linter): avoid unnecessary temp Vecs (#4963)
Use iterator instead of collecting into temporary `Vec` which is then iterated over.
  • Loading branch information
overlookmotel committed Aug 19, 2024
commit 06f2d818fe7bca4c5d0915b17f6b26a463953068
10 changes: 5 additions & 5 deletions crates/oxc_linter/src/utils/jest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ pub fn collect_possible_jest_call_node<'a, 'b>(
{
reference_id_with_original_list.extend(
collect_ids_referenced_to_global(ctx)
.iter()
// set the original of global test function to None
.map(|&id| (id, None)),
.map(|id| (id, None)),
);
}

Expand Down Expand Up @@ -239,13 +238,14 @@ fn find_original_name<'a>(import_decl: &'a ImportDeclaration<'a>, name: &str) ->
})
}

fn collect_ids_referenced_to_global(ctx: &LintContext) -> Vec<ReferenceId> {
fn collect_ids_referenced_to_global<'c>(
ctx: &'c LintContext,
) -> impl Iterator<Item = ReferenceId> + 'c {
ctx.scopes()
.root_unresolved_references()
.iter()
.filter(|(name, _)| JEST_METHOD_NAMES.contains(name.as_str()))
.flat_map(|(_, reference_ids)| reference_ids.clone())
.collect()
.flat_map(|(_, reference_ids)| reference_ids.iter().copied())
}

/// join name of the expression. e.g.
Expand Down