Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prefer-primordials): Ignore TsTypeRef #1197

Merged
merged 1 commit into from
Sep 13, 2023
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
18 changes: 15 additions & 3 deletions src/rules/prefer_primordials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -336,11 +336,14 @@ impl Handler for PreferPrimordialsHandler {
if let Some(kv) = node.to::<ast_view::KeyValueProp>() {
return kv.key.range().contains(&orig.range());
}
if let Some(type_ref) = node.to::<ast_view::TsTypeRef>() {
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)
}
}
}
Expand All @@ -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(),
) {
Expand Down Expand Up @@ -767,6 +770,15 @@ let a, b, c;
const { indirectEval } = primordials;
indirectEval("console.log('This test should pass.');");
"#,
r#"
function foo(a: Array<any>) {}
"#,
r#"
function foo(): Array<any> {}
"#,
r#"
type p = Promise<void>;
"#,
};
}

Expand Down