Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 4 additions & 15 deletions crates/oxc_linter/src/rules/eslint/no_inner_declarations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_span::Span;

use crate::{AstNode, context::LintContext, rule::Rule};

Expand Down Expand Up @@ -90,17 +90,6 @@ impl Rule for NoInnerDeclarations {
| AstKind::StaticBlock(_)
| AstKind::ExportNamedDeclaration(_)
| AstKind::ExportDefaultDeclaration(_) => return,
AstKind::ForStatement(for_stmt) => {
if for_stmt.init.as_ref().is_some_and(|init| init.span() == kind.span()) {
return;
}
}
AstKind::ForInStatement(for_stmt) if for_stmt.left.span() == kind.span() => {
return;
}
AstKind::ForOfStatement(for_stmt) if for_stmt.left.span() == kind.span() => {
return;
}
_ => {}
}

Expand Down Expand Up @@ -167,9 +156,6 @@ fn test() {
("class C { method() { var x; } }", Some(serde_json::json!(["both"]))),
("class C { static { function foo() {} } }", Some(serde_json::json!(["both"]))),
("class C { static { var x; } }", Some(serde_json::json!(["both"]))),
("for (var x in {}) {}", Some(serde_json::json!(["both"]))),
("for (var x of []) {}", Some(serde_json::json!(["both"]))),
("for (var x = 1; a < 10; a++) {}", Some(serde_json::json!(["both"]))),
("for (const x in {}) { let y = 5; }", Some(serde_json::json!(["both"]))),
("for (const x of []) { let y = 5; }", Some(serde_json::json!(["both"]))),
("for (const x = 1; a < 10; a++) { let y = 5; }", Some(serde_json::json!(["both"]))),
Expand Down Expand Up @@ -214,6 +200,9 @@ fn test() {
("for (const x in {}) var y = 5;", Some(serde_json::json!(["both"]))),
("for (const x of []) var y = 5;", Some(serde_json::json!(["both"]))),
("for (const x = 1; a < 10; a++) var y = 5;", Some(serde_json::json!(["both"]))),
("for (var x in {}) {}", Some(serde_json::json!(["both"]))),
("for (var x of []) {}", Some(serde_json::json!(["both"]))),
("for (var x = 1; a < 10; a++) {}", Some(serde_json::json!(["both"]))),
];

Tester::new(NoInnerDeclarations::NAME, NoInnerDeclarations::PLUGIN, pass, fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,24 @@ source: crates/oxc_linter/src/tester.rs
· ───
╰────
help: Move variable declaration to program root

⚠ eslint(no-inner-declarations): Variable or `function` declarations are not allowed in nested blocks
╭─[no_inner_declarations.tsx:1:6]
1 │ for (var x in {}) {}
· ───
╰────
help: Move variable declaration to program root

⚠ eslint(no-inner-declarations): Variable or `function` declarations are not allowed in nested blocks
╭─[no_inner_declarations.tsx:1:6]
1 │ for (var x of []) {}
· ───
╰────
help: Move variable declaration to program root

⚠ eslint(no-inner-declarations): Variable or `function` declarations are not allowed in nested blocks
╭─[no_inner_declarations.tsx:1:6]
1 │ for (var x = 1; a < 10; a++) {}
· ───
╰────
help: Move variable declaration to program root
Loading