mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(linter) add suggestion fix for oxc missing throw (#4806)
This commit is contained in:
parent
d2734f3bc4
commit
d7fce589f8
1 changed files with 10 additions and 3 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue