Skip to content

feat(lint): implement useUnifiedTypeSignature rule #6320

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 2 commits into from
Jun 25, 2025

Conversation

mdevils
Copy link
Contributor

@mdevils mdevils commented Jun 14, 2025

Summary

Added the new rule useUnifiedTypeSignature, which disallows overload signatures that can be unified into a single signature.

Overload signatures that can be merged into a single signature are redundant and should be avoided. This rule helps simplify function signatures by combining overloads by making parameters optional and/or using type unions.

Example (Invalid): Overload signatures that can be unified:

function f(a: number): void;
function f(a: string): void;
interface I {
    a(): void;
    a(x: number): void;
}

Example (Valid): Unified signatures:

function f(a: number | string): void {}
interface I {
    a(x?: number): void;
}

Example (Valid): Different return types cannot be merged:

interface I {
    f(): void;
    f(x: number): number;
}

Test Plan

Tests are included

Notes

  1. I had to include an implementation of type AST comparison in order to implement this rule. Let me know if it is already implemented anywhere else. Or (best case) if we can generate that. Basically need an AST comparison regardless of CST stuff.
  2. As per discussion at 📎 Implement nursery/useUnifiedTypeSignature - typescript-eslint/unified-signatures #50, only adjacent overload signatures are checked.

Closes #50

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter A-Parser Area: parser L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Jun 14, 2025
@dyc3 dyc3 requested review from a team June 14, 2025 12:10
@mdevils mdevils force-pushed the feat/use-unified-type-signature branch from 80d7883 to 61aae18 Compare June 14, 2025 12:31
Copy link

codspeed-hq bot commented Jun 14, 2025

CodSpeed Performance Report

Merging #6320 will not alter performance

Comparing mdevils:feat/use-unified-type-signature (90830a7) with main (a27b825)

Summary

✅ 115 untouched benchmarks

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.

I'm impressed! To say that this was a tough one would be an understatement.

As always, impeccable work! As the 2.0 release is immanent, we'll wait to merge this for 2.1.

dyc3
dyc3 previously requested changes Jun 14, 2025
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.

Blocking to prevent accidental merges.

Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Amazing work indeed!


if required_self_len > other.len() + 1 {
// If the difference between signatures is more than 1,
// means those additional parameters are cross-connected,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does cross-connected mean? That might be something to clarify.

Copy link
Contributor Author

@mdevils mdevils Jun 16, 2025

Choose a reason for hiding this comment

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

Feel free to suggest a better description.

Basically when a difference between signatures is one parameter, we can potentially make it optional and merge signatures:

function test(x: number): void;
function test(x: number, y: string): void;
// -->
function test(x: number, y?: string): void;

But when the difference between signatures exceeds one parameter, we can't do it, because those parameters are either not specified or specified together.

function test(): void;
function test(x: number, y: string): void;
// we can't merge them this way, because it makes test(1) a valid call:
function test(x?: number, y?: string): void;

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Could you leave an example such as that in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Rephrased the comment and added an example.

/// Trait for comparing types to determine if they are equal.
/// This can potentially be instead generated in the same process as the AST node generation.
/// Basically it compares only AST ignoring node metadata like comments, whitespace, etc.
trait TypeEquals {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link

changeset-bot bot commented Jun 19, 2025

🦋 Changeset detected

Latest commit: 90830a7

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

@mdevils mdevils force-pushed the feat/use-unified-type-signature branch from e2d80d1 to 97d8ba6 Compare June 19, 2025 22:22
@arendjr arendjr added this to the Biome 2.1 milestone Jun 23, 2025
@mdevils mdevils force-pushed the feat/use-unified-type-signature branch from 97d8ba6 to 4de0847 Compare June 24, 2025 20:22
@mdevils
Copy link
Contributor Author

mdevils commented Jun 24, 2025

Rebased.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I haven't checked the implementation, however we should update the changeset

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
@mdevils
Copy link
Contributor Author

mdevils commented Jun 25, 2025

@ematipico sure, updated.

@ematipico ematipico removed this from the Biome 2.1 milestone Jun 25, 2025
@ematipico ematipico merged commit 5705f1a into biomejs:main Jun 25, 2025
30 checks passed
@github-actions github-actions bot mentioned this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Parser Area: parser A-Project Area: project L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Implement nursery/useUnifiedTypeSignature - typescript-eslint/unified-signatures
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy