diff --git a/crates/oxc_linter/src/rules/oxc/missing_throw.rs b/crates/oxc_linter/src/rules/oxc/missing_throw.rs index 27fe633f8..52bb3a609 100644 --- a/crates/oxc_linter/src/rules/oxc/missing_throw.rs +++ b/crates/oxc_linter/src/rules/oxc/missing_throw.rs @@ -26,7 +26,7 @@ declare_oxc_lint!( /// ``` MissingThrow, correctness, - pending // TODO: add a suggestion that adds `throw` + suggestion ); impl Rule for MissingThrow { @@ -35,7 +35,9 @@ impl Rule for MissingThrow { return; }; if new_expr.callee.is_specific_id("Error") && Self::has_missing_throw(node, ctx) { - ctx.diagnostic(missing_throw_diagnostic(new_expr.span)); + ctx.diagnostic_with_suggestion(missing_throw_diagnostic(new_expr.span), |fixer| { + fixer.insert_text_before(node, "throw ") + }); } } } @@ -80,5 +82,10 @@ fn test() { let fail = vec![("function foo() { new Error() }", None), ("const foo = () => { new Error() }", None)]; - Tester::new(MissingThrow::NAME, pass, fail).test_and_snapshot(); + let fix = vec![ + ("function foo() { new Error() }", "function foo() { throw new Error() }"), + ("const foo = () => { new Error() }", "const foo = () => { throw new Error() }"), + ]; + + Tester::new(MissingThrow::NAME, pass, fail).expect_fix(fix).test_and_snapshot(); }