Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add jsx-key rule #1355

Merged
merged 9 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/rules/jsx_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Ensure the `key` attribute is present when passing iterables into JSX. It allows
frameworks to optimize checking the order of elements.

### Invalid:

```tsx
const foo = [<div>foo</div>];
const foo = [<>foo</>];
[1, 2, 3].map(() => <div />);
Array.from([1, 2, 3], () => <div />);
```

### Valid:

```tsx
const foo = [<div key="a">foo</div>];
const foo = [<Fragment key="b">foo</Fragment>];
[1, 2, 3].map((x) => <div key={x} />);
Array.from([1, 2, 3], (x) => <div key={x} />);
```
1 change: 1 addition & 0 deletions schemas/rules.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"guard-for-in",
"jsx-boolean-value",
"jsx-curly-braces",
"jsx-key",
"jsx-no-children-prop",
"jsx-no-duplicate-props",
"jsx-props-no-spread-multi",
Expand Down
2 changes: 2 additions & 0 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod getter_return;
pub mod guard_for_in;
pub mod jsx_boolean_value;
pub mod jsx_curly_braces;
pub mod jsx_key;
pub mod jsx_no_children_prop;
pub mod jsx_no_duplicate_props;
pub mod jsx_props_no_spread_multi;
Expand Down Expand Up @@ -268,6 +269,7 @@ fn get_all_rules_raw() -> Vec<Box<dyn LintRule>> {
Box::new(guard_for_in::GuardForIn),
Box::new(jsx_boolean_value::JSXBooleanValue),
Box::new(jsx_curly_braces::JSXCurlyBraces),
Box::new(jsx_key::JSXKey),
Box::new(jsx_no_children_prop::JSXNoChildrenProp),
Box::new(jsx_no_duplicate_props::JSXNoDuplicateProps),
Box::new(jsx_props_no_spread_multi::JSXPropsNoSpreadMulti),
Expand Down
Loading