Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 45f2121

Browse files
authored
Adding a pre-commit hook to enforce formatting (#279)
* Updated prettier config, added pre-commit hook * Enforce formatting when commiting
1 parent 3e04737 commit 45f2121

File tree

108 files changed

+1927
-1936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1927
-1936
lines changed

.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
prettier --config .prettierrc --write src '!**/*.{scss,css,json}'
5+
git add -A src/

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm test -- --watchAll=false
54
eslint --max-warnings 0 src --ext .ts --ext .tsx --cache
5+
npm test -- --watchAll=false

.prettierrc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
"useTabs": false,
33
"printWidth": 80,
44
"tabWidth": 4,
5+
"semi": false,
56
"singleQuote": false,
6-
7-
"trailingComma": "none",
8-
9-
"jsxBracketSameLine": false,
10-
7+
"jsxSingleQuote": false,
8+
"trailingComma": "es5",
9+
"bracketSpacing": true,
10+
"bracketSameLine": false,
11+
"arrowParens": "always",
1112
"parser": "typescript",
12-
13-
"noSemi": true,
14-
15-
"rcVerbose": true
1613
}

src/__tests__/storybook.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import initStoryshots from "@storybook/addon-storyshots";
2-
initStoryshots();
1+
import initStoryshots from "@storybook/addon-storyshots"
2+
initStoryshots()

src/assets/images/icons/reactSvgIcons/SymbolFile.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "react";
1+
import * as React from "react"
22
//https://reactsvgicons.com/bootstrap
33

44
export function FileEarmarkIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -13,7 +13,7 @@ export function FileEarmarkIcon(props: React.SVGProps<SVGSVGElement>) {
1313
<path d="M4 0h5.5v1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V4.5h1V14a2 2 0 01-2 2H4a2 2 0 01-2-2V2a2 2 0 012-2z" />
1414
<path d="M9.5 3V0L14 4.5h-3A1.5 1.5 0 019.5 3z" />
1515
</svg>
16-
);
16+
)
1717
}
1818

1919
export function FileEarmarkMusicIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -32,7 +32,7 @@ export function FileEarmarkMusicIcon(props: React.SVGProps<SVGSVGElement>) {
3232
d="M9.757 5.67A1 1 0 0111 6.64v1.75l-2 .5v3.61c0 .495-.301.883-.662 1.123C7.974 13.866 7.499 14 7 14c-.5 0-.974-.134-1.338-.377-.36-.24-.662-.628-.662-1.123s.301-.883.662-1.123C6.026 11.134 6.501 11 7 11c.356 0 .7.068 1 .196V6.89a1 1 0 01.757-.97l1-.25z"
3333
/>
3434
</svg>
35-
);
35+
)
3636
}
3737

3838
export function FileEarmarkPlayIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -48,7 +48,7 @@ export function FileEarmarkPlayIcon(props: React.SVGProps<SVGSVGElement>) {
4848
<path d="M4 0h5.5v1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V4.5h1V14a2 2 0 01-2 2H4a2 2 0 01-2-2V2a2 2 0 012-2z" />
4949
<path d="M9.5 3V0L14 4.5h-3A1.5 1.5 0 019.5 3z" />
5050
</svg>
51-
);
51+
)
5252
}
5353

5454
export function FileEarmarkTextIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -67,7 +67,7 @@ export function FileEarmarkTextIcon(props: React.SVGProps<SVGSVGElement>) {
6767
d="M5 11.5a.5.5 0 01.5-.5h2a.5.5 0 010 1h-2a.5.5 0 01-.5-.5zm0-2a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5zm0-2a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5z"
6868
/>
6969
</svg>
70-
);
70+
)
7171
}
7272

7373
export function FileEarmarkImageIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -88,7 +88,7 @@ export function FileEarmarkImageIcon(props: React.SVGProps<SVGSVGElement>) {
8888
d="M6.502 7a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"
8989
/>
9090
</svg>
91-
);
91+
)
9292
}
9393

9494
export function FileEarmarkRichtextIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -107,7 +107,7 @@ export function FileEarmarkRichtextIcon(props: React.SVGProps<SVGSVGElement>) {
107107
d="M4.5 12.5A.5.5 0 015 12h3a.5.5 0 010 1H5a.5.5 0 01-.5-.5zm0-2A.5.5 0 015 10h6a.5.5 0 010 1H5a.5.5 0 01-.5-.5zm1.639-3.708l1.33.886 1.854-1.855a.25.25 0 01.289-.047l1.888.974V8.5a.5.5 0 01-.5.5H5a.5.5 0 01-.5-.5V8s1.54-1.274 1.639-1.208zM6.25 6a.75.75 0 100-1.5.75.75 0 000 1.5z"
108108
/>
109109
</svg>
110-
);
110+
)
111111
}
112112

