Skip to content

feat(react-x): add 'no-unused-props' rule #1161

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

Draft
wants to merge 12 commits into
base: 2.0.0-beta
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions apps/website/content/docs/rules/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The `jsx-*` rules check for issues exclusive to JSX syntax, which are absent fro
| [`no-unstable-context-value`](./no-unstable-context-value) | 1️⃣ | | Prevents non-stable values (i.e. object literals) from being used as a value for `Context.Provider` | |
| [`no-unstable-default-props`](./no-unstable-default-props) | 1️⃣ | | Prevents using referential-type values as default props in object destructuring | |
| [`no-unused-class-component-members`](./no-unused-class-component-members) | 1️⃣ | | Warns unused class component methods and properties | |
| [`no-unused-props`](./no-unused-props) | 0️⃣ | | Warns about unused component prop declarations | |
| [`no-unused-state`](./no-unused-state) | 1️⃣ | | Warns unused class component state | |
| [`no-use-context`](./no-use-context) | 1️⃣ | `🔄` | Replaces usages of `useContext` with `use` | >=19.0.0 |
| [`no-useless-forward-ref`](./no-useless-forward-ref) | 1️⃣ | | Disallow useless `forwardRef` calls on components that don't use `ref`s | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const rules = {
"react-x/no-unstable-context-value": "warn",
"react-x/no-unstable-default-props": "warn",
"react-x/no-unused-class-component-members": "warn",
// "react-x/no-unused-props": "warn",
"react-x/no-unused-state": "warn",
"react-x/no-use-context": "warn",
"react-x/no-useless-forward-ref": "warn",
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/eslint-plugin-react-x/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import noUnsafeComponentWillUpdate from "./rules/no-unsafe-component-will-update
import noUnstableContextValue from "./rules/no-unstable-context-value";
import noUnstableDefaultProps from "./rules/no-unstable-default-props";
import noUnusedClassComponentMembers from "./rules/no-unused-class-component-members";
import noUnusedProps from "./rules/no-unused-props";
import noUnusedState from "./rules/no-unused-state";
import noUseContext from "./rules/no-use-context";
import noUselessForwardRef from "./rules/no-useless-forward-ref";
Expand Down Expand Up @@ -127,6 +128,7 @@ export const plugin = {
"no-unstable-context-value": noUnstableContextValue,
"no-unstable-default-props": noUnstableDefaultProps,
"no-unused-class-component-members": noUnusedClassComponentMembers,
"no-unused-props": noUnusedProps,
"no-unused-state": noUnusedState,
"no-use-context": noUseContext,
"no-useless-forward-ref": noUselessForwardRef,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: no-unused-props
---

**Full Name in `eslint-plugin-react-x`**

```sh copy
react-x/no-unused-props
```

**Full Name in `@eslint-react/eslint-plugin`**

```sh copy
@eslint-react/no-unused-props
```

## Description

Warns about unused component prop declarations.

## Examples

### Failing

```tsx
interface Props {
abc: string; // used
hello: string; // NOT used
}

function Component(props: Props) {
const { abc } = props; // `hello` isn't accessed from `props`
return null;
}
```

### Passing

```tsx
interface Props {
abc: string; // used
hello: string; // used
}

function Component(props: Props) {
const { abc, hello } = props;
return null;
}
```

## Implementation

- [Rule source](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x/src/rules/no-unused-props.ts)
- [Test source](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x/src/rules/no-unused-props.spec.ts)
Loading
Loading