refactor(linter): get arrow expression by scope_id in no_render_return_value (#2424)

This commit is contained in:
Dunqing 2024-02-17 21:06:28 +08:00 committed by GitHub
parent 7c2d868dc7
commit 67d7a4677f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 17 deletions

View file

@ -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),
));
}
}
}

View file

@ -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)
}