mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter/no_render_return_value): fix false positive when nested inside an arrow expression (#1109)
This commit is contained in:
parent
8b11592a1f
commit
4975440e1b
2 changed files with 19 additions and 8 deletions
|
|
@ -11,7 +11,7 @@ use crate::{context::LintContext, rule::Rule, AstNode};
|
|||
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
#[error("eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.")]
|
||||
#[diagnostic(severity(warning))]
|
||||
#[diagnostic(severity(warning), help("Using the return value is a legacy feature."))]
|
||||
struct NoRenderReturnValueDiagnostic(#[label] pub Span);
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
|
@ -64,16 +64,18 @@ impl Rule for NoRenderReturnValue {
|
|||
.contains(ScopeFlags::Arrow);
|
||||
|
||||
if is_arrow_function {
|
||||
ctx.nodes().ancestors(parent_node.id()).skip(1).find(|node_id| {
|
||||
let parent_node = ctx.nodes().get_node(*node_id);
|
||||
matches!(parent_node.kind(), AstKind::ArrowExpression(_))
|
||||
.then(|| {
|
||||
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),
|
||||
));
|
||||
})
|
||||
.is_some()
|
||||
});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -101,6 +103,8 @@ fn test() {
|
|||
("var foo = React.render(<div />, root);", None),
|
||||
("var foo = render(<div />, root)", None),
|
||||
("var foo = ReactDom.renderder(<div />, root)", None),
|
||||
("var foo = ReactDom.renderder(<div />, root)", None),
|
||||
("export const foo = () => ({ destroy: ({ dom }) => { ReactDOM.unmountComponentAtNode(dom); } });", None),
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ expression: no_render_return_value
|
|||
1 │ var Hello = ReactDOM.render(<div />, document.body);
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
⚠ eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.
|
||||
╭─[no_render_return_value.tsx:2:1]
|
||||
|
|
@ -15,6 +16,7 @@ expression: no_render_return_value
|
|||
· ───────────────
|
||||
4 │ };
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
⚠ eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.
|
||||
╭─[no_render_return_value.tsx:2:1]
|
||||
|
|
@ -23,29 +25,34 @@ expression: no_render_return_value
|
|||
· ───────────────
|
||||
4 │ }
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
⚠ eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.
|
||||
╭─[no_render_return_value.tsx:1:1]
|
||||
1 │ var render = (a, b) => ReactDOM.render(a, b)
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
⚠ eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.
|
||||
╭─[no_render_return_value.tsx:1:1]
|
||||
1 │ this.o = ReactDOM.render(<div />, document.body);
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
⚠ eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.
|
||||
╭─[no_render_return_value.tsx:1:1]
|
||||
1 │ var v; v = ReactDOM.render(<div />, document.body);
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
⚠ eslint-plugin-react(no-render-return-value): Do not depend on the return value from ReactDOM.render.
|
||||
╭─[no_render_return_value.tsx:1:1]
|
||||
1 │ var inst = ReactDOM.render(<div />, document.body);
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Using the return value is a legacy feature.
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue