Skip to content
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

feat: add no-unused-props rule #1061

Merged
merged 1 commit into from
Mar 16, 2025
Merged

feat: add no-unused-props rule #1061

merged 1 commit into from
Mar 16, 2025

Conversation

baseballyama
Copy link
Member

close: #1028

Copy link

changeset-bot bot commented Feb 8, 2025

🦋 Changeset detected

Latest commit: cfe9251

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@baseballyama baseballyama force-pushed the feat/no-unused-props branch 2 times, most recently from 4fa2ea9 to 3c33117 Compare February 8, 2025 08:24
Copy link
Contributor

github-actions bot commented Feb 8, 2025

Try the Instant Preview in Online Playground

ESLint Online Playground

Install the Instant Preview to Your Local

npm i https://pkg.pr.new/eslint-plugin-svelte@1061

Published Instant Preview Packages:

View Commit

@baseballyama baseballyama force-pushed the feat/no-unused-props branch 16 times, most recently from 3991329 to 4f69e29 Compare February 8, 2025 20:00
@baseballyama baseballyama marked this pull request as ready for review February 8, 2025 20:00
@baseballyama baseballyama marked this pull request as draft February 9, 2025 02:29
@baseballyama baseballyama force-pushed the feat/no-unused-props branch 4 times, most recently from 6491439 to 27d2072 Compare February 9, 2025 04:43
@baseballyama baseballyama marked this pull request as ready for review February 9, 2025 04:43

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mts can be ts now.

@baseballyama baseballyama requested a review from Copilot February 27, 2025 01:58

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces the new rule "svelte/no-unused-props" to warn developers about declared props that are not used, thereby helping identify dead code and improve component clarity.

  • Adds documentation for the new rule
  • Implements the rule logic in the ESLint plugin
  • Updates tests, configurations, and related files to integrate the new rule

Reviewed Changes

File Description
docs/rules/no-unused-props.md Adds detailed documentation and examples for the new rule
packages/eslint-plugin-svelte/src/rules/no-unused-props.ts Implements the rule logic for detecting unused props
packages/eslint-plugin-svelte/tests/** Adds new YAML test fixtures to cover various invalid cases
packages/eslint-plugin-svelte/src/configs/flat/recommended.ts Updates recommended configuration with the new rule
packages/eslint-plugin-svelte/src/rule-types.ts Extends the rule types for the new rule
README.md, docs/rules.md, packages/eslint-plugin-svelte/src/utils/rules.ts Adds references and imports for the new rule

Copilot reviewed 84 out of 84 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

packages/eslint-plugin-svelte/src/rules/no-unused-props.ts:291

  • [nitpick] The function name 'hasRestElement' may be misleading as it checks for a rest element by testing if the used properties set is empty. A more descriptive name (e.g., 'patternHasRestElement') could improve code readability.
function hasRestElement(usedProps: Set<string>): boolean {
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ota-meshi ota-meshi merged commit 268a372 into main Mar 16, 2025
17 checks passed
@ota-meshi ota-meshi deleted the feat/no-unused-props branch March 16, 2025 23:53
@Jerboas86
Copy link

This PR gives false positive with brand types and tuples in typescript

@baseballyama
Copy link
Member Author

@Jerboas86 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.

@Jerboas86
Copy link

@baseballyama still here for both (tuples and brand types) with v3.2.1

@baseballyama
Copy link
Member Author

baseballyama commented Mar 17, 2025

@Jerboas86

Can you share some repl?
Like below?

  const { foo, bar }: { foo: [string, number], bar: string & v.brand("bar") } = $props();

@ota-meshi
Copy link
Member

Hey guys.
We have an issue template for reporting bugs.
To ensure we can fix the issue, could you please use it and share the details of the bug you have with the plugin and your repository where we can reproduce the issue?

@baseballyama
Copy link
Member Author

I've created a issue for above issue: #1134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule no-unused-props
3 participants