113113
export function FileEarmarkLock2Icon(props: React.SVGProps<SVGSVGElement>) {
@@ -126,7 +126,7 @@ export function FileEarmarkLock2Icon(props: React.SVGProps<SVGSVGElement>) {
126126
<path d="M4 0h5.5v1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V4.5h1V14a2 2 0 01-2 2H4a2 2 0 01-2-2V2a2 2 0 012-2z" />
127127
<path d="M9.5 3V0L14 4.5h-3A1.5 1.5 0 019.5 3z" />
128128
</svg>
129-
);
129+
)
130130
}
131131

132132
export function FileEarmarkZipIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -146,7 +146,7 @@ export function FileEarmarkZipIcon(props: React.SVGProps<SVGSVGElement>) {
146146
/>
147147
<path d="M6 1h1.5v1H6zM5 2h1.5v1H5zm1 1h1.5v1H6zM5 4h1.5v1H5zm1 1h1.5v1H6V5z" />
148148
</svg>
149-
);
149+
)
150150
}
151151

152152
export function FileEarmarkCodeIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -165,7 +165,7 @@ export function FileEarmarkCodeIcon(props: React.SVGProps<SVGSVGElement>) {
165165
d="M8.646 6.646a.5.5 0 01.708 0l2 2a.5.5 0 010 .708l-2 2a.5.5 0 01-.708-.708L10.293 9 8.646 7.354a.5.5 0 010-.708zm-1.292 0a.5.5 0 00-.708 0l-2 2a.5.5 0 000 .708l2 2a.5.5 0 00.708-.708L5.707 9l1.647-1.646a.5.5 0 000-.708z"
166166
/>
167167
</svg>
168-
);
168+
)
169169
}
170170

171171
export function FileEarmarkPDFIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -184,7 +184,7 @@ export function FileEarmarkPDFIcon(props: React.SVGProps<SVGSVGElement>) {
184184
d="M7 5a.5.5 0 01.5.5v.634l.549-.317a.5.5 0 11.5.866L8 7l.549.317a.5.5 0 11-.5.866L7.5 7.866V8.5a.5.5 0 01-1 0v-.634l-.549.317a.5.5 0 11-.5-.866L6 7l-.549-.317a.5.5 0 01.5-.866l.549.317V5.5A.5.5 0 017 5zm-2 5.5a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5zm0 2a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5z"
185185
/>
186186
</svg>
187-
);
187+
)
188188
}
189189

190190
export function FileEarmarkBinaryIcon(props: React.SVGProps<SVGSVGElement>) {
@@ -199,7 +199,7 @@ export function FileEarmarkBinaryIcon(props: React.SVGProps<SVGSVGElement>) {
199199
<path d="M4 0h5.5v1H4a1 1 0 00-1 1v12a1 1 0 001 1h8a1 1 0 001-1V4.5h1V14a2 2 0 01-2 2H4a2 2 0 01-2-2V2a2 2 0 012-2z" />
200200
<path d="M9.5 3V0L14 4.5h-3A1.5 1.5 0 019.5 3zM5.526 14.09c.976 0 1.524-.79 1.524-2.205 0-1.412-.548-2.203-1.524-2.203-.978 0-1.526.79-1.526 2.203 0 1.415.548 2.206 1.526 2.206zm-.832-2.205c0-1.05.29-1.612.832-1.612.358 0 .607.247.733.721L4.7 12.137a6.749 6.749 0 01-.006-.252zm.832 1.614c-.36 0-.606-.246-.732-.718l1.556-1.145c.003.079.005.164.005.249 0 1.052-.29 1.614-.829 1.614zm5.329.501v-.595H9.73V9.772h-.69l-1.19.786v.688l1.136-.747h.05v2.906h-1.18V14h3z" />
201201
</svg>
202-
);
202+
)
203203
}
204204

205205
//--------------------------------------------------------------------\\
@@ -224,5 +224,5 @@ export function FolderIcon(props: React.SVGProps<SVGSVGElement>) {
224224
d="M13.81 4H2.19a1 1 0 00-.996 1.09l.637 7a1 1 0 00.995.91h10.348a1 1 0 00.995-.91l.637-7A1 1 0 0013.81 4zM2.19 3A2 2 0 00.198 5.181l.637 7A2 2 0 002.826 14h10.348a2 2 0 001.991-1.819l.637-7A2 2 0 0013.81 3H2.19z"
225225
/>
226226
</svg>
227-
);
227+
)
228228
}

