mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(linter): get arrow expression by scope_id in no_render_return_value (#2424)
This commit is contained in:
parent
7c2d868dc7
commit
67d7a4677f
2 changed files with 13 additions and 17 deletions
|
|
@ -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};
|
||||
|
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue