Skip to content
Open
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
48 changes: 34 additions & 14 deletions src/rules/prefer_primordials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,24 @@ impl Handler for PreferPrimordialsHandler {
fn bin_expr(&mut self, bin_expr: &ast_view::BinExpr, ctx: &mut Context) {
use ast_view::BinaryOp;

if matches!(bin_expr.op(), BinaryOp::InstanceOf) {
ctx.add_diagnostic_with_hint(
bin_expr.range(),
CODE,
PreferPrimordialsMessage::InstanceOf,
PreferPrimordialsHint::InstanceOf,
);
} else if matches!(bin_expr.op(), BinaryOp::In) {
ctx.add_diagnostic_with_hint(
bin_expr.range(),
CODE,
PreferPrimordialsMessage::In,
PreferPrimordialsHint::In,
);
match bin_expr.op() {
BinaryOp::InstanceOf => {
ctx.add_diagnostic_with_hint(
bin_expr.range(),
CODE,
PreferPrimordialsMessage::InstanceOf,
PreferPrimordialsHint::InstanceOf,
);
}
BinaryOp::In if !bin_expr.left.is::<ast_view::PrivateName>() => {
ctx.add_diagnostic_with_hint(
bin_expr.range(),
CODE,
PreferPrimordialsMessage::In,
PreferPrimordialsHint::In,
);
}
_ => {}
}
}
}
Expand Down Expand Up @@ -908,6 +912,15 @@ function foo(): Array<any> {}
r#"
type p = Promise<void>;
"#,
r#"
class A {
#brand;

static is(obj) {
return #brand in obj;
}
}
"#,
};
}

Expand Down Expand Up @@ -1289,6 +1302,13 @@ new DataView(new ArrayBuffer(10)).byteOffset;
hint: PreferPrimordialsHint::In,
},
],
r#"a in A"#: [
{
col: 0,
message: PreferPrimordialsMessage::In,
hint: PreferPrimordialsHint::In,
},
],
r#"a instanceof A"#: [
{
col: 0,
Expand Down