Skip to content

Commit

Permalink
fix(prefer-primordials): allow private identifier in in expression
Browse files Browse the repository at this point in the history
  • Loading branch information
0f-0b committed Dec 6, 2024
1 parent b722829 commit fd6f455
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/rules/prefer_primordials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,20 +713,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 @@ -913,6 +917,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 @@ -1294,6 +1307,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

0 comments on commit fd6f455

Please sign in to comment.