Skip to content

Commit ba0a493

Browse files
authored
refactor: biome linter updates (#1226)
* refactor: address biome warnings. add experimental rule from nursery for unusedFnParams * refactor: enable nursery use default switch clause rule * biome: remove exhaustive rule options * revert biome: remove exhaustive rule options * remove comment
1 parent fb177e5 commit ba0a493

File tree

13 files changed

+74
-52
lines changed

13 files changed

+74
-52
lines changed

biome.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"enabled": true,
88
"rules": {
99
"recommended": true,
10+
"nursery": {
11+
"noUnusedFunctionParameters": "error",
12+
"useDefaultSwitchClause": "error"
13+
},
1014
"correctness": {
1115
"useExhaustiveDependencies": {
1216
"level": "warn",

src/__mocks__/electron.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
send: jest.fn(),
3333
on: jest.fn(),
3434
sendSync: jest.fn(),
35-
invoke: jest.fn((channel, ...args) => {
35+
invoke: jest.fn((channel, ..._args) => {
3636
switch (channel) {
3737
case 'get-platform':
3838
return Promise.resolve('darwin');

src/components/AccountNotifications.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export const AccountNotifications = (props: IProps) => {
8484
return (
8585
<RepositoryNotifications
8686
key={repoSlug}
87-
account={account}
8887
repoName={repoSlug}
8988
repoNotifications={repoNotifications}
9089
/>

src/components/NotificationRow.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
useState,
1717
} from 'react';
1818
import { AppContext } from '../context/App';
19-
import { type Account, IconColor } from '../types';
19+
import { IconColor } from '../types';
2020
import type { Notification } from '../typesGitHub';
2121
import { cn } from '../utils/cn';
2222
import {
@@ -33,19 +33,16 @@ import { formatReason } from '../utils/reason';
3333
import { PillButton } from './buttons/PillButton';
3434

3535
interface IProps {
36-
account: Account;
3736
notification: Notification;
3837
}
3938

40-
export const NotificationRow: FC<IProps> = ({ notification, account }) => {
39+
export const NotificationRow: FC<IProps> = ({ notification }) => {
4140
const {
42-
auth,
4341
settings,
4442
removeNotificationFromState,
4543
markNotificationRead,
4644
markNotificationDone,
4745
unsubscribeNotification,
48-
notifications,
4946
} = useContext(AppContext);
5047
const [animateExit, setAnimateExit] = useState(false);
5148

@@ -59,8 +56,12 @@ export const NotificationRow: FC<IProps> = ({ notification, account }) => {
5956
// no need to mark as read, github does it by default when opening it
6057
removeNotificationFromState(settings, notification);
6158
}
62-
}, [notifications, notification, auth, settings]); // notifications required here to prevent weird state issues
63-
59+
}, [
60+
notification,
61+
markNotificationDone,
62+
removeNotificationFromState,
63+
settings,
64+
]);
6465
const unsubscribeFromThread = (event: MouseEvent<HTMLElement>) => {
6566
// Don't trigger onClick of parent element.
6667
event.stopPropagation();

src/components/Repository.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
import { CheckIcon, MarkGithubIcon, ReadIcon } from '@primer/octicons-react';
22
import { type FC, useCallback, useContext } from 'react';
33
import { AppContext } from '../context/App';
4-
import type { Account } from '../types';
54
import type { Notification } from '../typesGitHub';
65
import { openRepository } from '../utils/links';
76
import { NotificationRow } from './NotificationRow';
87

98
interface IProps {
10-
account: Account;
119
repoNotifications: Notification[];
1210
repoName: string;
1311
}
1412

1513
export const RepositoryNotifications: FC<IProps> = ({
1614
repoName,
1715
repoNotifications,
18-
account,
1916
}) => {
2017
const { markRepoNotificationsRead, markRepoNotificationsDone } =
2118
useContext(AppContext);
2219

2320
const markRepoAsRead = useCallback(() => {
2421
markRepoNotificationsRead(repoNotifications[0]);
25-
}, [repoNotifications, account]);
22+
}, [repoNotifications, markRepoNotificationsRead]);
2623

2724
const markRepoAsDone = useCallback(() => {
2825
markRepoNotificationsDone(repoNotifications[0]);
29-
}, [repoNotifications, account]);
26+
}, [repoNotifications, markRepoNotificationsDone]);
3027

3128
const avatarUrl = repoNotifications[0].repository.owner.avatar_url;
3229
const repoSlug = repoNotifications[0].repository.full_name;
@@ -77,7 +74,7 @@ export const RepositoryNotifications: FC<IProps> = ({
7774
</div>
7875

7976
{repoNotifications.map((obj) => (
80-
<NotificationRow key={obj.id} account={account} notification={obj} />
77+
<NotificationRow key={obj.id} notification={obj} />
8178
))}
8279
</>
8380
);

src/context/App.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
129129
fetchNotifications({ auth, settings });
130130
}, Constants.FETCH_INTERVAL);
131131

132-
// biome-ignore lint/correctness/useExhaustiveDependencies: We need to update tray title when settings or notifications changes.
133132
useEffect(() => {
134133
const count = getNotificationCount(notifications);
135134

@@ -227,37 +226,37 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
227226

228227
const fetchNotificationsWithAccounts = useCallback(
229228
async () => await fetchNotifications({ auth, settings }),
230-
[auth, settings, notifications],
229+
[auth, settings, fetchNotifications],
231230
);
232231

233232
const markNotificationReadWithAccounts = useCallback(
234233
async (notification: Notification) =>
235234
await markNotificationRead({ auth, settings }, notification),
236-
[auth, notifications],
235+
[auth, settings, markNotificationRead],
237236
);
238237

239238
const markNotificationDoneWithAccounts = useCallback(
240239
async (notification: Notification) =>
241240
await markNotificationDone({ auth, settings }, notification),
242-
[auth, notifications],
241+
[auth, settings, markNotificationDone],
243242
);
244243

245244
const unsubscribeNotificationWithAccounts = useCallback(
246245
async (notification: Notification) =>
247246
await unsubscribeNotification({ auth, settings }, notification),
248-
[auth, notifications],
247+
[auth, settings, unsubscribeNotification],
249248
);
250249

251250
const markRepoNotificationsReadWithAccounts = useCallback(
252251
async (notification: Notification) =>
253252
await markRepoNotificationsRead({ auth, settings }, notification),
254-
[auth, notifications],
253+
[auth, settings, markRepoNotificationsRead],
255254
);
256255

257256
const markRepoNotificationsDoneWithAccounts = useCallback(
258257
async (notification: Notification) =>
259258
await markRepoNotificationsDone({ auth, settings }, notification),
260-
[auth, notifications],
259+
[auth, settings, markRepoNotificationsDone],
261260
);
262261

263262
return (

src/hooks/useNotifications.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ export const useNotifications = (): NotificationsState => {
150150
setStatus('success');
151151
}
152152
},
153-
[notifications],
153+
[markNotificationRead],
154154
);
155155

156156
const markRepoNotificationsRead = useCallback(
157-
async (state: GitifyState, notification: Notification) => {
157+
async (_state: GitifyState, notification: Notification) => {
158158
setStatus('loading');
159159

160160
const repoSlug = notification.repository.full_name;
@@ -220,7 +220,7 @@ export const useNotifications = (): NotificationsState => {
220220
setStatus('success');
221221
}
222222
},
223-
[notifications],
223+
[notifications, markNotificationDone],
224224
);
225225

226226
const removeNotificationFromState = useCallback(

src/routes/Accounts.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ export const AccountsRoute: FC = () => {
2727
const { auth, logoutFromAccount } = useContext(AppContext);
2828
const navigate = useNavigate();
2929

30-
const logoutAccount = useCallback((account: Account) => {
31-
logoutFromAccount(account);
32-
navigate(-1);
33-
updateTrayIcon();
34-
updateTrayTitle();
35-
}, []);
30+
const logoutAccount = useCallback(
31+
(account: Account) => {
32+
logoutFromAccount(account);
33+
navigate(-1);
34+
updateTrayIcon();
35+
updateTrayTitle();
36+
},
37+
[logoutFromAccount],
38+
);
3639

3740
const loginWithPersonalAccessToken = useCallback(() => {
3841
return navigate('/login-personal-access-token', { replace: true });

src/routes/LoginWithOAuthApp.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ export const LoginWithOAuthApp: FC = () => {
117117
);
118118
};
119119

120-
const login = useCallback(async (data: IValues) => {
121-
try {
122-
await loginWithOAuthApp(data as LoginOAuthAppOptions);
123-
} catch (err) {
124-
// Skip
125-
}
126-
}, []);
120+
const login = useCallback(
121+
async (data: IValues) => {
122+
try {
123+
await loginWithOAuthApp(data as LoginOAuthAppOptions);
124+
} catch (err) {
125+
// Skip
126+
}
127+
},
128+
[loginWithOAuthApp],
129+
);
127130

128131
return (
129132
<div className="flex-1 bg-white dark:bg-gray-dark dark:text-white">

src/routes/LoginWithPersonalAccessToken.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,20 @@ export const LoginWithPersonalAccessToken: FC = () => {
121121
);
122122
};
123123

124-
const login = useCallback(async (data: IValues) => {
125-
setIsValidToken(true);
126-
try {
127-
await loginWithPersonalAccessToken(
128-
data as LoginPersonalAccessTokenOptions,
129-
);
130-
navigate(-1);
131-
} catch (err) {
132-
setIsValidToken(false);
133-
}
134-
}, []);
124+
const login = useCallback(
125+
async (data: IValues) => {
126+
setIsValidToken(true);
127+
try {
128+
await loginWithPersonalAccessToken(
129+
data as LoginPersonalAccessTokenOptions,
130+
);
131+
navigate(-1);
132+
} catch (err) {
133+
setIsValidToken(false);
134+
}
135+
},
136+
[loginWithPersonalAccessToken],
137+
);
135138

136139
return (
137140
<div className="flex-1 bg-white dark:bg-gray-dark dark:text-white">

0 commit comments

Comments
 (0)