Skip to content

Commit

Permalink
Enable plugin:@typescript-eslint/strict-type-checked (#1585)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwade authored Jul 6, 2024
1 parent c230e85 commit ca01e4d
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 22 deletions.
16 changes: 15 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
'plugin:playwright/recommended',

// https://github.com/typescript-eslint/typescript-eslint/milestone/9
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',

'plugin:unicorn/recommended',
Expand Down Expand Up @@ -67,7 +67,21 @@ module.exports = {

'@typescript-eslint/consistent-type-exports': 'warn',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off', // Used for params and in tests
'@typescript-eslint/only-throw-error': 'off', // Remix allows throwing responses
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowAny: false,
allowBoolean: false,
allowNullish: false,
allowNumber: true,
allowRegExp: false,
allowNever: false,
},
],
'@typescript-eslint/switch-exhaustiveness-check': [
'error',
{
Expand Down
4 changes: 3 additions & 1 deletion app/auth/redirect-to-login.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export async function redirectToLogin(
{ onHoldPage }: RedirectToLoginArgs = {},
) {
const { userId } = await getAuth(args);
console.log(`Checking if user is logged in: ${userId}`);

if (!userId) {
console.log('User is not logged in');
throw redirect(`/admin/sign-in?redirect_url=${args.request.url}`);
}

console.log(`User is logged in: ${userId}`);

const user = await createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
}).users.getUser(userId);
Expand Down
1 change: 0 additions & 1 deletion app/components/ShowPlaying/AudioCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export const AudioCanvas: FC<AudioCanvasProps> = ({
if (!ctx) return;

const progress = calculateProgress();
if (progress === undefined) return;

const midX = canvas.width / 2;
const midY = canvas.height / 2;
Expand Down
2 changes: 1 addition & 1 deletion app/components/admin/AudioFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const AudioFileUpload: FC<AudioFileUploadProps> = ({
setIsUploading(false);
}, 100);
})
.catch((error: { reason: string; status?: number }) => {
.catch((error: unknown) => {
console.error(`Audio file upload ${name} failed.`, error);
});

Expand Down
2 changes: 1 addition & 1 deletion app/components/admin/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const FileUpload: FC<FileUploadProps> = ({
setIsUploading(false);
}, 100);
})
.catch((error: { reason: string; status?: number }) => {
.catch((error: unknown) => {
console.error(`File upload ${name} failed.`, error);
});

Expand Down
22 changes: 17 additions & 5 deletions app/forms/show/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const SetForm: FC<SetFormProps> = ({ name, remove, onIsUploadingChanged }) => {
if (isUploading) {
onIsUploadingChanged(isUploading);
return () => {
if (isUploading) onIsUploadingChanged(false);
onIsUploadingChanged(false);
};
}
}, [isUploading, onIsUploadingChanged]);
Expand All @@ -58,7 +58,13 @@ const SetForm: FC<SetFormProps> = ({ name, remove, onIsUploadingChanged }) => {
isUploading={isUploading}
setIsUploading={setIsUploading}
/>
<button type="button" onClick={() => remove()} disabled={isUploading}>
<button
type="button"
onClick={() => {
remove();
}}
disabled={isUploading}
>
Remove set
</button>
</fieldset>
Expand Down Expand Up @@ -148,22 +154,28 @@ const ShowForm: FC<ShowFormProps> = ({
<SetForm
key={set.key}
name={`sets[${index}]`}
remove={() => remove(index)}
remove={() => {
remove(index);
}}
onIsUploadingChanged={onIsUploadingChanged}
/>
))}
<p>
<button
type="button"
onClick={() => push({ id: crypto.randomUUID() })}
onClick={() => {
push({ id: crypto.randomUUID() });
}}
>
Add set
</button>
</p>
<p>
<button
type="button"
onClick={() => navigate(cancelLinkTo)}
onClick={() => {
navigate(cancelLinkTo);
}}
disabled={saveDisabled}
>
Cancel
Expand Down
6 changes: 3 additions & 3 deletions app/routes/$show.[styles.css].ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export const loader = (async ({ params }) => {
});
if (!show) throw notFound();

const backgroundImage = `url(${show.backgroundImageFile?.url})`;
const backgroundImage = `url(${show.backgroundImageFile?.url ?? ''})`;
const backgroundColor = show.backgroundColor;
const backgroundColorLighter = show.backgroundColorSecondary;

return new Response(
`body {
--background-image: ${backgroundImage};
--background-color: ${backgroundColor};
--background-color-lighter: ${backgroundColorLighter};
--background-color: ${backgroundColor ?? 'black'};
--background-color-lighter: ${backgroundColorLighter ?? 'white'};
}`,
{ headers: { 'content-type': 'text/css' } },
);
Expand Down
2 changes: 1 addition & 1 deletion app/sse.server/admin-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getAdminEventTarget() {

declare global {
// eslint-disable-next-line no-var
var adminEventTarget: EventTarget;
var adminEventTarget: EventTarget | undefined;
}

export function dispatchAdminEvent(type: string, data: unknown) {
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { authFile } from './playwright/tests/shared-data';

dotenv.config();

const baseURL = `http://127.0.0.1:${process.env.PORT}`;
const baseURL = `http://127.0.0.1:${process.env.PORT!}`;

/**
* See https://playwright.dev/docs/test-configuration.
Expand Down
2 changes: 2 additions & 0 deletions playwright/ct-tests/useFetcherIgnoreErrors/FetcherTest.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-confusing-void-expression */

import { useCallback, useState } from 'react';

import { useFetcherIgnoreErrors } from '~/hooks/useFetcherIgnoreErrors';
Expand Down
6 changes: 3 additions & 3 deletions playwright/tests/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ test('can change show name and URL', async ({ page, baseURL }) => {
await page.getByLabel('URL:').fill(newShowSlug);
await page.getByLabel('Name:').fill('Edited Show');
await page.getByRole('button', { name: 'Save' }).click();
await expect(page).toHaveURL(`${baseURL}/admin/shows/${adminShowId}`);
await expect(page).toHaveURL(`${baseURL!}/admin/shows/${adminShowId}`);

await page.goto(`/${newShowSlug}`);
await expect(page).toHaveURL(`${baseURL}/${newShowSlug}`);
await expect(page).toHaveURL(`${baseURL!}/${newShowSlug}`);

await page.goto('/admin/shows');
await page
Expand All @@ -40,5 +40,5 @@ test('can change show name and URL', async ({ page, baseURL }) => {
await page.getByRole('link', { name: 'Edit', exact: true }).click();
await page.getByLabel('URL:').fill(adminShowSlug);
await page.getByRole('button', { name: 'Save' }).click();
await expect(page).toHaveURL(`${baseURL}/admin/shows/${adminShowId}`);
await expect(page).toHaveURL(`${baseURL!}/admin/shows/${adminShowId}`);
});
2 changes: 1 addition & 1 deletion playwright/tests/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ setup('authenticate', async ({ page, baseURL }) => {
await page.getByRole('button', { name: 'Continue', exact: true }).click();
await page.getByLabel('Password', { exact: true }).fill('cipassword');
await page.getByRole('button', { name: 'Continue' }).click();
await page.waitForURL(`${baseURL}/admin/shows`);
await page.waitForURL(`${baseURL!}/admin/shows`);

await page.context().storageState({ path: authFile });
});
6 changes: 3 additions & 3 deletions playwright/tests/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('root URL redirects to earliest upcoming show', async ({
}) => {
await page.goto('/');

await expect(page).toHaveURL(`${baseURL}/${process.env.SHOW_SLUG!}`);
await expect(page).toHaveURL(`${baseURL!}/${process.env.SHOW_SLUG!}`);
});

test('not found show redirects to earliest upcoming show', async ({
Expand All @@ -19,7 +19,7 @@ test('not found show redirects to earliest upcoming show', async ({
}) => {
await page.goto('/not-found');

await expect(page).toHaveURL(`${baseURL}/${process.env.SHOW_SLUG!}`);
await expect(page).toHaveURL(`${baseURL!}/${process.env.SHOW_SLUG!}`);
});

test('show URL redirects to path without trailing slash', async ({
Expand All @@ -28,7 +28,7 @@ test('show URL redirects to path without trailing slash', async ({
}) => {
await page.goto(`/${process.env.SHOW_SLUG!}/`);

await expect(page).toHaveURL(`${baseURL}/${process.env.SHOW_SLUG!}`);
await expect(page).toHaveURL(`${baseURL!}/${process.env.SHOW_SLUG!}`);
});

test('plays the default show', async ({ page, browserName }) => {
Expand Down

0 comments on commit ca01e4d

Please sign in to comment.