Skip to content

Commit 63bd135

Browse files
committed
feat: eslint
- added the monorepo eslint rules in the `@repo/common` and `@repo/trpc` packages - replaced the usage of `z.prettifyError` in the `errorFormatter` filter of the api by the `formatZodError` utility function of the `@repo/common` package
1 parent 23205c6 commit 63bd135

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

apps/api/src/filters/errorFormatter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { z, ZodError } from "zod";
1+
import { ZodError } from "zod";
22
import { EnvService } from "src/env/env.service";
33

4+
import { formatZodError } from "@repo/common/formatZodError";
45
import { TRPCError } from "@trpc/server";
56

67
type ErrorShape = {
@@ -30,7 +31,7 @@ const errorFormatter = (
3031
if (error.cause && isZodError(error.cause)) {
3132
return {
3233
...shape,
33-
message: z.prettifyError(error.cause),
34+
message: formatZodError(error.cause),
3435
data: {
3536
code: shape.data.code,
3637
httpStatus: shape.data.httpStatus,
@@ -48,7 +49,7 @@ const errorFormatter = (
4849
if (isZodError(error)) {
4950
return {
5051
...shape,
51-
message: z.prettifyError(error),
52+
message: formatZodError(error),
5253
data: {
5354
code: shape.data.code,
5455
httpStatus: shape.data.httpStatus,

packages/common/eslint.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import commonLintConfig from "@repo/eslint-config/lint";
2+
3+
export default [
4+
...commonLintConfig,
5+
{
6+
ignores: ["**/eslint.config.ts", "./dist/**"],
7+
},
8+
];

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"scripts": {
1818
"dev": "tsc --watch",
19-
"lint": "eslint .",
19+
"lint": "eslint . --fix",
2020
"build": "tsc"
2121
},
2222
"files": [

packages/common/src/formatZodError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ZodError, z } from "zod";
1+
import { z, ZodError } from "zod";
22

33
export const formatZodError = (error: ZodError) => {
44
return z.prettifyError(error);

packages/common/src/getPeriodResolution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { PeriodResolution } from "./types-schemas";
21
import { differenceInDays } from "date-fns";
32

3+
import { PeriodResolution } from "./types-schemas";
4+
45
const getPeriodResolution = (
56
start: string | Date,
6-
end: string | Date,
7+
end: string | Date
78
): PeriodResolution => {
89
const numberOfDays = Math.abs(differenceInDays(start, end));
910
const periodResolution =

packages/trpc/eslint.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import commonLintConfig from "@repo/eslint-config/lint";
2+
3+
export default [
4+
...commonLintConfig,
5+
{
6+
ignores: ["**/eslint.config.ts", "./dist/**"],
7+
},
8+
];

packages/trpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"types": "./dist/index.d.ts",
88
"scripts": {
99
"dev": "tsc --watch",
10-
"lint": "eslint .",
10+
"lint": "eslint . --fix",
1111
"build": "tsc"
1212
},
1313
"files": [

0 commit comments

Comments
 (0)