Skip to content

Commit

Permalink
reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Oct 12, 2023
1 parent b61d7cd commit c3ec7a8
Showing 1 changed file with 72 additions and 72 deletions.
144 changes: 72 additions & 72 deletions crates/oxc_linter/src/rules/unicorn/catch_error_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
}

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
Expand Down Expand Up @@ -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<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;
}

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<SymbolId>, ctx: &LintContext) -> bool {
if let Some(symbol_id) = symbol_id {
return ctx.semantic().symbol_references(symbol_id).next().is_some();
Expand Down

0 comments on commit c3ec7a8

Please sign in to comment.