From c3ec7a8cac6e5529e44d9e6fc0b4236a44aa0ea3 Mon Sep 17 00:00:00 2001 From: Cameron Clark Date: Thu, 12 Oct 2023 08:17:20 +0100 Subject: [PATCH] reorder --- .../src/rules/unicorn/catch_error_name.rs | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs index 415554249ecb7..4eacd9b6a3910 100644 --- a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs +++ b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs @@ -44,80 +44,9 @@ declare_oxc_lint!( /// /// ``` CatchErrorName, - correctness + style ); -impl CatchErrorName { - fn is_name_allowed(&self, name: &Atom) -> bool { - self.name == name || self.ignore.contains(name) - } - fn check_function_arguments( - &self, - arg0: &Argument, - ctx: &LintContext, - ) -> Option { - 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; - } - - 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, - )); - } - - 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 - } -} - impl Rule for CatchErrorName { fn from_configuration(value: serde_json::Value) -> Self { let ignored_names = value @@ -194,6 +123,77 @@ impl Rule for CatchErrorName { } } +impl CatchErrorName { + fn is_name_allowed(&self, name: &Atom) -> bool { + self.name == name || self.ignore.contains(name) + } + fn check_function_arguments( + &self, + arg0: &Argument, + ctx: &LintContext, + ) -> Option { + 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; + } + + 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, + )); + } + + 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 + } +} + fn symbol_has_references(symbol_id: Option, ctx: &LintContext) -> bool { if let Some(symbol_id) = symbol_id { return ctx.semantic().symbol_references(symbol_id).next().is_some();