mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
fix(linter) Fix prefer type error with parenthesis (#1240)
This commit is contained in:
parent
9f653881bb
commit
f25b496eea
2 changed files with 18 additions and 1 deletions
|
|
@ -49,7 +49,10 @@ impl Rule for PreferTypeError {
|
|||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
let AstKind::ThrowStatement(throw_stmt) = node.kind() else { return };
|
||||
|
||||
let Expression::NewExpression(new_expr) = &throw_stmt.argument else { return };
|
||||
let Expression::NewExpression(new_expr) = &throw_stmt.argument.without_parenthesized()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
if !new_expr.callee.is_specific_id("Error") {
|
||||
return;
|
||||
|
|
@ -445,6 +448,11 @@ fn test() {
|
|||
throw new Error();
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
if (_.isElement(foo)) {
|
||||
throw (new Error());
|
||||
}
|
||||
"#,
|
||||
];
|
||||
|
||||
Tester::new_without_config(PreferTypeError::NAME, pass, fail).test_and_snapshot();
|
||||
|
|
|
|||
|
|
@ -100,4 +100,13 @@ expression: prefer_type_error
|
|||
╰────
|
||||
help: Change to `throw new TypeError(...)`
|
||||
|
||||
⚠ eslint-plugin-unicorn(prefer-type-error): Prefer throwing a `TypeError` over a generic `Error` after a type checking if-statement
|
||||
╭─[prefer_type_error.tsx:2:1]
|
||||
2 │ if (_.isElement(foo)) {
|
||||
3 │ throw (new Error());
|
||||
· ─────
|
||||
4 │ }
|
||||
╰────
|
||||
help: Change to `throw new TypeError(...)`
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue