From 5063d005cae9a528e13bf313d912043ed03cc10a Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Tue, 3 Dec 2024 08:29:25 +0000 Subject: [PATCH] chore: lint and remove unnecessary conditions (#183) * chore: lint and remove unnecessary conditions * chore: fix build --- .eslintrc.js | 6 +++ src/app/LayoutUI.tsx | 2 +- src/app/api/admin/reset/route.ts | 2 +- src/app/api/decrypt/route.ts | 2 +- src/app/bot-firewall/BotFirewall.tsx | 38 +++++++------- .../api/get-bot-visits/botVisitDatabase.ts | 12 ++--- src/app/coupon-fraud/CouponFraud.tsx | 2 +- src/app/coupon-fraud/api/claim/route.ts | 2 +- .../CredentialStuffing.tsx | 2 +- .../api/authenticate/route.ts | 2 +- src/app/loan-risk/LoanRisk.tsx | 2 +- src/app/loan-risk/api/request-loan/route.ts | 2 +- .../payment-fraud/api/place-order/route.ts | 2 +- src/app/paywall/Paywall.tsx | 4 +- src/app/paywall/api/article/[id]/route.ts | 2 +- src/app/personalization/Personalization.tsx | 6 +-- .../api/cart/add-item/route.ts | 6 +-- .../api/get-search-history/route.ts | 2 +- .../components/productCard.tsx | 2 +- .../components/searchComponents.tsx | 2 +- src/app/personalization/hooks/use-cart.ts | 13 ++--- src/app/playground/Playground.tsx | 51 +++++++++---------- src/app/playground/components/ArrowLinks.tsx | 5 +- .../components/BotDetectionResult.tsx | 4 +- .../components/IpBlocklistResult.tsx | 12 ++--- .../components/VpnDetectionResult.tsx | 8 +-- src/app/sms-pumping/SmsPumping.tsx | 2 +- .../api/send-verification-sms/route.ts | 2 +- src/app/sms-pumping/api/submit-code/route.ts | 4 +- src/app/vpn-detection/VpnDetectionUseCase.tsx | 2 +- .../vpn-detection/api/activate-ppp/route.ts | 10 ++-- .../data/getDiscountByCountry.ts | 2 +- src/app/web-scraping/WebScraping.tsx | 6 +-- src/app/web-scraping/api/flights/route.ts | 8 +-- .../components/DropdownMenu/DropdownMenu.tsx | 2 +- .../ResourceLinks/ResourceLinks.tsx | 2 +- .../UseCaseWrapper/UseCaseWrapper.tsx | 4 +- src/client/thirdParty/Amplitude.tsx | 2 +- .../thirdParty/ThirdPartyIntegrations.tsx | 2 +- src/env.ts | 15 +++--- src/server/checks.ts | 16 +++--- src/utils/locationUtils.ts | 6 +-- 42 files changed, 139 insertions(+), 139 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d747db8e..2db5d047 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,12 +6,18 @@ module.exports = { // necessary to pickup project-specific overrides in prettierrc.js 'prettier', ], + parser: '@typescript-eslint/parser', + parserOptions: { + project: './tsconfig.json', // Adjust the path if necessary + tsconfigRootDir: __dirname, + }, plugins: ['react-hooks', 'jsx-a11y'], rules: { 'react-hooks/rules-of-hooks': 'error', 'react-hooks/exhaustive-deps': 'warn', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unnecessary-condition': 'error', 'react/no-unescaped-entities': 'off', }, }; diff --git a/src/app/LayoutUI.tsx b/src/app/LayoutUI.tsx index 449706e8..491d56b2 100644 --- a/src/app/LayoutUI.tsx +++ b/src/app/LayoutUI.tsx @@ -10,7 +10,7 @@ import styles from './LayoutUI.module.scss'; export function LayoutUI({ children }: { children: React.ReactNode }) { const segments = useSelectedLayoutSegments(); - const embed = Boolean(segments?.includes('embed')); + const embed = Boolean(segments.includes('embed')); return (
{embed ? null :
} diff --git a/src/app/api/admin/reset/route.ts b/src/app/api/admin/reset/route.ts index fea10ccf..dfb35866 100644 --- a/src/app/api/admin/reset/route.ts +++ b/src/app/api/admin/reset/route.ts @@ -33,7 +33,7 @@ export async function POST(req: NextRequest): Promise { - {botVisits?.slice(0, displayedVisits).map((botVisit) => { + {botVisits.slice(0, displayedVisits).map((botVisit) => { return ( - - {formatDate(botVisit?.timestamp)} - {botVisit?.requestId} + + {formatDate(botVisit.timestamp)} + {botVisit.requestId} - {botVisit?.botResult} ({botVisit.botType}) + {botVisit.botResult} ({botVisit.botType}) - {botVisit?.ip} + {botVisit.ip} @@ -197,32 +197,32 @@ export const BotFirewall: FunctionComponent = () => { {/* Display bot visits as **CARDS** only on small screens */}
- {botVisits?.slice(0, displayedVisits).map((botVisit) => { + {botVisits.slice(0, displayedVisits).map((botVisit) => { return (
Timestamp
-
{formatDate(botVisit?.timestamp)}
+
{formatDate(botVisit.timestamp)}
Request ID
-
{botVisit?.requestId}
+
{botVisit.requestId}
Bot Type
- {botVisit?.botResult} ({botVisit.botType}) + {botVisit.botResult} ({botVisit.botType})
IP Address
-
{botVisit?.ip}
+
{botVisit.ip}
); @@ -268,13 +268,13 @@ export const BotFirewall: FunctionComponent = () => { {content} {/* Display load older bot visits button if necessary */} - {botVisits && botVisits?.length > DEFAULT_DISPLAYED_VISITS ? ( + {botVisits && botVisits.length > DEFAULT_DISPLAYED_VISITS ? ( diff --git a/src/app/bot-firewall/api/get-bot-visits/botVisitDatabase.ts b/src/app/bot-firewall/api/get-bot-visits/botVisitDatabase.ts index 01babcd8..b935ce43 100644 --- a/src/app/bot-firewall/api/get-bot-visits/botVisitDatabase.ts +++ b/src/app/bot-firewall/api/get-bot-visits/botVisitDatabase.ts @@ -53,12 +53,12 @@ export const saveBotVisit = async (botData: EventResponseBotData, visitorId: str BotVisitDbModel.create({ ip: botData.ip, visitorId: visitorId, - requestId: botData.requestId ?? 'N/A', - timestamp: botData.time ?? 'N/A', - botResult: botData.bot.result ?? 'N/A', - botType: botData.bot.type ?? 'N/A', - userAgent: botData.userAgent ?? 'N/A', - url: botData.url ?? 'N/A', + requestId: botData.requestId, + timestamp: botData.time, + botResult: botData.bot.result, + botType: botData.bot.type ?? '', + userAgent: botData.userAgent, + url: botData.url, }); }; diff --git a/src/app/coupon-fraud/CouponFraud.tsx b/src/app/coupon-fraud/CouponFraud.tsx index 45f1b40c..44d879df 100644 --- a/src/app/coupon-fraud/CouponFraud.tsx +++ b/src/app/coupon-fraud/CouponFraud.tsx @@ -110,7 +110,7 @@ export function CouponFraudUseCase() { {isLoading ? 'Processing...' : 'Apply'}
- {claimResponse?.message && !isLoading && ( + {claimResponse?.message && (
{claimResponse.message}
diff --git a/src/app/coupon-fraud/api/claim/route.ts b/src/app/coupon-fraud/api/claim/route.ts index d0f0b095..aecd70c2 100644 --- a/src/app/coupon-fraud/api/claim/route.ts +++ b/src/app/coupon-fraud/api/claim/route.ts @@ -28,7 +28,7 @@ export async function POST(req: Request): Promise {loginNetworkError && {loginNetworkError.message}} - {loginResponse?.message && !isLoading && ( + {loginResponse?.message && ( {loginResponse.message} diff --git a/src/app/credential-stuffing/api/authenticate/route.ts b/src/app/credential-stuffing/api/authenticate/route.ts index c621e91f..60ea62bc 100644 --- a/src/app/credential-stuffing/api/authenticate/route.ts +++ b/src/app/credential-stuffing/api/authenticate/route.ts @@ -44,7 +44,7 @@ export async function POST(req: Request): Promise> { } // Get visitorId from the Server API Identification event - const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId; + const visitorId = fingerprintResult.data.products.identification?.data?.visitorId; if (!visitorId) { logLoginAttempt(clientVisitorId, username, 'RequestIdValidationFailed'); return NextResponse.json({ message: 'Visitor ID not found.', severity: 'error' }, { status: 403 }); diff --git a/src/app/loan-risk/LoanRisk.tsx b/src/app/loan-risk/LoanRisk.tsx index e927f342..fe6c32f8 100644 --- a/src/app/loan-risk/LoanRisk.tsx +++ b/src/app/loan-risk/LoanRisk.tsx @@ -196,7 +196,7 @@ export function LoanRisk() {
{loanRequestNetworkError && {loanRequestNetworkError.message}} - {loanRequestResponse?.message && !isLoanRequestLoading && ( + {loanRequestResponse?.message && ( {loanRequestResponse.message} )}