Skip to content

Commit

Permalink
[New] jsx-sort-props: add className to RESERVED_PROPS_LIST
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonkat committed Nov 15, 2024
1 parent 4ef92b4 commit 35a33f1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/rules/jsx-sort-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ When `true`, alphabetical order is **not** enforced:

This can be a boolean or an array option.

When `reservedFirst` is defined, React reserved props (`children`, `dangerouslySetInnerHTML` - **only for DOM components**, `key`, and `ref`) must be listed before all other props, but still respecting the alphabetical order:
When `reservedFirst` is defined, React reserved props (`children`, `dangerouslySetInnerHTML` - **only for DOM components**, `key`, and `ref`) or `className` must be listed before all other props, but still respecting the alphabetical order:

```jsx
<Hello key={0} ref={johnRef} name="John">
<div dangerouslySetInnerHTML={{__html: 'ESLint Plugin React!'}} ref={dangerDivRef} />
</Hello>
```

If given as an array, the array's values will override the default list of reserved props. **Note**: the values in the array may only be a **subset** of React reserved props.
If given as an array, the array's values will override the default list of reserved props. **Note**: the values in the array may only be a **subset** of React reserved props or `className`.

With `reservedFirst: ["key"]`, the following will **not** warn:

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const RESERVED_PROPS_LIST = [
'dangerouslySetInnerHTML',
'key',
'ref',
'className',
];

function isReservedPropName(name, list) {
Expand Down

0 comments on commit 35a33f1

Please sign in to comment.