Skip to content

Commit d28d31d

Browse files
committed
feat: added eslint and A11y for linting.
1 parent 6885ef4 commit d28d31d

18 files changed

Lines changed: 1039 additions & 62 deletions

eslint.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ export default defineConfig([
1515
extends: [
1616
js.configs.recommended,
1717
tseslint.configs.recommended,
18-
reactHooks.configs['recommended-latest'],
19-
reactRefresh.configs.vite,
2018
jsxA11y.flatConfigs.recommended,
2119
],
2220

21+
plugins: {
22+
'react-hooks': reactHooks,
23+
'react-refresh': reactRefresh,
24+
},
25+
2326
languageOptions: {
2427
ecmaVersion: 2020,
2528
globals: globals.browser,
2629
},
2730

2831
rules: {
32+
...reactHooks.configs['recommended-latest'].rules,
33+
...reactRefresh.configs.vite.rules,
2934
'jsx-a11y/alt-text': 'error',
3035
'jsx-a11y/anchor-is-valid': 'warn',
3136
'jsx-a11y/no-autofocus': 'warn',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@types/js-cookie": "^3.0.6",
2020
"@vitejs/plugin-react-swc": "^4.3.0",
2121
"axios": "^1.13.2",
22+
"eslint-plugin-jsx-a11y": "^6.10.2",
2223
"generate:api": "openapi-typescript http://localhost:8080/v3/api-docs -o src/api/generated/types.ts",
2324
"js-cookie": "^3.0.5",
2425
"jwt-decode": "^4.0.0",

pnpm-lock.yaml

Lines changed: 946 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context/AuthContext.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// context/AuthContext.tsx
22
import React, { createContext, useState, useEffect, useRef, useCallback } from "react";
3+
import type { AxiosError } from "axios";
34
import { authStore } from "@store/authStore";
45
import { authClient } from "@/utils/http/clients/authClient.client";
56
import { apiClient } from "@/utils/http/clients/backendApiClientGeneral";
@@ -89,7 +90,9 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
8990
try {
9091
const stack = new Error().stack;
9192
console.warn("loginSuccess called with undefined token, stack:\n", stack);
92-
} catch { }
93+
} catch {
94+
// intentional empty catch for stack logging
95+
}
9396
}
9497
setIsAuthenticated(true);
9598
};
@@ -111,9 +114,9 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
111114
return false;
112115
} catch (error) {
113116
console.error("Logout failed:", {
114-
message: (error as any)?.message,
115-
response: (error as any)?.response?.data,
116-
status: (error as any)?.response?.status,
117+
message: (error as AxiosError)?.message,
118+
response: (error as AxiosError)?.response?.data,
119+
status: (error as AxiosError)?.response?.status,
117120
});
118121
return false;
119122
}
@@ -146,9 +149,9 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
146149
}
147150
} catch (error) {
148151
console.error("AuthContext.bootstrap: refresh failed:", {
149-
message: (error as any)?.message,
150-
response: (error as any)?.response?.data,
151-
status: (error as any)?.response?.status,
152+
message: (error as AxiosError)?.message,
153+
response: (error as AxiosError)?.response?.data,
154+
status: (error as AxiosError)?.response?.status,
152155
});
153156
// Avoid stale bootstrap failure overriding a successful OAuth callback login.
154157
if (!hasLoginSucceededRef.current && !authStore.getToken()) {

src/context/LanguageContext.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
import React, { createContext, useContext, useState, useEffect } from 'react';
1+
// eslint-disable react-refresh/only-export-components
22

3-
const LanguageContext = createContext();
3+
import React, { createContext, useState, useEffect } from 'react';
4+
import { LanguageContextType } from '../types/language';
45

5-
export const useLanguage = () => useContext(LanguageContext);
6+
// eslint-disable-next-line react-refresh/only-export-components
7+
export const LanguageContext = createContext<LanguageContextType | null>(null);
68

79
export const LanguageProvider = ({ children }: { children: React.ReactNode }) => {
8-
const [lang, setLang] = useState(sessionStorage.getItem("lang"));
9-
10-
// Load saved language on mount
11-
useEffect(() => {
12-
const savedLang = (sessionStorage.getItem("lang") || "en");
13-
if (savedLang) {
14-
setLang(savedLang);
15-
}
16-
}, []);
10+
const [lang, setLang] = useState<string>(() => sessionStorage.getItem("lang") || "en");
1711

1812
// Save language on change
1913
useEffect(() => {
20-
sessionStorage.setItem("lang", lang || "en");
14+
sessionStorage.setItem("lang", lang);
2115
}, [lang]);
2216

23-
const changeLanguage = (code) => {
17+
const changeLanguage = (code: string) => {
2418
setLang(code);
2519
};
2620

src/hooks/useLanguage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { useContext } from 'react';
2+
import { LanguageContext } from '../context/LanguageContext';
3+
4+
export const useLanguage = () => {
5+
const context = useContext(LanguageContext);
6+
if (!context) {
7+
throw new Error('useLanguage must be used within a LanguageProvider');
8+
}
9+
return context;
10+
};

src/layouts/MainLayout/BaseLayout.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const BaseLayout: React.FC = () => {
4141
// const startRef = useRef(null);
4242
// const NAV_HEIGHT_OFFSET = 60;
4343

44-
const scrollToSection = (yScrollPosition: number) => {
45-
window.scrollTo({
46-
top: yScrollPosition,
47-
behavior: 'smooth'
48-
});
49-
};
44+
// const scrollToSection = (yScrollPosition: number) => {
45+
// window.scrollTo({
46+
// top: yScrollPosition,
47+
// behavior: 'smooth'
48+
// });
49+
// };
5050

5151
return (
5252
<div className="flex flex-col background">

src/layouts/ProtectedLayOut/ProtectedLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
3838
<div style={{ minHeight: "62vh" }}>
3939
<div className='flex flex items-center justify-center w-100% h-110 flex-col gap-4'>
4040
{/* <FaSpinner className="animate-spin text-4xl text-[#66B0FF]" /> */}
41-
<img src={cdacRoundLogo} className="mr-3 mb-4 size-20 cdacSpinner" />
41+
<img src={cdacRoundLogo} className="mr-3 mb-4 size-20 cdacSpinner" alt="Loading spinner" />
4242
<div className="text-[#000000] text-lg">
4343
Loading...
4444
</div>

src/services/inputInterceptor.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
GLOBAL PHONETIC INTERCEPTOR (SPACE BASED)
33
========================================== */
44

5-
let isApplying: boolean = false;
5+
import type { TransliterateResponse } from "../types/transliterate";
66

7-
let currentLang: string =
8-
sessionStorage.getItem("aicode") || "en";
7+
let isApplying: boolean = false;
98

109
/* ==========================================
1110
FIELD SKIP LOGIC
@@ -106,7 +105,7 @@ function phoneticApiPromise(
106105
})
107106
.then((res: Response) => res.json())
108107

109-
.then((data: any) => {
108+
.then((data: TransliterateResponse) => {
110109

111110
const converted: string | undefined =
112111
data?.result?.[lang];
@@ -238,7 +237,7 @@ export function setPhoneticLanguage(
238237
lang: string
239238
): void {
240239

241-
currentLang = lang;
240+
sessionStorage.setItem("aicode", lang);
242241

243242
sessionStorage.setItem(
244243
"aicode",

src/textTranslation/CustomTranslate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// src/CustomTranslate.tsx
22
import { useEffect } from "react";
3-
import { useLanguage } from "../context/LanguageContext";
3+
import { useLanguage } from "../hooks/useLanguage";
44
import { translateDom } from "./domTranslator.ts";
55
import { observeDom } from "./observeDom.ts";
66

77
const CustomTranslate: React.FC = () => {
8-
const { lang } = useLanguage() as { lang: string };
8+
const { lang } = useLanguage();
99

1010
useEffect(() => {
1111
if (!lang || lang === "en") return;

0 commit comments

Comments
 (0)