Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit ffd8d87

Browse files
committed
chore(eslint): enable strict rule set form @typescript-eslint
- fix linter errors - remove no-type-assertion plugin
1 parent 8632e77 commit ffd8d87

36 files changed

+124
-93
lines changed

.eslintrc.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module.exports = {
99
'eslint:recommended',
1010
'plugin:@typescript-eslint/eslint-recommended',
1111
'plugin:@typescript-eslint/recommended',
12+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
13+
'plugin:@typescript-eslint/strict',
1214
'plugin:react/recommended',
1315
'plugin:react/jsx-runtime',
1416
'plugin:import/recommended',
@@ -31,6 +33,10 @@ module.exports = {
3133
},
3234
],
3335
parser: '@typescript-eslint/parser',
36+
parserOptions: {
37+
project: ['./tsconfig.json'],
38+
tsconfigRootDir: __dirname,
39+
},
3440
plugins: [
3541
'@typescript-eslint',
3642
'jsx-a11y',
@@ -39,11 +45,18 @@ module.exports = {
3945
'sonarjs',
4046
'sort-keys-fix',
4147
'typescript-sort-keys',
42-
'no-type-assertion',
4348
// HINT: prettier must be the last plugin to work
4449
'prettier',
4550
],
4651
rules: {
52+
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
53+
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
54+
'@typescript-eslint/no-misused-promises': [
55+
'error',
56+
{
57+
checksVoidReturn: false,
58+
},
59+
],
4760
'@typescript-eslint/no-unused-vars': [
4861
'warn',
4962
{
@@ -90,7 +103,6 @@ module.exports = {
90103
],
91104
'import/prefer-default-export': 'off',
92105
'no-console': ['warn', { allow: ['warn', 'error'] }],
93-
'no-type-assertion/no-type-assertion': 'error',
94106
'prettier/prettier': 'error',
95107
'react/jsx-sort-default-props': 'error',
96108
'react/jsx-sort-props': [

.lintstagedrc.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module.exports = {
22
'*.css': ['stylelint --fix', 'git add --force'],
3-
'*.{js,jsx,ts,tsx}': [
4-
// Extend rule levels based on .eslintrc.js
5-
"eslint --fix --rule '@typescript-eslint/no-unused-vars: error' --rule 'no-console: error'",
3+
'*.{js,jsx}': [
4+
// Extend rule set of .eslintrc.js with 'no-console' and 'no-unused-vars'
5+
"eslint --fix --rule 'no-console: [error, { allow: [warn, error] }]' --rule 'no-unused-vars: error'",
6+
'git add --force',
7+
],
8+
'*.{ts,tsx}': [
9+
// Extend rule set of .eslintrc.js with 'no-console' and '@typescript-eslint/no-unused-vars'
10+
"eslint --fix --rule 'no-console: [error, { allow: [warn, error] }]' --rule '@typescript-eslint/no-unused-vars: [error, { argsIgnorePattern: ^_, caughtErrorsIgnorePattern: ^_, varsIgnorePattern: ^_, }]'",
611
'git add --force',
712
],
813
'*.json': ['prettier --write', 'git add --force'],

src/auth.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
AuthenticationResult,
2+
type AuthenticationResult,
33
BrowserAuthError,
44
type Configuration,
5-
EventMessage,
5+
type EventMessage,
66
EventType,
77
InteractionRequiredAuthError,
88
PublicClientApplication,
@@ -44,15 +44,14 @@ msalInstance.enableAccountStorageEvents();
4444

4545
msalInstance.addEventCallback((event: EventMessage) => {
4646
if (event.eventType === EventType.LOGIN_SUCCESS && event.payload) {
47-
// eslint-disable-next-line no-type-assertion/no-type-assertion
4847
const payload = event.payload as AuthenticationResult;
4948
const account = payload.account;
5049
msalInstance.setActiveAccount(account);
5150
}
5251
});
5352

5453
export const aquireTokenMsal = async () => {
55-
const account = msalInstance.getActiveAccount() || undefined;
54+
const account = msalInstance.getActiveAccount() ?? undefined;
5655

5756
return msalInstance
5857
.acquireTokenSilent({
@@ -70,8 +69,8 @@ export const aquireTokenMsal = async () => {
7069
account,
7170
scopes: ['User.Read'],
7271
})
73-
.catch((errorSsoSilent: Error) => {
74-
msalInstance.acquireTokenRedirect({
72+
.catch(async (errorSsoSilent: Error) => {
73+
await msalInstance.acquireTokenRedirect({
7574
account,
7675
prompt: 'select_account',
7776
scopes: ['User.Read'],

src/components/Avatar/Avatar.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Avatar } from './Avatar';
1111
const { mail } = MOCK_RESPONSE_MICROSOFT_GRAPH_GET_ME;
1212

1313
test.beforeEach(async ({ page }) => {
14-
page.route(`**/v1.0/users/${mail}/photos/64x64/$value`, async (route) => {
14+
await page.route(`**/v1.0/users/${mail}/photos/64x64/$value`, async (route) => {
1515
return route.fulfill({
1616
body: Buffer.from(MOCK_RESPONST_MICROSOFT_GRAPH_GET_USERS_PHOTOS_64_VALUE, 'base64'),
1717
contentType: 'image/jpeg',

src/components/Avatar/Avatar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const Avatar = ({ id, expand, ...rest }: AvatarProps) => {
1818

1919
return (
2020
<IonAvatar className={expand ? styles.expand : ''} {...rest}>
21-
<img alt={`avatar-${id}`} src={data} />
21+
<img alt={`avatar-${id ?? 'default'}`} src={data} />
2222
</IonAvatar>
2323
);
2424
};

src/components/ButtonLogIn/ButtonLogIn.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export const ButtonLogIn = ({ prompt }: TProps) => {
1919
* see: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-js-prompt-behavior
2020
*/
2121
const { searchParams } = useSearchParams();
22-
const promptBehavior = useMemo(() => (searchParams?.prompt || prompt) ?? undefined, [prompt, searchParams]);
22+
const promptBehavior = useMemo(() => (searchParams.prompt || prompt) ?? undefined, [prompt, searchParams]);
2323

24-
const handleClickLoginRedirect = useCallback(() => {
25-
instance.loginRedirect({
24+
const handleClickLoginRedirect = useCallback(async () => {
25+
await instance.loginRedirect({
2626
...REDIRECT_REQUEST,
2727
prompt: promptBehavior,
2828
});

src/components/ButtonLogOut/ItemLogOut.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export const ItemLogOut = () => {
99

1010
const isDisabled = useMemo(() => inProgress === InteractionStatus.Logout, [inProgress]);
1111

12-
const handleClickLoginRedirect = useCallback(() => {
13-
instance.logoutRedirect();
12+
const handleClickLoginRedirect = useCallback(async () => {
13+
await instance.logoutRedirect();
1414
}, [instance]);
1515

1616
return (

src/components/ButtonReset/ItemResetUserState.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { IonItem, IonLabel } from '@ionic/react';
33
import { persistor } from '../../store';
44

55
export const ItemResetUserState = ({ label = 'Reset', labelColor = 'danger', ...rest }: TProps) => {
6-
const handleClick = useCallback(() => {
7-
persistor.purge();
6+
const handleClick = useCallback(async () => {
7+
await persistor.purge();
88
}, []);
99

1010
return (

src/components/Greeter/Greeter.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { MOCK_RESPONSE_MICROSOFT_GRAPH_GET_ME } from '../../utils/test/api.me.mo
55
import { MsalMock } from '../../utils/test/MsalMock';
66
import { Greeter } from './Greeter';
77

8-
test.beforeEach(({ page }) => {
9-
page.route('**/v1.0/me/', (route) => {
8+
test.beforeEach(async ({ page }) => {
9+
await page.route('**/v1.0/me/', (route) => {
1010
return route.fulfill({
1111
body: JSON.stringify(MOCK_RESPONSE_MICROSOFT_GRAPH_GET_ME),
1212
contentType: 'application/json',

src/components/Message/MessageAccessInformation.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MessageAccessInformation } from './MessageAccessInformation';
44
test.describe('MessageAccessInformation', () => {
55
test('renders', async ({ mount }) => {
66
const component = await mount(<MessageAccessInformation />);
7-
await expect(component).toBeTruthy();
7+
expect(component).toBeTruthy();
88
});
99

1010
test('shows text', async ({ mount }) => {
@@ -27,7 +27,7 @@ test.describe('MessageAccessInformation', () => {
2727
component.getByRole('link', { name: 'Microsoft Docs' }).click(), // Opens a new tab
2828
]);
2929
await newPage.waitForLoadState();
30-
await expect(await newPage.title()).toBeTruthy();
30+
expect(await newPage.title()).toBeTruthy();
3131
});
3232

3333
test('click on link to navigate to microsoft docs about app roles', async ({ context, mount }) => {
@@ -41,6 +41,6 @@ test.describe('MessageAccessInformation', () => {
4141
component.getByRole('link', { name: 'How to add app roles in Azure AD apps' }).click(), // Opens a new tab
4242
]);
4343
await newPage.waitForLoadState();
44-
await expect(await newPage.title()).toBeTruthy();
44+
expect(await newPage.title()).toBeTruthy();
4545
});
4646
});

0 commit comments

Comments
 (0)