-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add rule no-unused-props
#1028
Comments
Thank you for proposing the rule! If possible, it would be even better if it could check the usage of unnamed props as well. <script lang="ts">
interface Props {
a: number;
[key: string]: unknown; // unused
}
let {a}: Props = $props();
// We can guess that the following would be correct:
// let {a, ...other}: Props = $props();
</script> And it would be even better if the rule could check member access as well. <script lang="ts">
interface Props {
a: string;
b: number; // unused
}
let props: Props = $props();
</script>
{props.a} <script lang="ts">
interface Props {
a: string;
b: number;
c: number; // unused
}
let { a, ...otherProps }: Props = $props();
</script>
{otherProps.b} I think the rule name might be better, something like |
Thanks for the good additional suggestions! I agree with the rule name, |
Did the usual updating of dependencies, ran eslint, got this output produced by this rule, is this intended?:
currentDayCommitHash is just a regular string passed as a prop. |
@shumadrid Can you share us code example? Like this? const { currentDayCommitHash }: { currentDayCommitHash: string } = $props(); |
@baseballyama Here is a minimal repro. It reports object-props as unused even when they have all their attributes referenced. It should probably allow for objects as long as at least one of its attributes is used inside the file ![]() |
@AndersRobstad Thank you! I will fix this ASAP. |
@shumadrid @AndersRobstad We’ve released v3.2.1. Could you please verify if this issue has been resolved? As this rule is relatively complex, there might still be some false positives. |
@baseballyama We're still seeing this reported as an error, even though the type prop is being referenced. In our codebase (and I assume many others as well), we often pass objects as props to components instead of just primitive values. This rule feels overly strict in our case since it requires every attribute of an object prop to be explicitly referenced for it to be considered valid.This makes it impractical for files where complex objects are passed as props, as we'd need to reference all of their attributes just to satisfy the rule. ![]() |
Seems to work fine for classes now though! They correctly only report as unused if they are never referenced at all |
By default, the Could you please tell me again about the practical issues you’re encountering with your specific use case? Additionally, we can use the |
@baseballyama Then the ![]() |
@AndersRobstad Thank you! But this is strange.🤔 I've created a issue: #1133 |
@baseballyama There still seems to be some problems with the reporting of unused props, created a new issue here |
Motivation
This rule aims to ensure consistency between the defined
Props
type and the actual use of$props()
.This prevents mistakes due to overlooking properties and improves code readability and maintainability.
Enforcing this rule helps developers understand and reduces the risk of potential bugs.
Description
Issue a warning if the type of the defined
Props
does not match the variable destructuring assignment in$props()
.Examples
Additional comments
No response
The text was updated successfully, but these errors were encountered: