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(linter): fix false positive in eslint/no-cond-assign #7241

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
20 changes: 7 additions & 13 deletions crates/oxc_linter/src/rules/eslint/no_cond_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ impl Rule for NoCondAssign {
if let Some(test) = &for_stmt.test {
spans.push(test.span());
}
if let Some(update) = &for_stmt.update {
spans.push(update.span());
}
if let Some(update) = &for_stmt.update {
spans.push(update.span());
}
}
AstKind::ConditionalExpression(cond_expr) => {
spans.push(cond_expr.span());
Expand All @@ -115,7 +109,7 @@ impl Rule for NoCondAssign {
}

// Only report the diagnostic if the assignment is in a span where it should not be.
// For example, report `if (a = b) { ...}`, not `if (...) { a = b }`
// For example, report `if (a = b) { ... }`, not `if (...) { a = b }`
if spans.iter().any(|span| span.contains_inclusive(node.span())) {
Self::emit_diagnostic(ctx, expr);
}
Expand Down Expand Up @@ -210,12 +204,7 @@ fn test() {
",
Some(serde_json::json!(["always"])),
),
(
"
while(true) newValue = value;
",
Some(serde_json::json!(["always"])),
),
("while(true) newValue = value;", Some(serde_json::json!(["always"]))),
(
"
for(;;) newValue = value;
Expand All @@ -225,6 +214,11 @@ fn test() {
("for (; (typeof l === 'undefined' ? (l = 0) : l); i++) { }", None),
("for (x = 0;x<10;x++) { x = 0 }", None),
("for (x = 0;x<10;(x = x + 1)) { x = 0 }", None),
("const nums = [1,2,3]; for(let i = 0; i < nums.length; i += 1) { dosomething(); }", None),
(
"for (let i = 0; i < nums.length; i += 1) { dosomething();}",
Some(serde_json::json!(["always"])),
),
];

let fail = vec![
Expand Down
Loading