refactor(linter): avoid unnecessary temp Vecs (#4963)

Use iterator instead of collecting into temporary `Vec` which is then iterated over.
This commit is contained in:
overlookmotel 2024-08-19 01:32:05 +00:00
parent d677b8e0ab
commit 06f2d818fe

View file

@ -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)),
);
}
@ -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.