From a79c6227b145cb6e28933c015fefac4a425f1035 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Mon, 28 Aug 2023 11:25:50 +0100 Subject: [PATCH] Fix frontend lint issues --- .../utilities/checks/password/PasswordCheck.ts | 13 ++++++------- .../utilities/checks/password/checkPassword.ts | 6 +++--- frontend/src/pages/password-reset.tsx | 8 +++----- frontend/src/pages/signupinvite.tsx | 2 +- .../ChangePasswordSection/ChangePasswordSection.tsx | 2 +- .../components/UserInfoSSOStep/UserInfoSSOStep.tsx | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/utilities/checks/password/PasswordCheck.ts b/frontend/src/components/utilities/checks/password/PasswordCheck.ts index 3804841fc..90ea4c7ea 100644 --- a/frontend/src/components/utilities/checks/password/PasswordCheck.ts +++ b/frontend/src/components/utilities/checks/password/PasswordCheck.ts @@ -1,9 +1,8 @@ -import { letterCharRegex, numAndSpecialCharRegex, repeatedCharRegex, escapeCharRegex, lowEntropyRegexes } from "./passwordRegexes"; import { checkIsPasswordBreached } from "./checkIsPasswordBreached"; +import { escapeCharRegex, letterCharRegex, lowEntropyRegexes,numAndSpecialCharRegex, repeatedCharRegex } from "./passwordRegexes"; interface PasswordCheckProps { password: string; - errorCheck: boolean; setPasswordErrorTooShort: (value: boolean) => void; setPasswordErrorTooLong: (value: boolean) => void; setPasswordErrorNoLetterChar: (value: boolean) => void; @@ -23,9 +22,9 @@ const passwordCheck = async ({ setPasswordErrorRepeatedChar, setPasswordErrorEscapeChar, setPasswordErrorLowEntropy, - setPasswordErrorBreached, - errorCheck + setPasswordErrorBreached }: PasswordCheckProps) => { + let errorCheck = false; const tests = [ { name: "tooShort", @@ -74,15 +73,15 @@ const passwordCheck = async ({ } else { setPasswordErrorBreached(false); } - - for (const test of tests) { + + tests.forEach((test) => { if (!test.validator(password)) { errorCheck = true; test.setError(true); } else { test.setError(false); } - } + }) return errorCheck; }; diff --git a/frontend/src/components/utilities/checks/password/checkPassword.ts b/frontend/src/components/utilities/checks/password/checkPassword.ts index b1b72e797..55fede5a6 100644 --- a/frontend/src/components/utilities/checks/password/checkPassword.ts +++ b/frontend/src/components/utilities/checks/password/checkPassword.ts @@ -1,5 +1,5 @@ -import { letterCharRegex, numAndSpecialCharRegex, repeatedCharRegex, escapeCharRegex, lowEntropyRegexes } from "./passwordRegexes"; import { checkIsPasswordBreached } from "./checkIsPasswordBreached"; +import { escapeCharRegex, letterCharRegex, lowEntropyRegexes,numAndSpecialCharRegex, repeatedCharRegex } from "./passwordRegexes"; type Errors = { tooShort?: string; @@ -86,11 +86,11 @@ const checkPassword = async ({ password, setErrors }: CheckPasswordParams): Prom errors.breached = "Password was found in a data breach."; } - for (const test of tests) { + tests.forEach((test) => { if (test.validator && !test.validator(password)) { errors[test.name as keyof Errors] = test.errorText; } - } + }); setErrors(errors); return Object.keys(errors).length > 0; diff --git a/frontend/src/pages/password-reset.tsx b/frontend/src/pages/password-reset.tsx index 6d9becb08..0f63ef4af 100644 --- a/frontend/src/pages/password-reset.tsx +++ b/frontend/src/pages/password-reset.tsx @@ -10,7 +10,7 @@ import queryString from "query-string"; import Button from "@app/components/basic/buttons/Button"; import InputField from "@app/components/basic/InputField"; -import passwordCheck from "~/components/utilities/checks/password/PasswordCheck"; +import passwordCheck from "@app/components/utilities/checks/password/PasswordCheck"; import Aes256Gcm from "@app/components/utilities/cryptography/aes-256-gcm"; import { useResetPassword, useVerifyPasswordResetCode } from "@app/hooks/api"; import { getBackupEncryptedPrivateKey } from "@app/hooks/api/auth/queries"; @@ -79,8 +79,7 @@ export default function PasswordReset() { setPasswordErrorRepeatedChar, setPasswordErrorEscapeChar, setPasswordErrorLowEntropy, - setPasswordErrorBreached, - errorCheck: false + setPasswordErrorBreached }); if (!errorCheck) { @@ -240,8 +239,7 @@ export default function PasswordReset() { setPasswordErrorRepeatedChar, setPasswordErrorEscapeChar, setPasswordErrorLowEntropy, - setPasswordErrorBreached, - errorCheck: false + setPasswordErrorBreached }); }} type="password" diff --git a/frontend/src/pages/signupinvite.tsx b/frontend/src/pages/signupinvite.tsx index 20a093b9c..0784806c8 100644 --- a/frontend/src/pages/signupinvite.tsx +++ b/frontend/src/pages/signupinvite.tsx @@ -16,7 +16,7 @@ import { encodeBase64 } from "tweetnacl-util"; import Button from "@app/components/basic/buttons/Button"; import InputField from "@app/components/basic/InputField"; -import checkPassword from "~/components/utilities/checks/password/checkPassword"; +import checkPassword from "@app/components/utilities/checks/password/checkPassword"; import Aes256Gcm from "@app/components/utilities/cryptography/aes-256-gcm"; import { deriveArgonKey } from "@app/components/utilities/cryptography/crypto"; import issueBackupKey from "@app/components/utilities/cryptography/issueBackupKey"; diff --git a/frontend/src/views/Settings/PersonalSettingsPage/ChangePasswordSection/ChangePasswordSection.tsx b/frontend/src/views/Settings/PersonalSettingsPage/ChangePasswordSection/ChangePasswordSection.tsx index 6a141d652..0c5012cdb 100644 --- a/frontend/src/views/Settings/PersonalSettingsPage/ChangePasswordSection/ChangePasswordSection.tsx +++ b/frontend/src/views/Settings/PersonalSettingsPage/ChangePasswordSection/ChangePasswordSection.tsx @@ -8,7 +8,7 @@ import * as yup from "yup"; import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider"; import attemptChangePassword from "@app/components/utilities/attemptChangePassword"; -import checkPassword from "~/components/utilities/checks/password/checkPassword"; +import checkPassword from "@app/components/utilities/checks/password/checkPassword"; import { Button, FormControl, Input } from "@app/components/v2"; import { useUser } from "@app/context"; diff --git a/frontend/src/views/Signup/components/UserInfoSSOStep/UserInfoSSOStep.tsx b/frontend/src/views/Signup/components/UserInfoSSOStep/UserInfoSSOStep.tsx index cc23933e9..23353d7d8 100644 --- a/frontend/src/views/Signup/components/UserInfoSSOStep/UserInfoSSOStep.tsx +++ b/frontend/src/views/Signup/components/UserInfoSSOStep/UserInfoSSOStep.tsx @@ -9,7 +9,7 @@ import nacl from "tweetnacl"; import { encodeBase64 } from "tweetnacl-util"; import InputField from "@app/components/basic/InputField"; -import checkPassword from "~/components/utilities/checks/password/checkPassword"; +import checkPassword from "@app/components/utilities/checks/password/checkPassword"; import Aes256Gcm from "@app/components/utilities/cryptography/aes-256-gcm"; import { deriveArgonKey } from "@app/components/utilities/cryptography/crypto"; import { saveTokenToLocalStorage } from "@app/components/utilities/saveTokenToLocalStorage";