-
-
Notifications
You must be signed in to change notification settings - Fork 664
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
feat(lint): implement useUnifiedTypeSignature
rule
#6320
Conversation
80d7883
to
61aae18
Compare
CodSpeed Performance ReportMerging #6320 will not alter performanceComparing Summary
|
There was a problem hiding this 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.
crates/biome_js_analyze/src/lint/nursery/use_unified_type_signature.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work indeed!
crates/biome_js_analyze/src/lint/nursery/use_unified_type_signature.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_unified_type_signature.rs
Outdated
Show resolved
Hide resolved
|
||
if required_self_len > other.len() + 1 { | ||
// If the difference between signatures is more than 1, | ||
// means those additional parameters are cross-connected, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
🦋 Changeset detectedLatest commit: 90830a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
e2d80d1
to
97d8ba6
Compare
97d8ba6
to
4de0847
Compare
Rebased. |
There was a problem hiding this 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>
@ematipico sure, updated. |
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:
Example (Valid): Unified signatures:
Example (Valid): Different return types cannot be merged:
Test Plan
Tests are included
Notes
nursery/useUnifiedTypeSignature
-typescript-eslint/unified-signatures
#50, only adjacent overload signatures are checked.Closes #50