-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c02d42a
bootstrap new rule
ulrichstark ac323a5
add first tests and make them pass
ulrichstark d5c321f
add more tests
ulrichstark 961ba4e
add basic examples to doc page
ulrichstark 8e31ac6
remove rule from examples for now
ulrichstark 7a31396
Merge branch '2.0.0-beta' into no-unused-props
Rel1cx 64e2fb1
comment out no-unused-props in x preset
Rel1cx d72e304
fix: comment out no-unused-props rule in 'all' config
Rel1cx c7e4608
only report on property key and not the whole declaration
ulrichstark ba34768
add valid test and make it pass
ulrichstark f0b5e3b
add more tests to avoid false positives
ulrichstark 1393016
track properties of rest element, add more tests and comments
ulrichstark aa343f2
make it work in node 20
ulrichstark 8ed5807
refactor to avoid false positives, detect more cases, add tests
ulrichstark c52d0a2
simplify code
ulrichstark f7032d9
two more tests
ulrichstark 3ee1ae9
fix crash if declaration is in another file
ulrichstark 7891387
add a second sentence to the description
ulrichstark 68c0d8f
some final hopefully correct docs changes
ulrichstark d229530
test: add test cases related to `PropsWithChildren` and `forwardRef`
Rel1cx 9010cf4
test: add multiple components case
Rel1cx 638c3c3
test: remove todo for multiple components case
Rel1cx 3461a5b
chore: minor fixes
Rel1cx 67ccee8
outline differences to original rule in docs description and example
ulrichstark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/plugins/eslint-plugin-react-x/src/rules/no-unused-props.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| 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. | ||
|
|
||
| Unused props increase maintenance overhead and may mislead consumers of the component into thinking the prop is required or meaningful, even when it has no effect. | ||
|
|
||
| This is the TypeScript-only version of [`eslint-plugin-react/no-unused-prop-types`](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md). In contrast to the original rule, this rule | ||
|
|
||
| - doesn't support the legacy propTypes syntax | ||
| - combines the used props of one type definition declared by multiple components | ||
|
|
||
| ## 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; | ||
| } | ||
| ``` | ||
|
|
||
| ```tsx | ||
| interface Props { | ||
| abc: string; // used by Component1 | ||
| hello: string; // used by Component2 | ||
| } | ||
|
|
||
| function Component1({ abc }: Props) { | ||
| return null; | ||
| } | ||
|
|
||
| function Component2({ 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) | ||
|
|
||
| ## See Also | ||
|
|
||
| - [`no-prop-types`](/docs/rules/no-prop-types)\ | ||
| Disallows `propTypes` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.