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

feat(linter/unicorn): add fixer to throw-new-error #5148

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
13 changes: 10 additions & 3 deletions crates/oxc_linter/src/rules/unicorn/throw_new_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare_oxc_lint!(
/// ```
ThrowNewError,
style,
pending
fix
);

impl Rule for ThrowNewError {
Expand Down Expand Up @@ -85,7 +85,9 @@ impl Rule for ThrowNewError {
_ => return,
}

ctx.diagnostic(throw_new_error_diagnostic(call_expr.span));
ctx.diagnostic_with_fix(throw_new_error_diagnostic(call_expr.span), |fixer| {
fixer.insert_text_before_range(call_expr.span, "new ")
});
}
}

Expand Down Expand Up @@ -143,5 +145,10 @@ fn test() {
("throw (( getGlobalThis().Error ))()", None),
];

Tester::new(ThrowNewError::NAME, pass, fail).test_and_snapshot();
let fix = vec![
("throw Error()", "throw new Error()"),
("throw (( getGlobalThis().Error ))()", "throw new (( getGlobalThis().Error ))()"),
DonIsaac marked this conversation as resolved.
Show resolved Hide resolved
];

Tester::new(ThrowNewError::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}