From f87e327ce8f5cc4f0ee5ebed48eacd69b3a98a23 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Sat, 9 Sep 2023 22:23:23 +0900 Subject: [PATCH] Fix(prefer-primordials): Ignore `TsTypeRef` --- src/rules/prefer_primordials.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/rules/prefer_primordials.rs b/src/rules/prefer_primordials.rs index 99905a607..fcfadc4d8 100644 --- a/src/rules/prefer_primordials.rs +++ b/src/rules/prefer_primordials.rs @@ -323,7 +323,7 @@ struct PreferPrimordialsHandler; impl Handler for PreferPrimordialsHandler { fn ident(&mut self, ident: &ast_view::Ident, ctx: &mut Context) { - fn inside_var_decl_lhs_or_member_expr_or_prop( + fn inside_var_decl_lhs_or_member_expr_or_prop_or_type_ref( orig: ast_view::Node, node: ast_view::Node, ) -> bool { @@ -336,11 +336,14 @@ impl Handler for PreferPrimordialsHandler { if let Some(kv) = node.to::() { return kv.key.range().contains(&orig.range()); } + if let Some(type_ref) = node.to::() { + return type_ref.type_name.range().contains(&orig.range()); + } match node.parent() { None => false, Some(parent) => { - inside_var_decl_lhs_or_member_expr_or_prop(orig, parent) + inside_var_decl_lhs_or_member_expr_or_prop_or_type_ref(orig, parent) } } } @@ -349,7 +352,7 @@ impl Handler for PreferPrimordialsHandler { scope.var(&ident.inner.to_id()).is_some() } - if inside_var_decl_lhs_or_member_expr_or_prop( + if inside_var_decl_lhs_or_member_expr_or_prop_or_type_ref( ident.as_node(), ident.as_node(), ) { @@ -767,6 +770,15 @@ let a, b, c; const { indirectEval } = primordials; indirectEval("console.log('This test should pass.');"); "#, + r#" +function foo(a: Array) {} + "#, + r#" +function foo(): Array {} + "#, + r#" +type p = Promise; + "#, }; }