Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ESlint and TS issues #275

Merged
merged 9 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion template/apps/api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "import"],
plugins: ["@typescript-eslint", "import", "tsc"],
extends: [
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
Expand All @@ -17,6 +17,9 @@ module.exports = {
tsconfigRootDir: __dirname,
},
rules: {
'tsc/config': [2, {
configFile: 'tsconfig.json'
}],
'arrow-body-style': 0,
'no-underscore-dangle': 0,
'function-paren-newline': 1,
Expand Down
6 changes: 3 additions & 3 deletions template/apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"test": "run-s test:**",
"test:lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix",
"test:lint": "tsc --noEmit && eslint \"**/*.ts\" --fix",
"test:unit": "jest --runInBand -c ./jest.config.ts --collectCoverage false",
"dev": "NODE_ENV=development APP_ENV=development ts-node-dev --respawn --transpile-only src/app.ts",
"start": "ts-node src/app.ts",
Expand Down Expand Up @@ -66,7 +66,6 @@
"@types/koa-helmet": "6.0.4",
"@types/koa-logger": "3.1.2",
"@types/koa-mount": "4.0.2",
"@types/koa-qs": "2.0.0",
"@types/koa-ratelimit": "5.0.0",
"@types/koa__cors": "3.3.1",
"@types/koa__multer": "2.0.4",
Expand All @@ -82,6 +81,7 @@
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-tsc": "2.0.0",
"jest": "29.5.0",
"lint-staged": "13.2.0",
"mongodb-memory-server": "8.12.0",
Expand All @@ -93,7 +93,7 @@
"typescript": "4.9.5"
},
"lint-staged": {
"*.{js,ts}": [
"*.ts": [
"eslint --fix"
]
}
Expand Down
2 changes: 1 addition & 1 deletion template/apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const initKoa = () => {

app.use(cors({ credentials: true }));
app.use(helmet());
qs(app as any);
qs(app);
app.use(bodyParser({
enableTypes: ['json', 'form', 'text'],
onerror: (err: Error, ctx) => {
Expand Down
9 changes: 9 additions & 0 deletions template/apps/api/src/koa-qs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AppKoa from 'types';

declare namespace koaQs {
type ParseMode = 'extended' | 'strict' | 'first';
}

declare function koaQs(app: AppKoa, mode?: koaQs.ParseMode): AppKoa;

export = koaQs;
2 changes: 1 addition & 1 deletion template/apps/api/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getFormat = (isDev: boolean) => {
};

const createConsoleLogger = (isDev: boolean) => {
const transports: any[] = [
const transports: winston.transport[] = [
new winston.transports.Console({
level: isDev ? 'debug' : 'info',
stderrLevels: [
Expand Down
2 changes: 1 addition & 1 deletion template/apps/api/src/migrator/migrations/1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ migration.migrate = async () => {
{ $set: { isEmailVerified: false } },
);

await promiseUtil.promiseLimit(userIds, 50, updateFn);
await promiseUtil.promiseLimit<string>(userIds, 50, updateFn);
};

export default migration;
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
import { AppKoaContext, Next } from 'types';
import { AppKoaContext, Next, ValidationErrors } from 'types';

import logger from 'logger';

interface CustomError extends Error {
status?: number;
clientErrors?: ValidationErrors;
}

const routeErrorHandler = async (ctx: AppKoaContext, next: Next) => {
try {
await next();
} catch (error: any) {
const clientError = error.clientErrors;
const serverError = { global: error.message };
} catch (error) {
if (typeof error === 'object' && error !== null && 'message' in error) {
const typedError = error as CustomError;

const errors = clientError || serverError;
logger.error(errors);
const clientError = typedError.clientErrors;
const serverError = { global: typedError.message || 'Unknown error' };

if (serverError && process.env.APP_ENV === 'production') {
serverError.global = 'Something went wrong';
}
const errors = clientError || serverError;
logger.error(errors);

if (serverError && process.env.APP_ENV === 'production') {
serverError.global = 'Something went wrong';
}

ctx.status = error.status || 500;
ctx.body = { errors };
ctx.status = typedError.status || 500;
ctx.body = { errors };
} else {
logger.error(`An unexpected error type was caught. Error: ${JSON.stringify(error)}`);

ctx.status = 500;
ctx.body = { errors: { global: 'An unexpected error occurred' } };
}
}
};

Expand Down
16 changes: 11 additions & 5 deletions template/apps/api/src/utils/promise.util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import _ from 'lodash';

const promiseLimit = (documents: unknown[], limit: number, operator: (doc: any) => any): Promise<void> => {
const promiseLimit = <T>(
documents: T[],
limit: number,
operator: (document: T) => Promise<unknown>,
): Promise<void> => {
const chunks = _.chunk(documents, limit);

return chunks.reduce((init: any, chunk) => {
return init.then(() => {
return Promise.all(chunk.map((c) => operator(c)));
});
return chunks.reduce<Promise<void>>(async (previousPromise, chunk) => {
await previousPromise;

const operations = chunk.map(operator);

await Promise.all(operations);
}, Promise.resolve());
};

Expand Down
3 changes: 2 additions & 1 deletion template/apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"include": [
"src/**/*",
"src/**/*.json"
"src/**/*.json",
".eslintrc.js"
],
"ts-node": { "transpileOnly": true },
"exclude": []
Expand Down
5 changes: 4 additions & 1 deletion template/apps/web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'tsc'],
env: {
browser: true,
es2021: true,
Expand All @@ -20,6 +20,9 @@ module.exports = {
sourceType: 'module',
},
rules: {
'tsc/config': [2, {
configFile: 'tsconfig.json'
}],
// solve problem with public folder
'import/no-unresolved': [2,
{ ignore: ['public'] },
Expand Down
9 changes: 5 additions & 4 deletions template/apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@
"devDependencies": {
"@babel/core": "7.21.0",
"@storybook/addon-essentials": "7.6.9",
"@storybook/addon-styling-webpack": "0.0.6",
"@storybook/preview-api": "7.6.9",
"@storybook/addon-interactions": "7.6.9",
"@storybook/addon-links": "7.6.9",
"@storybook/addon-onboarding": "^1.0.10",
"@storybook/addon-styling-webpack": "0.0.6",
"@storybook/blocks": "7.6.9",
"@storybook/builder-webpack5": "7.6.10",
"@storybook/nextjs": "7.6.9",
"@storybook/preview-api": "7.6.9",
"@storybook/react": "7.6.9",
"@storybook/test": "7.6.9",
"storybook-dark-mode": "3.0.3",
"@tanstack/eslint-plugin-query": "5.12.1",
"@tanstack/react-query-devtools": "5.13.5",
"@types/mixpanel-browser": "2.38.1",
Expand All @@ -72,17 +71,19 @@
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-next": "13.2.4",
"eslint-plugin-storybook": "0.6.15",
"eslint-plugin-tsc": "2.0.0",
"lint-staged": "13.2.0",
"postcss": "8.4.19",
"postcss-preset-mantine": "1.9.0",
"postcss-simple-vars": "7.0.1",
"storybook": "7.6.9",
"storybook-dark-mode": "3.0.3",
"style-loader": "3.3.1",
"typescript": "4.9.5"
},
"lint-staged": {
"*.{ts,tsx}": [
"eslint --ext ts --ext tsx --fix"
"eslint --fix"
]
}
}
2 changes: 1 addition & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"turbo-start": "turbo run development --filter=\"./apps/*\" --filter=\"./packages/*\" --filter=\"!react-email-client\" ",
"docker": "bash ./bin/start.sh",
"start": "bash ./bin/run-all.sh",
"prepare": "husky install"
"prepare": "cd .. husky install"
},
"devDependencies": {
"husky": "8.0.3",
Expand Down
19 changes: 15 additions & 4 deletions template/packages/mailer/emails/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import React, { FC, ReactNode } from 'react';
import { Body, Container, Html, Preview, Section, Tailwind } from '@react-email/components';
import { Body, Container, Html, Preview, Section, Tailwind, TailwindProps } from '@react-email/components';

import Head from './components/head';
import Header from './components/header';
import BodyFooter from './components/body-footer';
import MainFooter from './components/main-footer';

import config from '../tailwind.config';

interface LayoutProps {
children: ReactNode;
previewText?: string;
}

const tailwindConfig: TailwindProps['config'] = {
theme: {
fontFamily: {
sans: ['Roboto', 'sans-serif'],
},
extend: {
colors: {
background: '#efeef1',
},
},
},
};

const Layout:FC<LayoutProps> = ({ children, previewText }) => (
<Html>
<Head />

{previewText && <Preview>{previewText}</Preview>}

<Tailwind config={config}>
<Tailwind config={tailwindConfig}>
<Body className="bg-background py-8">
<Container className="mx-auto rounded-md bg-white">
<Header />
Expand Down
41 changes: 28 additions & 13 deletions template/packages/mailer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion template/packages/mailer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"devDependencies": {
"@types/node": "20.3.1",
"@types/react": "18.2.13",
"@types/react": "18.2.55",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"eslint": "^8.0.1",
"eslint-config-airbnb": "19.0.4",
Expand Down
13 changes: 0 additions & 13 deletions template/packages/mailer/tailwind.config.js

This file was deleted.

Loading