Skip to content

Commit

Permalink
Merge pull request #945 from CruGlobal/eslint-require-curly-braces
Browse files Browse the repository at this point in the history
[no-Jira] Require curly braces around all blocks
  • Loading branch information
canac authored May 13, 2024
2 parents 3fc96f5 + b9d2fbf commit 685b58d
Show file tree
Hide file tree
Showing 39 changed files with 187 additions and 66 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = {
ignoreMemberSort: false,
},
],
curly: 'error',
eqeqeq: 'error',
'no-console': 'error',
'@typescript-eslint/no-loss-of-precision': 'warn',
Expand Down
3 changes: 2 additions & 1 deletion onesky/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ onesky
fileName: 'translation.json',
})
.then(function (langContent) {
if (!fs.existsSync('public/locales/' + lang.code))
if (!fs.existsSync('public/locales/' + lang.code)) {
fs.promises.mkdir('public/locales/' + lang.code);
}
fs.promises.writeFile(
'public/locales/' + lang.code + '/translation.json',
langContent,
Expand Down
4 changes: 3 additions & 1 deletion pages/accountLists/[accountListId].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const AccountListIdPage = ({
}, []);

useEffect(() => {
if (!modal || dialogOpen) return;
if (!modal || dialogOpen) {
return;
}
switch (modal) {
case 'AddContact':
setSelectedMenuItem(AddMenuItemsEnum.NewContact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export const MailchimpAccount = (
): MailchimpAccountCamel[] => {
// Returning inside an array so I can mock an empty response from GraphQL
// without the test thinking I want it to create custom random test data.
if (!data) return [];
if (!data) {
return [];
}
const attributes = {} as Omit<MailchimpAccountCamel, 'id'>;
Object.keys(data.attributes).forEach((key) => {
attributes[snakeToCamel(key)] = data.attributes[key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const PrayerlettersAccount = (
): PrayerlettersAccountCamel[] => {
// Returning inside an array so I can mock an empty response from GraphQL
// without the test thinking I want it to create custom random test data.
if (!data) return [];
if (!data) {
return [];
}
return [
{
id: data.id,
Expand Down
12 changes: 9 additions & 3 deletions pages/api/auth/[...nextauth].page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ const Auth = (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
user.userID = userInfo.userID;
user.impersonating = userInfo.impersonating;
user.impersonatorApiToken = userInfo.impersonatorApiToken;
if (cookies) res.setHeader('Set-Cookie', cookies);
if (cookies) {
res.setHeader('Set-Cookie', cookies);
}
};

// An API token is not required for the apiOauthSignIn or oktaSignIn mutations
Expand Down Expand Up @@ -266,13 +268,17 @@ const Auth = (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
};
},
redirect({ url, baseUrl }) {
if (url.startsWith(baseUrl)) return url;
if (url.startsWith(baseUrl)) {
return url;
}
if (url === 'signOut' && AUTH_PROVIDER === 'OKTA') {
return `https://signon.okta.com/login/signout?fromURI=${encodeURIComponent(
process.env.OKTA_SIGNOUT_REDIRECT_URL ?? '',
)}`;
}
if (url.startsWith('/')) return new URL(url, baseUrl).toString();
if (url.startsWith('/')) {
return new URL(url, baseUrl).toString();
}
return baseUrl;
},
},
Expand Down
24 changes: 18 additions & 6 deletions pages/api/mpdx-web-handoff.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ const defineRedirectUrl = ({
rest,
}: DefineRedirectUrlProps): string => {
let redirectUrl = `${process.env.SITE_URL}/accountLists/${accountListId}`;
if (path) redirectUrl += path;
if (path) {
redirectUrl += path;
}
if (rest) {
for (const [key, value] of Object.entries(rest)) {
if (typeof value !== 'string') continue;
if (typeof value !== 'string') {
continue;
}
const contactsAndReportsRegex = new RegExp('/contacts|/reports');
if (contactsAndReportsRegex.test(path) && key === 'contactId') {
if (redirectUrl.includes('?')) {
Expand All @@ -30,21 +34,27 @@ const defineRedirectUrl = ({
`/${value}`,
`?${redirectUrl.split('?')[1]}`,
].join('');
} else redirectUrl += `/${value}`;
} else {
redirectUrl += `/${value}`;
}
continue;
} else if (path.includes('/tasks') && key === 'group') {
const typeDetails = taskFiltersTabs.find(
(item) => item.name.toLowerCase() === value.toLowerCase(),
);
if (typeDetails) {
if (!redirectUrl.includes('?')) redirectUrl += '?';
if (!redirectUrl.includes('?')) {
redirectUrl += '?';
}
redirectUrl += `filters=${encodeURIComponent(
JSON.stringify(typeDetails.activeFiltersOptions),
)}`;
continue;
}
}
if (!redirectUrl.includes('?')) redirectUrl += '?';
if (!redirectUrl.includes('?')) {
redirectUrl += '?';
}
redirectUrl += `${key}=${value}&`;
}
}
Expand Down Expand Up @@ -110,7 +120,9 @@ const mpdxWebHandoff = async (
);
}
// Removes duplicates and set cookies
if (cookies) res.setHeader('Set-Cookie', [...new Set(cookies)]);
if (cookies) {
res.setHeader('Set-Cookie', [...new Set(cookies)]);
}
res.redirect(jwtToken ? redirectUrl : `${process.env.SITE_URL}/login`);
} catch (err) {
res.redirect(`${process.env.SITE_URL}/`);
Expand Down
4 changes: 3 additions & 1 deletion pages/login.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const Login = ({
const { appName } = useGetAppSettings();

useEffect(() => {
if (immediateSignIn) signIn(signInAuthProviderId);
if (immediateSignIn) {
signIn(signInAuthProviderId);
}
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export const ContactTags: React.FC<ContactTagsProps> = ({
{ resetForm }: FormikHelpers<{ tagList: string[] & never[] }>,
): Promise<void> => {
resetForm();
if (tagList.length === 0) return;
if (tagList.length === 0) {
return;
}

const { data } = await updateContactTags({
variables: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const TaskDate: React.FC<TaskDateProps> = ({
taskDate,
small,
}) => {
if (!taskDate) return null;
if (!taskDate) {
return null;
}
const locale = useLocale();
const isLate = isComplete ? false : taskDate < DateTime.local();
const showYear = taskDate.year !== DateTime.local().year;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export const ContactTasksTab: React.FC<ContactTasksTabProps> = ({
const { t } = useTranslation();

useEffect(() => {
if (!infiniteListRef.current) return;
if (!infiniteListRef.current) {
return;
}
setInfiniteListRectTop(infiniteListRef.current.getBoundingClientRect().top);
}, [contactId, contactDetailsLoaded]);

Expand Down
4 changes: 3 additions & 1 deletion src/components/Contacts/ContactsContext/ContactsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export const ContactsProvider: React.FC<Props> = ({
}, [isReady, contactId]);

useEffect(() => {
if (userOptionsLoading) return;
if (userOptionsLoading) {
return;
}

setContactFocus(
contactId &&
Expand Down
7 changes: 5 additions & 2 deletions src/components/Contacts/ContactsMap/ContactsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const ContactsMap: React.FC = ({}) => {
const beacon = document.querySelector(
'#beacon-container .BeaconFabButtonFrame',
) as HTMLElement;
if (!beacon) return;
if (!beacon) {
return;
}
beacon.style.setProperty('right', '60px', 'important');
return () => beacon.style.setProperty('right', '20px');
}, []);
Expand All @@ -109,8 +111,9 @@ export const ContactsMap: React.FC = ({}) => {
// Update the map to contain all of the contacts' locations
const bounds = new window.google.maps.LatLngBounds();
data.forEach((contact) => {
if (typeof contact.lat === 'number' && typeof contact.lng === 'number')
if (typeof contact.lat === 'number' && typeof contact.lng === 'number') {
bounds.extend({ lat: contact.lat, lng: contact.lng });
}
});
mapRef.current.fitBounds(bounds);
}, [data, isLoaded, mapRef.current]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ const NotificationMenuItem = ({
},
},
update: (cache) => {
if (!optimisticResponse) return;
if (!optimisticResponse) {
return;
}

const query = {
query: GetNotificationsDocument,
Expand All @@ -102,7 +104,9 @@ const NotificationMenuItem = ({
},
});
}
if (typeof onClick === 'function') onClick();
if (typeof onClick === 'function') {
onClick();
}
};

let message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ const NotificationMenu = ({
},
},
update: (cache) => {
if (!optimisticResponse) return;
if (!optimisticResponse) {
return;
}

const query = {
query: GetNotificationsDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export const FourteenMonthReport: React.FC<Props> = ({
});

const csvData = useMemo(() => {
if (!contacts) return [];
if (!contacts) {
return [];
}

const months =
data?.fourteenMonthReport.currencyGroups[0]?.totals.months ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export const FourteenMonthReportTable: React.FC<
return contact.months.reduce((partialSum, month) => {
return partialSum + month.salaryCurrencyTotal;
}, 0);
} else return 0;
} else {
return 0;
}
}, [contact]);
return (
<TableRow
Expand Down
4 changes: 3 additions & 1 deletion src/components/Settings/Accounts/MergeForm/MergeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export const MergeForm: React.FC<MergeFormProps> = ({ isSpouse }) => {

const onSubmit = async (attributes: FormikSchema) => {
const { selectedAccountId, accept } = attributes;
if (!currentAccount?.id || !accept) return;
if (!currentAccount?.id || !accept) {
return;
}

await mergeAccountList({
variables: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export const AccountListCoachesOrUsers: React.FC<Props> = ({
<Box>
{emails &&
emails.map((email, idx) => {
if (!email?.id) return null;
if (!email?.id) {
return null;
}

return (
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const AccountListInvites: React.FC<Props> = ({
const { enqueueSnackbar } = useSnackbar();

const haneleInviteDelete = async (invite) => {
if (!invite?.id) return;
if (!invite?.id) {
return;
}

await adminDeleteOrganizationInvite({
variables: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export const AccountLists: React.FC = () => {
const pagination = data?.searchOrganizationsAccountLists.pagination;

useEffect(() => {
if (!accountListsRef.current) return;
if (!window.visualViewport?.height) return;
if (!accountListsRef.current || !window.visualViewport?.height) {
return;
}
// 24px for the padding which the parent page has added.
setInfiniteListHeight(
window.visualViewport.height -
Expand Down
5 changes: 3 additions & 2 deletions src/components/Settings/Organization/Contacts/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export const Contacts: React.FC = () => {
const pagination = data?.searchOrganizationsContacts.pagination;

useEffect(() => {
if (!contactsRef.current) return;
if (!window.visualViewport?.height) return;
if (!contactsRef.current || !window.visualViewport?.height) {
return;
}
// 24px for the padding which the parent page has added.
setInfiniteListHeight(
window.visualViewport.height -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const EditGoogleAccountModal: React.FC<EditGoogleAccountModalProps> = ({
const handleToggleCalendarIntegration = async (
enableIntegration: boolean,
) => {
if (!tabSelected) return;
if (!tabSelected) {
return;
}
setIsSubmitting(true);

if (!googleAccountDetails && enableIntegration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ export const EditGoogleIntegrationForm: React.FC<

<StyledBox>
{actvities?.map((activity) => {
if (!activity?.id || !activity?.value) return null;
if (!activity?.id || !activity?.value) {
return null;
}
const activityId = `${activity.value}-Checkbox`;
const isChecked = calendarIntegrations.includes(
activity?.id ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export const OrganizationAddAccountModal: React.FC<
const { getOrganizationOauthUrl: getOauthUrl } = useOauthUrl();

const onSubmit = async (attributes: Partial<OrganizationFormikSchema>) => {
if (!attributes?.selectedOrganization) return;
if (!attributes?.selectedOrganization) {
return;
}
const { apiClass, oauth, id } = attributes.selectedOrganization;
const type = getOrganizationType(apiClass, oauth);

Expand All @@ -134,7 +136,9 @@ export const OrganizationAddAccountModal: React.FC<
return;
}

if (!accountListId) return;
if (!accountListId) {
return;
}

const createAccountAttributes: {
organizationId: string;
Expand Down
Loading

0 comments on commit 685b58d

Please sign in to comment.