Skip to content

Commit

Permalink
refactor(linter): get arrow expression by scope_id in no_render_retur…
Browse files Browse the repository at this point in the history
…n_value (oxc-project#2424)
  • Loading branch information
Dunqing authored and IWANABETHATGUY committed May 29, 2024
1 parent 454653f commit 55e547f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
26 changes: 9 additions & 17 deletions crates/oxc_linter/src/rules/react/no_render_return_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use oxc_diagnostics::{
thiserror::Error,
};
use oxc_macros::declare_oxc_lint;
use oxc_semantic::ScopeFlags;
use oxc_span::Span;

use crate::{context::LintContext, rule::Rule, AstNode};
Expand Down Expand Up @@ -58,22 +57,15 @@ impl Rule for NoRenderReturnValue {
));
}

let is_arrow_function = ctx
.scopes()
.get_flags(parent_node.scope_id())
.contains(ScopeFlags::Arrow);

if is_arrow_function {
for node_id in ctx.nodes().ancestors(parent_node.id()).skip(1) {
let node = ctx.nodes().get_node(node_id);
if let AstKind::ArrowExpression(e) = node.kind() {
if e.expression {
ctx.diagnostic(NoRenderReturnValueDiagnostic(
ident.span.merge(&property_span),
));
} else {
break;
}
let scope_id = parent_node.scope_id();
if ctx.scopes().get_flags(scope_id).is_arrow() {
if let AstKind::ArrowExpression(e) =
ctx.nodes().kind(ctx.scopes().get_node_id(scope_id))
{
if e.expression {
ctx.diagnostic(NoRenderReturnValueDiagnostic(
ident.span.merge(&property_span),
));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_syntax/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl ScopeFlags {
self.contains(Self::Function)
}

pub fn is_arrow(&self) -> bool {
self.contains(Self::Arrow)
}

pub fn is_constructor(&self) -> bool {
self.contains(Self::Constructor)
}
Expand Down

0 comments on commit 55e547f

Please sign in to comment.