Skip to content
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

refactor: remove typecasts and non-null assertions #1596

Merged
merged 10 commits into from
Apr 9, 2021
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@
{ "files": ["*.spec.ts"], "extends": ["plugin:jest/recommended"] },
{
"files": ["*.ts", "*.js"],
"excludedFiles": ["**/*.spec.ts", "**/.spec.js"],
"excludedFiles": ["**/*.spec.ts", "**/.spec.js", "**/__tests__/**/*.ts"],
"rules": {
"typesafe/no-await-without-trycatch": "warn"
"typesafe/no-await-without-trycatch": "warn",
"@typescript-eslint/no-non-null-assertion": "error"
}
}
],
Expand Down
4 changes: 0 additions & 4 deletions src/app/modules/examples/examples.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ const execExamplesQuery = (
): ResultAsync<QueryPageResult, DatabaseError> => {
return ResultAsync.fromPromise(
queryBuilder
// TODO(#42): Missing type in native typescript, waiting on upstream fixes.
// Tracking at https://github.com/Automattic/mongoose/issues/9714.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
.append(
selectAndProjectCardInfo(/* limit= */ PAGE_SIZE, /* offset= */ offset),
)
Expand Down

This file was deleted.

54 changes: 0 additions & 54 deletions src/app/modules/form/public-form/public-form.middlewares.ts

This file was deleted.

23 changes: 7 additions & 16 deletions src/app/modules/myinfo/myinfo.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ const hasMyInfoAnswer = (
return !!field.isVisible && !!field.myInfo?.attr
}

const filterFieldsWithHashes = (
responses: ProcessedFieldResponse[],
hashes: IHashes,
): VisibleMyInfoResponse[] => {
// Filter twice to get types to cooperate
return responses
.filter(hasMyInfoAnswer)
.filter((response) => !!hashes[response.myInfo.attr])
}

const transformAnswer = (field: VisibleMyInfoResponse): string => {
const answer = field.answer
return field.fieldType === BasicField.Date
Expand All @@ -117,14 +107,15 @@ export const compareHashedValues = (
responses: ProcessedFieldResponse[],
hashes: IHashes,
): MyInfoComparePromises => {
// Filter responses to only those fields with a corresponding hash
const fieldsWithHashes = filterFieldsWithHashes(responses, hashes)
// Map MyInfoAttribute to response
const myInfoResponsesMap: MyInfoComparePromises = new Map()
fieldsWithHashes.forEach((field) => {
const attr = field.myInfo.attr
// Already checked that hashes contains this attr
myInfoResponsesMap.set(field._id, compareSingleHash(hashes[attr]!, field))
responses.forEach((field) => {
if (hasMyInfoAnswer(field)) {
const hash = hashes[field.myInfo.attr]
if (hash) {
myInfoResponsesMap.set(field._id, compareSingleHash(hash, field))
}
}
})
return myInfoResponsesMap
}
Expand Down
18 changes: 12 additions & 6 deletions src/app/modules/spcp/__tests__/spcp.factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ describe('spcp.factory', () => {
)
const fetchLoginPageResult = await SpcpFactory.fetchLoginPage('')
const validateLoginPageResult = SpcpFactory.validateLoginPage('')
const extractJwtPayloadResult = await SpcpFactory.extractJwtPayload(
const extractSingpassJwtPayloadResult = await SpcpFactory.extractSingpassJwtPayload(
'',
)
const extractCorppassJwtPayloadResult = await SpcpFactory.extractCorppassJwtPayload(
'',
AuthType.SP,
)
const parseOOBParamsResult = SpcpFactory.parseOOBParams('', '', AuthType.SP)
const getSpcpAttributesResult = await SpcpFactory.getSpcpAttributes(
Expand All @@ -51,7 +53,8 @@ describe('spcp.factory', () => {
expect(createRedirectUrlResult._unsafeUnwrapErr()).toEqual(error)
expect(fetchLoginPageResult._unsafeUnwrapErr()).toEqual(error)
expect(validateLoginPageResult._unsafeUnwrapErr()).toEqual(error)
expect(extractJwtPayloadResult._unsafeUnwrapErr()).toEqual(error)
expect(extractSingpassJwtPayloadResult._unsafeUnwrapErr()).toEqual(error)
expect(extractCorppassJwtPayloadResult._unsafeUnwrapErr()).toEqual(error)
expect(parseOOBParamsResult._unsafeUnwrapErr()).toEqual(error)
expect(getSpcpAttributesResult._unsafeUnwrapErr()).toEqual(error)
expect(createJWTResult._unsafeUnwrapErr()).toEqual(error)
Expand All @@ -74,9 +77,11 @@ describe('spcp.factory', () => {
)
const fetchLoginPageResult = await SpcpFactory.fetchLoginPage('')
const validateLoginPageResult = SpcpFactory.validateLoginPage('')
const extractJwtPayloadResult = await SpcpFactory.extractJwtPayload(
const extractSingpassJwtPayloadResult = await SpcpFactory.extractSingpassJwtPayload(
'',
)
const extractCorppassJwtPayloadResult = await SpcpFactory.extractCorppassJwtPayload(
'',
AuthType.SP,
)
const parseOOBParamsResult = SpcpFactory.parseOOBParams('', '', AuthType.SP)
const getSpcpAttributesResult = await SpcpFactory.getSpcpAttributes(
Expand All @@ -98,7 +103,8 @@ describe('spcp.factory', () => {
expect(createRedirectUrlResult._unsafeUnwrapErr()).toEqual(error)
expect(fetchLoginPageResult._unsafeUnwrapErr()).toEqual(error)
expect(validateLoginPageResult._unsafeUnwrapErr()).toEqual(error)
expect(extractJwtPayloadResult._unsafeUnwrapErr()).toEqual(error)
expect(extractSingpassJwtPayloadResult._unsafeUnwrapErr()).toEqual(error)
expect(extractCorppassJwtPayloadResult._unsafeUnwrapErr()).toEqual(error)
expect(parseOOBParamsResult._unsafeUnwrapErr()).toEqual(error)
expect(getSpcpAttributesResult._unsafeUnwrapErr()).toEqual(error)
expect(createJWTResult._unsafeUnwrapErr()).toEqual(error)
Expand Down
Loading