src/background/api/api.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
import Axios from "axios";
2-
import { constants } from "../constants";
1+
import Axios from "axios"
2+
import { constants } from "../constants"
33

4-
export const hostname: string = constants.url.API_URL;
4+
export const hostname: string = constants.url.API_URL
55

6-
export const userPath: string = "/v1/users";
6+
export const userPath: string = "/v1/users"
77

8-
export const filesystemPath: string = "/v1/filesystem/";
8+
export const filesystemPath: string = "/v1/filesystem/"
99

1010
enum DataIntegrity {
1111
STABLE = "bg-success",
1212
POSSIBLE_RISK = "bg-warning",
13-
UNSTABLE = "bg-danger"
13+
UNSTABLE = "bg-danger",
1414
}
1515

1616
interface SystemHealthData {
17-
uptimeInSeconds: number;
18-
userCount: number;
19-
dataIntegrity: string;
20-
deployment: string;
21-
usedStorageInBytes: number;
22-
version: string;
17+
uptimeInSeconds: number
18+
userCount: number
19+
dataIntegrity: string
20+
deployment: string
21+
usedStorageInBytes: number
22+
version: string
2323
}
2424

2525
function callBackendHealth(): Promise<SystemHealthData> {
2626
return new Promise((resolve, reject) => {
2727
Axios.get(`${hostname}/health`)
2828
.then((data) => {
29-
resolve(data.data);
29+
resolve(data.data)
3030
})
3131
.catch((error) => {
32-
reject(error);
33-
});
34-
});
32+
reject(error)
33+
})
34+
})
3535
}
3636

37-
export { callBackendHealth, DataIntegrity };
38-
export type { SystemHealthData };
37+
export { callBackendHealth, DataIntegrity }
38+
export type { SystemHealthData }

src/background/api/auth.ts

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
1-
import Axios, { AxiosResponse } from "axios";
1+
import Axios, { AxiosResponse } from "axios"
22

3-
import { hostname, userPath } from "./api";
3+
import { hostname, userPath } from "./api"
44

5-
import { UserState } from "../redux/actions/userTypes";
6-
import store from "../redux/store";
5+
import { UserState } from "../redux/actions/userTypes"
6+
import store from "../redux/store"
77
import {
88
addAccessToken,
99
addRefreshToken,
1010
checkedCookies,
11-
removeTokens
12-
} from "../redux/actions/tokens";
13-
import { AccessToken, CookieStatus } from "../redux/actions/tokenTypes";
14-
import { deleteCookie, getCookie, setCookie } from "../methods/cookies";
15-
import { updateUser } from "../redux/actions/user";
16-
import { hashPassword } from "../methods/passwords";
11+
removeTokens,
12+
} from "../redux/actions/tokens"
13+
import { AccessToken, CookieStatus } from "../redux/actions/tokenTypes"
14+
import { deleteCookie, getCookie, setCookie } from "../methods/cookies"
15+
import { updateUser } from "../redux/actions/user"
16+
import { hashPassword } from "../methods/passwords"
1717

1818
// reference: https://daveceddia.com/access-redux-store-outside-react/
1919

20-
const cookieName: string = "refreshToken";
20+
const cookieName: string = "refreshToken"
2121

2222
export interface BackendLoginData {
23-
tokenValue: string;
24-
user: UserState;
23+
tokenValue: string
24+
user: UserState
2525
}
2626

2727
export interface BackendAuthData {
28-
tokenValue: string;
29-
userId: number;
30-
validUntil: number;
28+
tokenValue: string
29+
userId: number
30+
validUntil: number
3131
}
3232

3333
export const checkForCookie = () => {
34-
let refreshTokenCookieValue = getCookie(cookieName);
34+
let refreshTokenCookieValue = getCookie(cookieName)
3535
if (!refreshTokenCookieValue) {
36-
return store.dispatch(checkedCookies(CookieStatus.FINISHED));
36+
return store.dispatch(checkedCookies(CookieStatus.FINISHED))
3737
}
3838

39-
store.dispatch(addRefreshToken(refreshTokenCookieValue));
40-
store.dispatch(checkedCookies(CookieStatus.LOADING));
41-
getAccessTokenWithRefreshToken();
42-
};
39+
store.dispatch(addRefreshToken(refreshTokenCookieValue))
40+
store.dispatch(checkedCookies(CookieStatus.LOADING))
41+
getAccessTokenWithRefreshToken()
42+
}
4343

