Skip to content

Commit

Permalink
Typescript eslint v6 (#4298)
Browse files Browse the repository at this point in the history
* feat: lint with latest typescript eslint v6

* feat: lint with latest typescript eslint v6

* feat: lint with latest typescript eslint v6
  • Loading branch information
belgattitude authored Aug 25, 2023
1 parent bf87960 commit c32aeeb
Show file tree
Hide file tree
Showing 68 changed files with 2,192 additions and 967 deletions.
14 changes: 14 additions & 0 deletions .changeset/fair-dolls-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@your-org/eslint-config-bases": patch
"@your-org/db-main-prisma": patch
"@your-org/api-gateway": patch
"@your-org/common-i18n": patch
"@your-org/core-lib": patch
"@your-org/ts-utils": patch
"nextjs-app": patch
"@your-org/ui-lib": patch
"remix-app": patch
"vite-app": patch
---

Lint with typescript eslint v6
2 changes: 1 addition & 1 deletion .ncurc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# @link https://github.com/raineorshine/npm-check-updates

# Add here exclusions on packages if any
reject: ['@typescript-eslint/eslint-plugin', '@typescript-eslint/parser']
reject: []
2 changes: 1 addition & 1 deletion apps/nextjs-app/.escheckrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ecmaVersion": "es2019",
"ecmaVersion": "es2020",
"module": false,
"files": "./.next/static/chunks/**/*.js"
}
2 changes: 1 addition & 1 deletion apps/nextjs-app/config/tests/I18nextTestStubProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { I18nNamespace } from '@/lib/i18n/I18nNamespace.types';
* @link {https://react.i18next.com/misc/testing}
*/
// eslint-disable-next-line import/no-named-as-default-member
i18next.use(initReactI18next).init({
void i18next.use(initReactI18next).init({
lng: 'en',
fallbackLng: 'en',
ns: ['common'],
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs-app/config/tests/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ afterEach(() => {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const customRender = (ui: ReactElement, options?: any) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
render(ui, {
wrapper: AppTestProviders,
...options,
Expand Down
6 changes: 4 additions & 2 deletions apps/nextjs-app/e2e/api/gateway/graphql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ test('should call the mesh for random cats', async ({ request }) => {
query: `{ getRandomFact { fact, length } }`,
},
});
expect(resp).toBeOK();
await expect(resp).toBeOK();
const headers = resp.headers();
expect(headers['content-type']).toEqual('application/json; charset=utf-8');
const json = await resp.json();
const json = (await resp.json()) as {
data?: { getRandomFact?: { fact: string; length: string } };
};
const { fact, length } = json?.data?.getRandomFact ?? {};
expect(isNonEmptyString(fact)).toBeTruthy();
expect(isParsableNumeric(length)).toBeTruthy();
Expand Down
6 changes: 4 additions & 2 deletions apps/nextjs-app/e2e/api/graphql/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ test('should call the getUser graphql endpoint', async ({ request }) => {
query: `query { getUser(id: 1) { email, id } }`,
},
});
expect(resp).toBeOK();
await expect(resp).toBeOK();
const headers = resp.headers();
expect(headers['content-type']).toEqual('application/json; charset=utf-8');
const json = await resp.json();
const json = (await resp.json()) as {
data?: { getUser?: { id: string; email: string } };
};
const { id, email } = json?.data?.getUser ?? {};
expect(isNonEmptyString(email)).toBeTruthy();
expect(isParsableNumeric(id)).toBeTruthy();
Expand Down
8 changes: 4 additions & 4 deletions apps/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dev": "next",
"fix-all-files": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --fix",
"flamegraph-home": "npx 0x --output-dir './.debug/flamegraph/{pid}.0x' --on-port 'autocannon http://localhost:$PORT --duration 20' -- node ../../node_modules/.bin/next start",
"lint": "cross-env TIMING=1 eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --cache --cache-location ../../.cache/eslint/nextjs-app.eslintcache",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --cache --cache-location ../../.cache/eslint/nextjs-app.eslintcache",
"start": "next start",
"test": "yarn test-unit",
"test-e2e": "cross-env E2E_WEBSERVER_MODE=BUILD_AND_START playwright test",
Expand All @@ -35,7 +35,7 @@
},
"browserslist": {
"production": [
">0.3%",
">1%",
"not ie 11",
"not dead",
"not op_mini all"
Expand Down Expand Up @@ -128,7 +128,7 @@
"@testing-library/user-event": "14.4.3",
"@types/cors": "2.8.13",
"@types/jest": "29.5.4",
"@types/node": "20.4.5",
"@types/node": "20.5.6",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"@types/react-test-renderer": "18.0.0",
Expand All @@ -141,7 +141,7 @@
"dotenv-flow": "3.2.0",
"dotenv-flow-cli": "1.0.0",
"es-check": "7.1.1",
"eslint": "8.47.0",
"eslint": "8.48.0",
"eslint-config-next": "13.4.19",
"eslint-plugin-tailwindcss": "3.13.0",
"get-tsconfig": "4.7.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sentryInit({
console.log('Sentry event', event);
console.log('Sentry hint', hint);
}
return event;
return Promise.resolve(event);
},
ignoreErrors: [
/**
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ sentryInit({
console.log('Sentry event', event);
console.log('Sentry hint', hint);
}
return event;
return Promise.resolve(event);
},
});
4 changes: 2 additions & 2 deletions apps/nextjs-app/src/backend/api/rest/post-repository.ssr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpInternalServerError, HttpNotFound } from '@httpx/exception';
import type { PrismaClientDbMain } from '@your-org/db-main-prisma';
import { assertNonEmptyString, type UnPromisify } from '@your-org/ts-utils';
import { assertIsPresent, type UnPromisify } from '@your-org/ts-utils';

export type GetPosts = UnPromisify<
ReturnType<(typeof PostRepositorySsr)['prototype']['getPosts']>
Expand All @@ -18,7 +18,7 @@ export class PostRepositorySsr {
where: { id: postId },
include: { author: true },
});
assertNonEmptyString(
assertIsPresent(
post,
() => new HttpNotFound(`Post ${postId} can't be found`)
);
Expand Down
3 changes: 1 addition & 2 deletions apps/nextjs-app/src/backend/config/cors.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const corsAllowedOrigins: string[] = [
];

export const getCorsWhitelistOriginRegexp = (allowedOrigins?: string[]) => {
const origins =
allowedOrigins !== undefined ? allowedOrigins : corsAllowedOrigins;
const origins = allowedOrigins ?? corsAllowedOrigins;
return new RegExp(
`^https?://(([^/])+\\.)?(${origins.join('|')})(\\:\\d+)?$`,
'i'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class SearchPoemsQuery {
return this.mapToResult(await this.searchPoems(params));
};

private mapToResult = async (rows: SearchPoems) => {
private mapToResult = (rows: SearchPoems) => {
return rows.map((poem) => {
const { createdAt, updatedAt, keywords, ...rest } = poem;
return {
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/src/backend/graphql/graphqlSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ builder.queryType({
args: {
name: t.arg.string(),
},
resolve: (parent, { name }) => `hello, ${name || 'World'}`,
resolve: (parent, { name }) => `hello, ${name ?? 'World'}`,
}),
getUser: t.prismaField({
type: 'User',
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs-app/src/backend/i18n/getServerTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
import type { SSRConfig, UserConfig } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import {
type I18nActiveNamespaces,
type I18nNamespace,
import type {
I18nActiveNamespaces,
I18nNamespace,
} from '@/lib/i18n/I18nNamespace.types';
import nextI18nextConfig from '../../../next-i18next.config.mjs';

Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs-app/src/config/api-fetcher.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const apiFetcher = ofetch.create({
*/
keepalive: true,

/*
async onRequest({ request, options }) {
// Nothing yet
},
Expand All @@ -30,5 +31,5 @@ export const apiFetcher = ofetch.create({
async onResponseError({ request, response, options }) {
// Nothing yet
},
}, */
});
13 changes: 7 additions & 6 deletions apps/nextjs-app/src/config/next-auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const nextAuthConfig: NextAuthOptions = {
email,
password
);
if (staticAllowedDemoAdminUser) return staticAllowedDemoAdminUser;
if (staticAllowedDemoAdminUser)
return Promise.resolve(staticAllowedDemoAdminUser);

throw createHttpUnauthorized('Invalid credentials');
},
Expand Down Expand Up @@ -96,17 +97,17 @@ export const nextAuthConfig: NextAuthOptions = {
},
*/
async redirect({ url, baseUrl }) {
return url.startsWith(baseUrl) ? url : baseUrl;
return Promise.resolve(url.startsWith(baseUrl) ? url : baseUrl);
},
// async session({ session, token, user }) {
async session({ session, token }) {
return {
return Promise.resolve({
...session,
user: {
...session.user,
role: token.role as string,
role: token.role,
},
};
});
},
async jwt({ token, user, trigger }) {
if (trigger === 'signUp') {
Expand All @@ -115,7 +116,7 @@ export const nextAuthConfig: NextAuthOptions = {
if (user) {
token.role = user.role;
}
return token;
return Promise.resolve(token);
},
},
pages: {
Expand Down
3 changes: 1 addition & 2 deletions apps/nextjs-app/src/features/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ export const LoginForm: FC<Props> = (props) => {
});
const {
ok = false,
url,
status = 500,
error = 'Server or network Error',
} = result ?? {};

if (ok) {
router.push(redirectToPage);
await router.push(redirectToPage);
} else {
setError(`${status} - ${error}`);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/src/features/auth/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { FC } from 'react';
import { authConfig } from '@/features/auth/auth.config';
import { LoginForm } from '@/features/auth/components/LoginForm';

export const LoginPage: FC = (props) => {
export const LoginPage: FC = () => {
const { t } = useTranslation(authConfig.i18nNamespaces);
const redirectToPage = '/admin';
return (
Expand Down
3 changes: 0 additions & 3 deletions apps/nextjs-app/src/features/home/blocks/hero/HeroBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import Image from 'next/image';
import { useTranslation } from 'next-i18next';
import type { FC } from 'react';

type Props = {
children?: never;
};

export const HeroBlock: FC<Props> = () => {
const { t } = useTranslation(['home', 'common']);

return (
<section className="body-font text-gray-600">
<div className="container mx-auto flex flex-col items-center px-5 py-24 md:flex-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ErrorPage } from '@/features/system/pages';
import { render, screen } from '@/test-utils';

describe('errorPage test', () => {
it('should contain error passed status code', async () => {
it('should contain error passed status code', () => {
render(<ErrorPage statusCode={500} />);
expect(screen.getByTestId('error-status-code')).toHaveTextContent('500');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NotFoundPage } from '@/features/system/pages';
import { render, screen } from '@/test-utils';

describe('notFoundPage test', () => {
it('should contain passed title', async () => {
it('should contain passed title', () => {
render(<NotFoundPage title={'404 - Not found'} />);
expect(screen.getByTestId('not-found-title')).toHaveTextContent(
'404 - Not found'
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs-app/src/layouts/admin/AdminSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { TextAvatar } from '@/components/avatar/TextAvatar';

export const AdminSidebar: FC = () => {
// @todo better to use middleware or https://next-auth.js.org/getting-started/client#custom-client-session-handling
const { data: session, status } = useSession();
// const { data: session, status } = useSession();
const { data: session } = useSession();
const user = session?.user;
return (
<div className="flex flex-row sm:gap-10">
Expand Down
2 changes: 0 additions & 2 deletions apps/nextjs-app/src/layouts/main/MainFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const BgWaved = styled(FooterWaves)`
`;

const FooterCtn = styled.footer`
//background-image: url('/images/layout/footer-waves.svg');
//background-image: url(${() => FooterWaves.url});
display: grid;
.content,
.bgImage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@/test-utils';
import { MainLayout } from '../MainLayout';

describe('main layout tests', () => {
it('should render children', async () => {
it('should render children', () => {
render(
<MainLayout>
<div role="article">Hello</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs-app/src/lib/factory/ky.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Props = {
request: Request,
options: NormalizedOptions,
response: Response
) => void;
) => Promise<void>;
};

export class KyFactory {
Expand All @@ -22,7 +22,7 @@ export class KyFactory {
[401, 403].includes(status) &&
this.props.onAuthFailure !== undefined
) {
this.props.onAuthFailure(request, options, response);
await this.props.onAuthFailure(request, options, response);
}
return response;
},
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/src/lib/i18n/getSortedI18nNamespaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type I18nActiveNamespaces } from '@/lib/i18n/I18nNamespace.types';
import type { I18nActiveNamespaces } from '@/lib/i18n/I18nNamespace.types';

/**
* Ensure that the i18nNamespaces are sorted alphabetically when passed in feature configs.
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs-app/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type MyAppProps = AppProps & {
* @link https://nextjs.org/docs/advanced-features/custom-app
*/
const MyApp = (appProps: MyAppProps) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { Component, pageProps, emotionCache } = appProps;
return (
<AppProviders emotionCache={emotionCache}>
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs-app/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ MyDocument.getInitialProps = async (ctx) => {
// You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
// However, be aware that it can have global side effects.
const cache = createEmotionCache();
// eslint-disable-next-line @typescript-eslint/unbound-method
const { extractCriticalToChunks } = createEmotionServer(cache);

ctx.renderPage = () =>
Expand Down
5 changes: 3 additions & 2 deletions apps/nextjs-app/src/pages/_monitor/sentry/csr-page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState, type FC } from 'react';

const getAsyncError = async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/require-await
const getAsyncError = async (): Promise<never> => {
throw new Error(
'Error purposely crafted for monitoring sentry (/pages/_monitor/sentry/csr-page.tsx)'
);
Expand All @@ -10,7 +11,7 @@ const MonitorSentryCsrRoute: FC = () => {
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
getAsyncError().catch((err) => setError(err));
getAsyncError().catch((err) => setError(err as Error));
}, []);

if (error) {
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs-app/src/pages/_monitor/sentry/ssr-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default function MonitorSentrySsrRoute(
*/
export const getServerSideProps: GetServerSideProps<Props> = async (
_context
) => {
// eslint-disable-next-line @typescript-eslint/require-await
): Promise<never> => {
throw new Error(
'Error purposely crafted for monitoring sentry (/pages/_monitor/sentry/ssr-page.tsx)'
);
Expand Down
Loading

2 comments on commit c32aeeb

@vercel
Copy link

@vercel vercel bot commented on c32aeeb Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-nextjs-app – ./apps/nextjs-app

monorepo-nextjs-app-git-main-belgattitude.vercel.app
monorepo-nextjs-app-belgattitude.vercel.app
monorepo-nextjs-app.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c32aeeb Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-vite-app – ./apps/vite-app

monorepo-vite-app-belgattitude.vercel.app
monorepo-vite-app.vercel.app
monorepo-vite-app-git-main-belgattitude.vercel.app

Please sign in to comment.