Skip to content

Commit

Permalink
fix(repo): set noUncheckedIndexAccess to true (#252)
Browse files Browse the repository at this point in the history
Co-authored-by: danadajian <[email protected]>
  • Loading branch information
danadajian and danadajian authored Jul 15, 2023
1 parent ec182f1 commit 0fc4648
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/backend/src/fetchCurrentPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const fetchCurrentPage = async ({
}: FetchCurrentPageInput) => {
const paginatedKeys = await getGroupedKeys(hash, bucket);
const currentPage = paginatedKeys[page - 1];
if (!currentPage) {
if (!currentPage?.keys) {
throw new TRPCError({
code: 'NOT_FOUND',
message: `Page ${page} does not exist. Only ${paginatedKeys.length} pages were found.`,
Expand Down
15 changes: 9 additions & 6 deletions app/backend/src/getGroupedKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ export const getGroupedKeys = async (hash: string, bucket: string) => {
const imageObjects = keys.map(parse);
const groupedImages = groupBy(imageObjects, 'dir');
const groupedKeys = Object.keys(groupedImages)
.filter(
key =>
groupedImages[key].length > 1 ||
groupedImages[key].find(item => item.name === NEW_IMAGE_NAME)
)
.filter(key => {
const groupedImage = groupedImages[key];
return (
groupedImage &&
(groupedImage.length > 1 ||
groupedImage.find(item => item.name === NEW_IMAGE_NAME))
);
})
.map(key => ({
title: getPathFromKey(key),
keys: groupedImages[key].map(({ base, dir }) => join(dir, base)),
keys: groupedImages[key]?.map(({ base, dir }) => join(dir, base)),
}));

if (!groupedKeys.length) {
Expand Down
2 changes: 1 addition & 1 deletion app/backend/src/updateBaseImagesInS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const filterNewImages = (s3Paths: string[]) => {

export const getBaseImagePaths = (newImagePaths: string[]) => {
return newImagePaths.map(path => {
const commitHash = path.split('/')[0];
const commitHash = path.split('/')[0] ?? '';
return path
.replace(commitHash, BASE_IMAGES_DIRECTORY)
.replace(NEW_IMAGE_NAME, BASE_IMAGE_NAME);
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/components/image-views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const SingleImageView: React.FC<SingleImageViewProps> = ({
})}
</div>
<img
src={images[selectedImageIndex].base64}
alt={images[selectedImageIndex].name}
src={images[selectedImageIndex]?.base64}
alt={images[selectedImageIndex]?.name}
/>
</div>
);
Expand Down
6 changes: 5 additions & 1 deletion app/frontend/components/main-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ const getViewType = async (
if (images.length === 1) {
return undefined;
}
const firstImage = images[0].base64;
const firstImage = images[0]?.base64;
if (!firstImage) {
return undefined;
}

const shouldViewSideBySide = await imageIsSmallEnoughForSideBySide(
firstImage
);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"isolatedModules": true,
"jsx": "react-jsx",
"strict": true,
"noEmit": true
"noEmit": true,
"noUncheckedIndexedAccess": true
}
}

0 comments on commit 0fc4648

Please sign in to comment.