Skip to content

Commit 2c1dab6

Browse files
committed
fix(linter/no-unassigned-vars): false positive with variables in for loop (#12833)
1 parent 44ac5a1 commit 2c1dab6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/oxc_linter/src/rules/eslint/no_unassigned_vars.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,20 @@ impl Rule for NoUnassignedVars {
6060
if declarator.init.is_some() || declarator.kind.is_const() {
6161
return;
6262
}
63-
let AstKind::VariableDeclaration(parent) = ctx.nodes().parent_kind(node.id()) else {
63+
let parent_node = ctx.nodes().parent_node(node.id());
64+
let AstKind::VariableDeclaration(parent) = parent_node.kind() else {
6465
return;
6566
};
6667
if parent.declare {
6768
return;
6869
}
70+
let grand_parent = ctx.nodes().parent_node(parent_node.id());
71+
if matches!(
72+
grand_parent.kind(),
73+
AstKind::ForStatement(_) | AstKind::ForInStatement(_) | AstKind::ForOfStatement(_)
74+
) {
75+
return;
76+
}
6977
if ctx
7078
.nodes()
7179
.ancestors(node.id())
@@ -123,6 +131,7 @@ fn test() {
123131
export = x;
124132
}
125133
",
134+
"for (let p of pathToRemove) { p.remove() }",
126135
];
127136

128137
let fail = vec![

0 commit comments

Comments
 (0)