mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(linter/no_children_prop): point the span to "children" (#1106)
This commit is contained in:
parent
22c31cef3f
commit
b703c0c5b5
2 changed files with 17 additions and 17 deletions
|
|
@ -7,7 +7,7 @@ use oxc_diagnostics::{
|
|||
thiserror::Error,
|
||||
};
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, utils::is_create_element_call, AstNode};
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ impl Rule for NoChildrenProp {
|
|||
AstKind::JSXAttributeItem(JSXAttributeItem::Attribute(attr)) => {
|
||||
let JSXAttributeName::Identifier(attr_ident) = &attr.name else { return };
|
||||
if attr_ident.name == "children" {
|
||||
ctx.diagnostic(NoChildrenPropDiagnostic(attr.span));
|
||||
ctx.diagnostic(NoChildrenPropDiagnostic(attr_ident.span));
|
||||
}
|
||||
}
|
||||
AstKind::CallExpression(call_expr) => {
|
||||
|
|
@ -76,7 +76,7 @@ impl Rule for NoChildrenProp {
|
|||
if let Some(span) = obj_expr.properties.iter().find_map(|prop| {
|
||||
if let ObjectPropertyKind::ObjectProperty(prop) = prop {
|
||||
if prop.key.is_specific_static_name("children") {
|
||||
return Some(prop.span);
|
||||
return Some(prop.key.span());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,98 +12,98 @@ expression: no_children_prop
|
|||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <div children="Children" />;
|
||||
· ───────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <div children={<div />} />;
|
||||
· ──────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <div children={[<div />, <div />]} />;
|
||||
· ─────────────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <div children="Children">Children</div>;
|
||||
· ───────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement("div", {children: "Children"});
|
||||
· ────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement("div", {children: "Children"}, "Children");
|
||||
· ────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement("div", {children: React.createElement("div")});
|
||||
· ────────────────────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement("div", {children: [React.createElement("div"), React.createElement("div")]});
|
||||
· ──────────────────────────────────────────────────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <MyComponent children="Children" />
|
||||
· ───────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement(MyComponent, {children: "Children"});
|
||||
· ────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <MyComponent className="class-name" children="Children" />;
|
||||
· ───────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement(MyComponent, {children: "Children", className: "class-name"});
|
||||
· ────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ <MyComponent {...props} children="Children" />;
|
||||
· ───────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
⚠ eslint-plugin-react(no-children-prop): Avoid passing children using a prop.
|
||||
╭─[no_children_prop.tsx:1:1]
|
||||
1 │ React.createElement(MyComponent, {...props, children: "Children"})
|
||||
· ────────────────────
|
||||
· ────────
|
||||
╰────
|
||||
help: The canonical way to pass children in React is to use JSX elements
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue