mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter) Fix catch error name with parenthesis (#1242)
This commit is contained in:
parent
f25b496eea
commit
e60c287b77
2 changed files with 57 additions and 48 deletions
|
|
@ -132,64 +132,66 @@ impl CatchErrorName {
|
|||
arg0: &Argument,
|
||||
ctx: &LintContext,
|
||||
) -> Option<CatchErrorNameDiagnostic> {
|
||||
if let Argument::Expression(expr) = arg0 {
|
||||
if let Expression::ArrowExpression(arrow_expr) = expr {
|
||||
if let Some(arg0) = arrow_expr.params.items.get(0) {
|
||||
if let BindingPatternKind::BindingIdentifier(v) = &arg0.pattern.kind {
|
||||
if self.is_name_allowed(&v.name) {
|
||||
return None;
|
||||
}
|
||||
let Argument::Expression(expr) = arg0 else { return None };
|
||||
|
||||
if v.name.starts_with('_') {
|
||||
if symbol_has_references(v.symbol_id.get(), ctx) {
|
||||
ctx.diagnostic(CatchErrorNameDiagnostic(
|
||||
v.name.clone(),
|
||||
self.name.clone(),
|
||||
v.span,
|
||||
));
|
||||
}
|
||||
let expr = expr.without_parenthesized();
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(CatchErrorNameDiagnostic(
|
||||
v.name.clone(),
|
||||
self.name.clone(),
|
||||
v.span,
|
||||
));
|
||||
if let Expression::ArrowExpression(arrow_expr) = expr {
|
||||
if let Some(arg0) = arrow_expr.params.items.get(0) {
|
||||
if let BindingPatternKind::BindingIdentifier(v) = &arg0.pattern.kind {
|
||||
if self.is_name_allowed(&v.name) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Expression::FunctionExpression(fn_expr) = expr {
|
||||
if let Some(arg0) = fn_expr.params.items.get(0) {
|
||||
if let BindingPatternKind::BindingIdentifier(binding_ident) = &arg0.pattern.kind
|
||||
{
|
||||
if self.is_name_allowed(&binding_ident.name) {
|
||||
return None;
|
||||
if v.name.starts_with('_') {
|
||||
if symbol_has_references(v.symbol_id.get(), ctx) {
|
||||
ctx.diagnostic(CatchErrorNameDiagnostic(
|
||||
v.name.clone(),
|
||||
self.name.clone(),
|
||||
v.span,
|
||||
));
|
||||
}
|
||||
|
||||
if binding_ident.name.starts_with('_') {
|
||||
if symbol_has_references(binding_ident.symbol_id.get(), ctx) {
|
||||
ctx.diagnostic(CatchErrorNameDiagnostic(
|
||||
binding_ident.name.clone(),
|
||||
self.name.clone(),
|
||||
binding_ident.span,
|
||||
));
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(CatchErrorNameDiagnostic(
|
||||
binding_ident.name.clone(),
|
||||
self.name.clone(),
|
||||
binding_ident.span,
|
||||
));
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(CatchErrorNameDiagnostic(
|
||||
v.name.clone(),
|
||||
self.name.clone(),
|
||||
v.span,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Expression::FunctionExpression(fn_expr) = expr {
|
||||
if let Some(arg0) = fn_expr.params.items.get(0) {
|
||||
if let BindingPatternKind::BindingIdentifier(binding_ident) = &arg0.pattern.kind {
|
||||
if self.is_name_allowed(&binding_ident.name) {
|
||||
return None;
|
||||
}
|
||||
|
||||
if binding_ident.name.starts_with('_') {
|
||||
if symbol_has_references(binding_ident.symbol_id.get(), ctx) {
|
||||
ctx.diagnostic(CatchErrorNameDiagnostic(
|
||||
binding_ident.name.clone(),
|
||||
self.name.clone(),
|
||||
binding_ident.span,
|
||||
));
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(CatchErrorNameDiagnostic(
|
||||
binding_ident.name.clone(),
|
||||
self.name.clone(),
|
||||
binding_ident.span,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
@ -263,6 +265,7 @@ fn test() {
|
|||
("promise.catch(notMatching => { })", Some(serde_json::json!([{"ignore": ["unicorn"]}]))),
|
||||
("promise.catch((foo) => { })", None),
|
||||
("promise.catch(function (foo) { })", None),
|
||||
("promise.catch((function (foo) { }))", None),
|
||||
("promise.then(function (foo) { }).catch((foo) => { })", None),
|
||||
("promise.then(undefined, function (foo) { })", None),
|
||||
("promise.then(undefined, (foo) => { })", None),
|
||||
|
|
|
|||
|
|
@ -68,6 +68,12 @@ expression: catch_error_name
|
|||
· ───
|
||||
╰────
|
||||
|
||||
× eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error"
|
||||
╭─[catch_error_name.tsx:1:1]
|
||||
1 │ promise.catch((function (foo) { }))
|
||||
· ───
|
||||
╰────
|
||||
|
||||
× eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error"
|
||||
╭─[catch_error_name.tsx:1:1]
|
||||
1 │ promise.then(function (foo) { }).catch((foo) => { })
|
||||
|
|
|
|||
Loading…
Reference in a new issue