Skip to content

Commit

Permalink
refactor(core): ARC-69 ignore unexpected console error sonar smells
Browse files Browse the repository at this point in the history
ignore code smells related to unexpected
console statement whil error handling
  • Loading branch information
sf-sahil-jassal committed Dec 14, 2023
1 parent 82c6696 commit c309ff2
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 30 deletions.
12 changes: 7 additions & 5 deletions configGenerator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-env node */
import dotenv from 'dotenv';
import fs from 'fs';
import path, {dirname} from 'path';
import yargs from 'yargs';
import dotenv from 'dotenv';
import {fileURLToPath} from 'url';
import yargs from 'yargs';

// Get the directory name and filename
const currentDir = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -51,12 +51,14 @@ try {
// Write the substituted data to config.json
try {
fs.writeFileSync(currentConfigFilePath, substitutedData, 'utf-8');
console.log('Configuration file written in current directory.');
// eslint-disable-next-line no-console
console.log('Configuration file written in current directory.'); // NOSONAR

// Copy config.json to the public directory
try {
fs.copyFileSync(currentConfigFilePath, outConfigFilePath);
console.log('Configuration file copied to public directory.');
// eslint-disable-next-line no-console
console.log('Configuration file copied to public directory.'); // NOSONAR
} catch (copyError) {
handleError(`Error copying config file: ${copyError.message}`);
}
Expand All @@ -68,6 +70,6 @@ try {
}

function handleError(message) {
console.error(message);
console.error(message); // NOSONAR
process.exit(1);
}
6 changes: 4 additions & 2 deletions src/Components/Forms/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {Form as FormikForm, Formik} from 'formik';
import {ForwardedRef, forwardRef, ReactNode} from 'react';
import * as yup from 'yup';

type AnyObject = Record<string, any>; // NOSONAR

interface Props {
initialValues: any;
onSubmit: any;
initialValues: AnyObject;
onSubmit: (...args: any) => void; // NOSONAR
validationSchema?: ReturnType<typeof yup.object>;
id?: string;
enableReinitialize?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {MemoryRouter, RouteObject, useRoutes} from 'react-router-dom';
import {ProtectedRouteWrapper} from './ProtectedRouteWrapper';

interface TestAppProps {
isAuthorized: (...args: any[]) => boolean;
isAuthorized: (...args: any[]) => boolean; // NOSONAR
}

const TestApp: React.FC<TestAppProps> = ({isAuthorized}) => {
Expand All @@ -22,7 +22,8 @@ const TestApp: React.FC<TestAppProps> = ({isAuthorized}) => {
),
},
];
return useRoutes(routesConfig);
const routes = useRoutes(routesConfig);
return <>{routes}</>;
};

describe('ProtectedRouteWrapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Navigate, useLocation} from 'react-router-dom';

export interface ProtectedRouteWrapperProps {
children: JSX.Element;
isAuthorized?: (...args: any[]) => boolean;
isAuthorized?: (...args: any[]) => boolean; // NOSONAR
}

/**
Expand All @@ -20,5 +20,5 @@ export const ProtectedRouteWrapper = ({
children,
}: ProtectedRouteWrapperProps) => {
const location = useLocation();
return isAuthorized() ? children : <Navigate to={'/login'} state={{from: location}} replace />;
return <>{isAuthorized() ? children : <Navigate to={'/login'} state={{from: location}} replace />}</>;
};
16 changes: 8 additions & 8 deletions src/Components/TransferList/TransferList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function intersection(arr1: {label: string; value: string}[], arr2: {label: stri
return arr1.filter(item1 => arr2.some(item2 => item2.value === item1.value));
}

const IconButton = ({text, ...rest}: {text: ReactNode; onClick: () => void; disabled: boolean}) => (
<Button {...rest}>
<Box component="span" sx={{transform: {md: 'rotate(0deg)', xs: 'rotate(90deg)'}}}>
{text}
</Box>
</Button>
);

const TransferList: React.FC<TransferListProps> = ({
left = [],
setLeft,
Expand Down Expand Up @@ -87,14 +95,6 @@ const TransferList: React.FC<TransferListProps> = ({
setChecked([]);
};

const IconButton = ({text, ...rest}: {text: ReactNode; onClick: () => void; disabled: boolean}) => (
<Button {...rest}>
<Box component="span" sx={{transform: {md: 'rotate(0deg)', xs: 'rotate(90deg)'}}}>
{text}
</Box>
</Button>
);

const customList = ({
items,
title,
Expand Down
9 changes: 5 additions & 4 deletions src/Helpers/authorizationFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import useAuth from 'Hooks/useAuth';

export interface AnyFunctions {
[key: string]: (...args: any[]) => boolean; // NOSONAR
}

const IsAuthenticated = () => {
// NOSONAR typescript:S100
const {isLoggedIn} = useAuth();
return !!isLoggedIn;
};

export interface AnyFunctions {
[key: string]: (...args: any[]) => boolean; // NOSONAR
}

export const authorizationFunctions: AnyFunctions = {
isAuthenticated: IsAuthenticated,
};
2 changes: 1 addition & 1 deletion src/Hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function useAuth() {
await logoutApi(refreshToken).unwrap();
dispatch(unsetCredentials());
} catch (err) {
console.error(err);
console.error(err); // NOSONAR
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/Hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const useLocalStorage = <T>(key: string, initialValue: T): [T, (value: T | ((pre
const item = window.localStorage.getItem(key);
return item ? (JSON.parse(item) as T) : initialValue;
} catch (error) {
console.error('error while setting useLocalStorage initial value = ', error);
console.error('error while setting useLocalStorage initial value = ', error); // NOSONAR
return initialValue;
}
});
Expand All @@ -21,7 +21,7 @@ const useLocalStorage = <T>(key: string, initialValue: T): [T, (value: T | ((pre
window.localStorage.setItem(key, JSON.stringify(valueToStore));
}
} catch (error) {
console.error('error while setting useLocalStorage value = ', error);
console.error('error while setting useLocalStorage value = ', error); // NOSONAR
}
};
return [storedValue, setValue];
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class ErrorBoundary extends React.Component<Props, State> {

static getDerivedStateFromError(error: Error) {
// Update state so the next render will show the fallback UI.
console.error(error);
console.error(error); // NOSONAR
return {hasError: true};
}

componentDidCatch(error: Error, errorInfo: ErrorInfo) {
// You can also log the error to an error reporting service
console.error(error, errorInfo);
console.error(error, errorInfo); // NOSONAR
}

render(): ReactNode {
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OnlineStatusProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const checkOnlineStatus = async () => {
return true;
} catch (error) {
// Error Log
console.error(error);
console.error(error); // NOSONAR

// This can be because of request timed out
// so we abort the request for any case
Expand Down
3 changes: 2 additions & 1 deletion src/redux/apiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const baseQueryWithReauth: BaseQueryFn<string | FetchArgs, unknown, FetchBaseQue

if (result.error && result.error.status === RESULT_ERROR_STATUS) {
// try to get a new token
console.log('sending refresh token....');
// eslint-disable-next-line no-console
console.log('sending refresh token....'); // NOSONAR
const refreshResult = await baseQuery(
{
url: '/auth/token-refresh',
Expand Down

0 comments on commit c309ff2

Please sign in to comment.