Skip to content

refactor: further sonar issue fixes #1819

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
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/renderer/components/avatars/AvatarWithFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const AvatarWithFallback: React.FC<IAvatarWithFallback> = ({
const [isBroken, setIsBroken] = useState(false);

const isNonHuman = isNonHumanUser(userType);
const DefaultUserIcon = isNonHuman ? MarkGithubIcon : FeedPersonIcon;

// TODO explore using AnchoredOverlay component (https://primer.style/components/anchored-overlay/react/alpha) to render Avatar Card on hover
return (
Expand All @@ -36,11 +37,7 @@ export const AvatarWithFallback: React.FC<IAvatarWithFallback> = ({
data-testid="avatar"
>
{!src || isBroken ? (
isNonHuman ? (
<MarkGithubIcon size={size} />
) : (
<FeedPersonIcon size={size} />
)
<DefaultUserIcon size={size} />
) : (
<Avatar
src={src}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/fields/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export const Checkbox: FC<ICheckbox> = ({
<Tooltip name={`tooltip-${props.name}`} tooltip={props.tooltip} />
)}

{counter && (
{counter ? (
<CounterLabel scheme={props.checked ? 'primary' : 'secondary'}>
{counter}
</CounterLabel>
)}
) : null}
</Stack>
)
);
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/components/metrics/MetricPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export const MetricPill: FC<IMetricPill> = (props: IMetricPill) => {
>
<Stack direction="horizontal" align="center" gap="none">
<props.icon size={Size.XSMALL} className={props.color} />
{props.metric && <Text className="text-xxs px-1">{props.metric}</Text>}
{props.metric ? (
<Text className="text-xxs px-1">{props.metric}</Text>
) : null}
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

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

What's the reasoning behind this?

Copy link
Member Author

Choose a reason for hiding this comment

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

</Stack>
</Label>
);
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/notifications/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export const NotificationRow: FC<INotificationRow> = ({
? `#${notification.subject.number}`
: '';

const notificationTitle =
`${notification.subject.title} ${notificationNumber && `[${notificationNumber}]`}`.trim();
const notificationTitle = notificationNumber
? `${notification.subject.title} [${notificationNumber}]`
: notification.subject.title;

const groupByDate = settings.groupBy === GroupBy.DATE;

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/typesGitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type PullRequestReviewAuthorAssociation =
| 'NONE'
| 'OWNER';

// TODO: Add explicit types for GitHub API response vs Gitify Notifications object
// TODO: #828 Add explicit types for GitHub API response vs Gitify Notifications object
export type Notification = GitHubNotification & GitifyNotification;

export interface GitHubNotification {
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/utils/auth/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ describe('renderer/utils/auth/utils.ts', () => {
});

await expect(async () => await auth.authGitHub()).rejects.toEqual(
"Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: The redirect_uri is missing or invalid. Docs: https://docs.github.com/en/developers/apps/troubleshooting-oauth-errors",
new Error(
"Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: The redirect_uri is missing or invalid. Docs: https://docs.github.com/en/developers/apps/troubleshooting-oauth-errors",
),
);

expect(openExternalLinkMock).toHaveBeenCalledTimes(1);
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/utils/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export function authGitHub(
});
} else if (error) {
reject(
`Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: ${errorDescription} Docs: ${errorUri}`,
new Error(
`Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: ${errorDescription} Docs: ${errorUri}`,
),
);
}
};
Expand Down Expand Up @@ -257,9 +259,7 @@ export function getNewOAuthAppURL(hostname: Hostname): Link {
}

export function isValidHostname(hostname: Hostname) {
return /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/i.test(
hostname,
);
return /^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}$/i.test(hostname);
}

export function isValidClientId(clientId: ClientID) {
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Link } from '../types';
import type { ClientID, ClientSecret, Hostname } from '../types';
import type { ClientID, ClientSecret, Hostname, Link } from '../types';

export const Constants = {
REPO_SLUG: 'gitify-app/gitify',
Expand Down