-
Notifications
You must be signed in to change notification settings - Fork 694
Remove uses of property existence with in
#6932
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -121,11 +121,13 @@ export interface Account extends Actor { | |||||||||
| } | ||||||||||
|
|
||||||||||
| export function isAccount(x: Actor | Team | Node | undefined | null): x is Account { | ||||||||||
| return !!x && 'name' in x && 'email' in x; | ||||||||||
| const asAccount = x as Partial<Account>; | ||||||||||
| return !!asAccount && !!asAccount?.name && !!asAccount?.email; | ||||||||||
|
||||||||||
| return !!asAccount && !!asAccount?.name && !!asAccount?.email; | |
| return !!asAccount && asAccount?.name !== undefined && asAccount?.email !== undefined; |
Copilot
AI
Jul 17, 2025
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.
The logic requires both name and email to be truthy, but according to the Account interface, email is optional (email?: string). This will incorrectly return false for valid Account objects that don't have an email.
| return !!asAccount && !!asAccount?.name && !!asAccount?.email; | |
| return !!asAccount && !!asAccount?.name; |
Copilot
AI
Jul 17, 2025
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.
The logic for checking if an object is a Team is incorrect. It should check if the slug property exists (is not undefined), not if it is truthy. A team could have slug: '', which would make this function return false incorrectly.
| return !!asTeam && !!asTeam?.slug; | |
| return !!asTeam && asTeam?.slug !== undefined; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,26 +104,28 @@ export interface MergeQueueEntry { | |||||||||
|
|
||||||||||
| export function reviewerId(reviewer: ITeam | IAccount): string { | ||||||||||
| // We can literally get different login values for copilot depending on where it's coming from (already assignee vs suggested assingee) | ||||||||||
| return isTeam(reviewer) ? reviewer.id : (reviewer.specialDisplayName ?? reviewer.login); | ||||||||||
| return isITeam(reviewer) ? reviewer.id : (reviewer.specialDisplayName ?? reviewer.login); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export function reviewerLabel(reviewer: ITeam | IAccount | IActor | any): string { | ||||||||||
| return isTeam(reviewer) ? (reviewer.name ?? reviewer.slug ?? reviewer.id) : (reviewer.specialDisplayName ?? reviewer.login); | ||||||||||
| return isITeam(reviewer) ? (reviewer.name ?? reviewer.slug ?? reviewer.id) : (reviewer.specialDisplayName ?? reviewer.login); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export function isTeam(reviewer: ITeam | IAccount | IActor | any): reviewer is ITeam { | ||||||||||
| return 'org' in reviewer; | ||||||||||
| export function isITeam(reviewer: ITeam | IAccount | IActor | any): reviewer is ITeam { | ||||||||||
| const asITeam = reviewer as Partial<ITeam>; | ||||||||||
| return !!asITeam.org; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export interface ISuggestedReviewer extends IAccount { | ||||||||||
| isAuthor: boolean; | ||||||||||
| isCommenter: boolean; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export function isSuggestedReviewer( | ||||||||||
| export function isISuggestedReviewer( | ||||||||||
| reviewer: IAccount | ISuggestedReviewer | ITeam | ||||||||||
| ): reviewer is ISuggestedReviewer { | ||||||||||
| return 'isAuthor' in reviewer && 'isCommenter' in reviewer; | ||||||||||
| const asISuggestedReviewer = reviewer as Partial<ISuggestedReviewer>; | ||||||||||
| return !!asISuggestedReviewer.isAuthor && !!asISuggestedReviewer.isCommenter; | ||||||||||
|
||||||||||
| return !!asISuggestedReviewer.isAuthor && !!asISuggestedReviewer.isCommenter; | |
| return typeof asISuggestedReviewer.isAuthor !== 'undefined' && typeof asISuggestedReviewer.isCommenter !== 'undefined'; |
Copilot
AI
Jul 17, 2025
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.
The logic for checking if an object is an ISuggestedReviewer is incorrect. The function should return true when both properties exist (regardless of their boolean values), but the current implementation requires both to be truthy. This could cause false negatives when isAuthor or isCommenter are explicitly false.
| return !!asISuggestedReviewer.isAuthor && !!asISuggestedReviewer.isCommenter; | |
| return 'isAuthor' in asISuggestedReviewer && 'isCommenter' in asISuggestedReviewer; |
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.
Checking for toString method existence is similar to the 'in' operator usage that this PR aims to eliminate. Consider using a more explicit type checking approach.