🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@YuyaYoshioka
Copy link
Contributor

@YuyaYoshioka YuyaYoshioka commented Nov 24, 2025

PR Checklist

Overview

Solution

This PR adds support for tracking destructured properties from this and counts them as member access at the point of destructuring.

Key insight: Destructuring from this is semantically equivalent to property access.

  • const { a } = this is equivalent to const a = this.a (reads this.a)
  • ({ a } = this) is equivalent to a = this.a (reads this.a)

Implementation Details

Added a shared handleThisDestructuring method that:

  1. Detects ObjectPattern destructuring from this
  2. Directly calls countReference for each destructured property at the point of destructuring
  3. Supports multiple destructuring contexts:
    • Variable declarations: const { a } = this
    • Assignment expressions: ({ a } = this)
    • Function parameters: (param = { a } = this) => {}

Handles all destructuring patterns:

  • ✅ Shorthand: const { a } = this
  • ✅ Renamed: const { a: x } = this (still counts as accessing this.a)
  • ✅ Multiple properties: const { a, b } = this
  • ✅ Static members: const { staticMember } = this in static methods

Test Coverage

Added comprehensive test cases:

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @YuyaYoshioka!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@netlify
Copy link

netlify bot commented Nov 24, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 83c15c3
🔍 Latest deploy log https://app.netlify.com/projects/typescript-eslint/deploys/692e3be20e39c1000800146f
😎 Deploy Preview https://deploy-preview-11785--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97 (🔴 down 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link

nx-cloud bot commented Nov 24, 2025

View your CI Pipeline Execution ↗ for commit 83c15c3

Command Status Duration Result
nx test eslint-plugin --coverage=false ✅ Succeeded 5m 9s View ↗
nx run-many -t lint ✅ Succeeded 3m 26s View ↗
nx run-many -t typecheck ✅ Succeeded 2m 1s View ↗
nx test eslint-plugin-internal --coverage=false ✅ Succeeded 4s View ↗
nx run integration-tests:test ✅ Succeeded 6s View ↗
nx test typescript-estree --coverage=false ✅ Succeeded 2s View ↗
nx run types:build ✅ Succeeded 2s View ↗
nx run generate-configs ✅ Succeeded 6s View ↗
Additional runs (29) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-12-02 01:19:11 UTC

@YuyaYoshioka YuyaYoshioka changed the title fix private destructed class member case fix(eslint-plugin): [no-unused-private-class-members] Private destructed class member is defined but used Nov 24, 2025
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

quickly looking, this misses the following cases:

class Foo {
  property = 1;

  caseOne() {
    let property;
    ({ property } = this);
  }

  caseTwo() {
    const foo = (
      { property } = this,
    ) => {}
  }
}

Instead of declaring an intermediate class property destructuredThisProperties and then writing to it, could we instead do it more localised -- eg do the countReference entirely within VariableDeclarator instead of splitting it across VariableDeclarator and Identifier?

@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 82.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.53%. Comparing base (d622778) to head (83c15c3).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...rc/util/class-scope-analyzer/classScopeAnalyzer.ts 82.00% 9 Missing ⚠️

❌ Your patch check has failed because the patch coverage (82.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11785      +/-   ##
==========================================
+ Coverage   90.49%   90.53%   +0.04%     
==========================================
  Files         522      523       +1     
  Lines       53360    53146     -214     
  Branches     8911     8853      -58     
==========================================
- Hits        48286    48114     -172     
+ Misses       5059     5019      -40     
+ Partials       15       13       -2     
Flag Coverage Δ
unittest 90.53% <82.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rc/util/class-scope-analyzer/classScopeAnalyzer.ts 82.37% <82.00%> (-0.08%) ⬇️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@YuyaYoshioka
Copy link
Contributor Author

Thank you for your review!
I fixed f7c6afe c5c4417

@YuyaYoshioka YuyaYoshioka changed the title fix(eslint-plugin): [no-unused-private-class-members] Private destructed class member is defined but used fix(eslint-plugin): [no-unused-private-class-members] private destructed class member is defined but used Nov 24, 2025
Copy link
Member

Choose a reason for hiding this comment

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

(testing)

Please also include a few tests around the long form destructuring assignment, i.e.

class Foo {
  private privateMember;

  method() {
    const { unused: privateNember } = this;
  }
}
class Foo {
  private privateMember;

  method() {
    const { privateNember: used } = this;
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!
I fixed at 83c15c3

@kirkwaiblinger kirkwaiblinger changed the title fix(eslint-plugin): [no-unused-private-class-members] private destructed class member is defined but used fix(eslint-plugin): [no-unused-private-class-members] private destructured class member is defined but used Dec 6, 2025
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.

Bug: [@typescript-eslint/no-unused-private-class-members] Private destructed class member is defined but used

3 participants