From 62739949ae7d65586743d44385995d551e54fdd2 Mon Sep 17 00:00:00 2001 From: heygsc <1596920983@qq.com> Date: Wed, 7 Aug 2024 12:44:38 +0800 Subject: [PATCH] fix(linter): block in eslint/no_cond_assign (#4721) fix: #4687 --- crates/oxc_linter/src/rules/eslint/no_cond_assign.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs b/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs index 17c726fb3..8a649b3d6 100644 --- a/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs @@ -77,7 +77,8 @@ impl Rule for NoCondAssign { } AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) - | AstKind::Program(_) => break, + | AstKind::Program(_) + | AstKind::BlockStatement(_) => break, _ => {} } } @@ -159,6 +160,11 @@ fn test() { ("switch (foo) { case a = b: bar(); }", Some(serde_json::json!(["except-parens"]))), ("switch (foo) { case a = b: bar(); }", Some(serde_json::json!(["always"]))), ("switch (foo) { case baz + (a = b): bar(); }", Some(serde_json::json!(["always"]))), + // not in condition + ("if (obj.key) { (obj.key=false) }", Some(serde_json::json!(["always"]))), + ("for (;;) { (obj.key=false) }", Some(serde_json::json!(["always"]))), + ("while (obj.key) { (obj.key=false) }", Some(serde_json::json!(["always"]))), + ("do { (obj.key=false) } while (obj.key)", Some(serde_json::json!(["always"]))), ]; let fail = vec![