4444
export const loginWithUsernameAndPassword = async (
4545
userName: string,
4646
password: string,
4747
stayLoggedIn: boolean
4848
): Promise<BackendLoginData> => {
49-
console.log("[Auth] loginWithUsernameAndPassword", userName);
50-
let hashed = await hashPassword(password);
49+
console.log("[Auth] loginWithUsernameAndPassword", userName)
50+
let hashed = await hashPassword(password)
5151
return new Promise<BackendLoginData>((resolve, reject) => {
5252
let config = {
5353
headers: {
54-
Authorization: `Basic ${btoa(userName + ":" + hashed)}`
55-
}
56-
};
54+
Authorization: `Basic ${btoa(userName + ":" + hashed)}`,
55+
},
56+
}
5757

5858
return Axios.get<BackendLoginData>(
5959
hostname + userPath + "/login",
6060
config
6161
)
6262
.then((data: AxiosResponse<BackendLoginData>) => {
63-
console.log(data.data);
64-
store.dispatch(addRefreshToken(data.data.tokenValue));
65-
store.dispatch(updateUser(data.data.user as UserState));
63+
console.log(data.data)
64+
store.dispatch(addRefreshToken(data.data.tokenValue))
65+
store.dispatch(updateUser(data.data.user as UserState))
6666

6767
if (stayLoggedIn) {
68-
setCookie(cookieName, data.data.tokenValue, 60);
68+
setCookie(cookieName, data.data.tokenValue, 60)
6969
}
7070

71-
getAccessTokenWithRefreshToken();
71+
getAccessTokenWithRefreshToken()
7272
})
7373
.catch((error) => {
74-
reject(error);
75-
});
76-
});
77-
};
74+
reject(error)
75+
})
76+
})
77+
}
7878

7979
export const getAccessTokenWithRefreshToken = () => {
80-
console.log("getAccessTokenWithRefreshToken");
80+
console.log("getAccessTokenWithRefreshToken")
8181

82-
let refreshToken: string | null = store.getState().tokens.refreshToken;
82+
let refreshToken: string | null = store.getState().tokens.refreshToken
8383

8484
let config = {
8585
headers: {
86-
Authorization: `Bearer ${refreshToken}`
87-
}
88-
};
86+
Authorization: `Bearer ${refreshToken}`,
87+
},
88+
}
8989

9090
Axios.get<BackendAuthData>(hostname + userPath + "/auth", config)
9191
.then((data: AxiosResponse<BackendAuthData>) => {
92-
store.dispatch(checkedCookies(CookieStatus.FINISHED));
93-
setAuthHeaderToAxios(data.data.tokenValue);
92+
store.dispatch(checkedCookies(CookieStatus.FINISHED))
93+
setAuthHeaderToAxios(data.data.tokenValue)
9494

9595
store.dispatch(
9696
addAccessToken({
9797
token: data.data.tokenValue,
98-
timestamp: data.data.validUntil
98+
timestamp: data.data.validUntil,
9999
} as AccessToken)
100-
);
100+
)
101101
if (!store.getState().user.username) {
102-
getOwnUserData(data.data.userId);
102+
getOwnUserData(data.data.userId)
103103
}
104104
})
105105
.catch((error) => {
106-
store.dispatch(removeTokens());
107-
store.dispatch(checkedCookies(CookieStatus.FINISHED));
106+
store.dispatch(removeTokens())
107+
store.dispatch(checkedCookies(CookieStatus.FINISHED))
108108

109-
console.log(error);
109+
console.log(error)
110110
//you probably want to notify the user, maybe with a toast or similar
111-
});
112-
};
111+
})
112+
}
113113

114114
const getOwnUserData = (userId: number) => {
115115
Axios.get<UserState>(`${hostname}${userPath}/${userId}/info`)
116116
.then((response: AxiosResponse<UserState>) => {
117-
store.dispatch(updateUser(response.data));
117+
store.dispatch(updateUser(response.data))
118118
})
119119
.catch((error) => {
120-
console.log(error);
121-
});
122-
};
120+
console.log(error)
121+
})
122+
}
123123

124124
export const logout = () => {
125-
store.dispatch(removeTokens());
126-
deleteCookie(cookieName);
127-
};
125+
store.dispatch(removeTokens())
126+
deleteCookie(cookieName)
127+
}
128128

129129
function setAuthHeaderToAxios(accessToken: string) {
130-
Axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
130+
Axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`
131131
}

0 commit comments

Comments
 (0)