Skip to content

Conversation

@ruidosujeira
Copy link
Contributor

Summary

Fixes #8435

This PR fixes a false positive in noUnusedVariables where type parameters in TypeScript construct signatures were incorrectly flagged as unused.

Problem

The semantic model was not tracking scopes for TS_CONSTRUCT_SIGNATURE_TYPE_MEMBER nodes. This caused type parameters in construct signatures like new <T>(): T to not be properly registered, leading the linter to report them as unused even though they were clearly used in the return type.

Solution

Added TS_CONSTRUCT_SIGNATURE_TYPE_MEMBER to the scope entry/exit events in events.rs, ensuring that:

  • Type parameters are correctly registered when entering a construct signature scope
  • Their usage is properly tracked within that scope
  • The noUnusedVariables rule can accurately determine if they're actually used

This is a minimal, fix that mirrors how other type member scopes are handled in the semantic model.

Test Plan

Added regression test in validInterface.ts:

interface BadConstructor {
  new <T>(): T;
}

This test verifies that:

  • Type parameter T is recognized as used in the return type
  • No false positive "unused type parameter" diagnostic is raised
  • The fix works correctly with the existing semantic analysis infrastructure

Ran the full test suite to ensure no regressions in other areas.

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: e6b1dc5

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

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

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

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Dec 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Walkthrough

Adds support for construct signature type members in the semantic event extractor so an ambient scope is pushed on entering and popped on leaving new construct signatures. Includes a test file adjustment showing added constructor-style interfaces and expanded class bodies, plus a changeset documenting a fix for a false positive in the noUnusedVariables rule related to generic construct-signature overloads.

Suggested reviewers

  • ematipico
  • siketyan
  • dyc3

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: tracking scope for TS construct signature type parameters to resolve the noUnusedVariables false positive.
Description check ✅ Passed The description clearly explains the problem, solution, and test plan, directly relating to the code changes that fix the false positive for unused type parameters in construct signatures.
Linked Issues check ✅ Passed The changes fully address issue #8435 by adding TS_CONSTRUCT_SIGNATURE_TYPE_MEMBER to scope entry/exit events in events.rs, ensuring type parameters in construct signatures are properly registered and tracked.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the construct signature type parameter issue: semantic event handling, test case, and changeset documentation—no extraneous modifications detected.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 657d8dd and e6b1dc5.

📒 Files selected for processing (1)
  • .changeset/fix-construct-signature-unused-type-param.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Write changesets that are concise (1-3 sentences), user-focused, use past tense for actions taken and present tense for Biome behavior, include code examples for rules, and end sentences with periods

Files:

  • .changeset/fix-construct-signature-unused-type-param.md
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use `Semantic<T>` query type instead of `Ast<T>` when a rule needs to access the semantic model for binding references and scope information
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Check if a variable is global before banning it to avoid false positives when the variable is redeclared in local scope; use the semantic model to verify global scope
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.

Applied to files:

  • .changeset/fix-construct-signature-unused-type-param.md
📚 Learning: 2025-12-12T10:11:05.549Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-12T10:11:05.549Z
Learning: Applies to .changeset/*.md : Write changesets that are concise (1-3 sentences), user-focused, use past tense for actions taken and present tense for Biome behavior, include code examples for rules, and end sentences with periods

Applied to files:

  • .changeset/fix-construct-signature-unused-type-param.md
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.

Applied to files:

  • .changeset/fix-construct-signature-unused-type-param.md
🪛 LanguageTool
.changeset/fix-construct-signature-unused-type-param.md

[uncategorized] ~5-~5: The preposition ‘to’ seems more likely in this position.
Context: ...dVariables for generic type parameters in construct signature type members (new ...

(AI_HYDRA_LEO_REPLACE_IN_TO)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: End-to-end tests
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test Node.js API
  • GitHub Check: Parser conformance
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: autofix
🔇 Additional comments (1)
.changeset/fix-construct-signature-unused-type-param.md (1)

1-5: LGTM! The changeset is concise, clearly explains the fix, uses proper past tense, includes a helpful code example, and follows the format guidelines. The false positive in the noUnusedVariables rule for generic type parameters in construct signatures is now properly documented.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 790a664 and 657d8dd.

📒 Files selected for processing (1)
  • .changeset/fix-construct-signature-unused-type-param.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Write changesets that are concise (1-3 sentences), user-focused, use past tense for actions taken and present tense for Biome behavior, include code examples for rules, and end sentences with periods

Files:

  • .changeset/fix-construct-signature-unused-type-param.md
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use `Semantic<T>` query type instead of `Ast<T>` when a rule needs to access the semantic model for binding references and scope information
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Check if a variable is global before banning it to avoid false positives when the variable is redeclared in local scope; use the semantic model to verify global scope
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.

Applied to files:

  • .changeset/fix-construct-signature-unused-type-param.md
🪛 LanguageTool
.changeset/fix-construct-signature-unused-type-param.md

[uncategorized] ~5-~5: The preposition ‘to’ seems more likely in this position.
Context: ...dVariables for generic type parameters in construct signature type members (new ...

(AI_HYDRA_LEO_REPLACE_IN_TO)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: autofix
  • GitHub Check: Parser conformance
🔇 Additional comments (1)
.changeset/fix-construct-signature-unused-type-param.md (1)

1-5: Changeset structure looks good.

The changeset is user-focused, concise, includes a relevant code example, and properly references the linked issue. Once the tense is corrected, this is ready to merge.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 15, 2025

CodSpeed Performance Report

Merging #8459 will not alter performance

Comparing ruidosujeira:fix/no-unused-variables-construct-signature-8435 (e6b1dc5) with main (b064786)1

Summary

✅ 58 untouched
⏩ 95 skipped2

Footnotes

  1. No successful run was found on main (7fedb92) during the generation of this report, so b064786 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@dyc3 dyc3 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!

@dyc3 dyc3 merged commit b17d12b into biomejs:main Dec 15, 2025
18 checks passed
This was referenced Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lint/correctness/noUnusedVariables falsePositive for multiple new overloads with generic parameters

2 participants