Skip to content

Commit

Permalink
feat: add jsx-key rule (#1355)
Browse files Browse the repository at this point in the history
* feat: add jsx-key rule

* fix: clippy

* fix: update schemas

* message

Co-authored-by: Bartek Iwańczuk <[email protected]>

* message

Co-authored-by: Bartek Iwańczuk <[email protected]>

* message

Co-authored-by: Bartek Iwańczuk <[email protected]>

* fixup

* chore: simplify indentation

---------

Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
marvinhagemeister and bartlomieju authored Nov 29, 2024
1 parent 1e76fc0 commit 3aca2e7
Show file tree
Hide file tree
Showing 5 changed files with 515 additions and 0 deletions.
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-danger-with-children",
"jsx-no-duplicate-props",
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_danger_with_children;
pub mod jsx_no_duplicate_props;
Expand Down Expand Up @@ -270,6 +271,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_danger_with_children::JSXNoDangerWithChildren),
Box::new(jsx_no_duplicate_props::JSXNoDuplicateProps),
Expand Down
Loading

0 comments on commit 3aca2e7

Please sign in to comment.