Skip to content

Commit 265c8e1

Browse files
committed
Refactor linting and formatting configurations across applications: Updated package.json scripts to utilize Turbo for linting and formatting, consolidated ignore patterns in .oxlintrc.json, and removed obsolete ESLint configuration file. Enhanced code consistency by standardizing import statements and improving formatting in various files.
1 parent e06835d commit 265c8e1

File tree

15 files changed

+171
-230
lines changed

15 files changed

+171
-230
lines changed

.github/workflows/node.js.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: ["main", "develop"]
8+
branches: ['main', 'develop']
99
pull_request:
10-
branches: ["main", "develop"]
10+
branches: ['main', 'develop']
1111

1212
jobs:
1313
build:

.oxlintrc.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@
99
"typescript/no-floating-promises": "error",
1010
"typescript/no-unsafe-assignment": "warn"
1111
},
12-
"ignorePatterns": [
13-
"*.spec.ts",
14-
"*.test.ts",
15-
"apps/api/test/**",
16-
"apps/api/eslint.config.mjs"
17-
]
12+
"ignorePatterns": ["*.spec.ts", "*.test.ts", "apps/api/test/**", "apps/api/eslint.config.mjs"]
1813
}

apps/api/eslint.config.mjs

Lines changed: 0 additions & 35 deletions
This file was deleted.

apps/api/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
"test:watch": "jest --watch",
2929
"typecheck": "tsc --noEmit",
3030
"openapi:generate": "tsx src/utils/openapi.ts",
31-
"lint": "oxlint",
32-
"depcheck": "depcheck"
31+
"depcheck": "depcheck",
32+
"format": "oxfmt",
33+
"lint:fix": "oxlint --fix --fix-suggestions --fix-dangerously .",
34+
"lint": "oxlint --type-aware --type-check ."
3335
},
3436
"dependencies": {
3537
"@aws-sdk/client-s3": "^3.994.0",
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { User } from 'better-auth';
22
import { Transform } from 'class-transformer';
33

4-
const STORAGE_URL =
5-
process.env['STORAGE_URL']?.replace(/\/+$/, '') ?? 'http://localhost:9000';
4+
const STORAGE_URL = process.env['STORAGE_URL']?.replace(/\/+$/, '') ?? 'http://localhost:9000';
65
const STORAGE_BUCKET = process.env['STORAGE_BUCKET_NAME'] ?? 'public';
76

87
export class ActiveUserDto implements User {
@@ -12,8 +11,6 @@ export class ActiveUserDto implements User {
1211
email!: string;
1312
createdAt!: Date;
1413
updatedAt!: Date;
15-
@Transform(({ value }) =>
16-
value ? `${STORAGE_URL}/${STORAGE_BUCKET}/${value}` : null,
17-
)
14+
@Transform(({ value }) => (value ? `${STORAGE_URL}/${STORAGE_BUCKET}/${value}` : null))
1815
image?: string | null;
1916
}

apps/api/src/storage/files.service.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
import { Injectable, NotFoundException } from "@nestjs/common";
2-
import { S3Service } from "./s3.service";
3-
import { createId } from "@paralleldrive/cuid2";
4-
import { DrizzleTransactionClient } from "src/databases/drizzle.provider";
5-
import { files } from "src/databases/drizzle.schema";
6-
import { takeFirstOrThrow } from "src/databases/drizzle.utils";
7-
import { eq } from "drizzle-orm";
8-
import { StorageConfig } from "src/common/config/storage.config";
9-
import { TransactionHost, Transactional } from "@nestjs-cls/transactional";
1+
import { Injectable, NotFoundException } from '@nestjs/common';
2+
import { S3Service } from './s3.service';
3+
import { createId } from '@paralleldrive/cuid2';
4+
import { DrizzleTransactionClient } from 'src/databases/drizzle.provider';
5+
import { files } from 'src/databases/drizzle.schema';
6+
import { takeFirstOrThrow } from 'src/databases/drizzle.utils';
7+
import { eq } from 'drizzle-orm';
8+
import { StorageConfig } from 'src/common/config/storage.config';
9+
import { TransactionHost, Transactional } from '@nestjs-cls/transactional';
1010

1111
@Injectable()
1212
export class FilesService {
1313
constructor(
1414
private readonly s3Service: S3Service,
1515
private readonly txHost: TransactionHost<DrizzleTransactionClient>,
16-
private readonly storageConfig: StorageConfig
16+
private readonly storageConfig: StorageConfig,
1717
) {}
1818

1919
@Transactional()
2020
async create(file: Express.Multer.File) {
2121
const storageKey = createId();
22-
const test = "test";
2322

2423
await this.s3Service.putObject({
2524
bucketName: this.storageConfig.bucketName,
2625
key: storageKey,
27-
file: file.buffer
26+
file: file.buffer,
2827
});
2928

3029
try {
@@ -34,15 +33,15 @@ export class FilesService {
3433
name: file.originalname,
3534
mimeType: file.mimetype,
3635
sizeBytes: file.size,
37-
storageKey
36+
storageKey,
3837
})
3938
.returning()
4039
.then(takeFirstOrThrow);
4140
} catch (error) {
4241
// Compensate uploaded object if the DB write fails.
4342
await this.s3Service.deleteObject({
4443
bucketName: this.storageConfig.bucketName,
45-
key: storageKey
44+
key: storageKey,
4645
});
4746
throw error;
4847
}
@@ -52,24 +51,24 @@ export class FilesService {
5251
async update(key: string, file: Express.Multer.File) {
5352
const fileRecord = await this.txHost.tx.query.files.findFirst({
5453
where: {
55-
storageKey: key
56-
}
54+
storageKey: key,
55+
},
5756
});
58-
if (!fileRecord) throw new NotFoundException("File not found");
57+
if (!fileRecord) throw new NotFoundException('File not found');
5958

6059
// Keep the storage key stable and replace object contents/metadata in-place.
6160
await this.s3Service.putObject({
6261
bucketName: this.storageConfig.bucketName,
6362
key,
64-
file: file.buffer
63+
file: file.buffer,
6564
});
6665

6766
return this.txHost.tx
6867
.update(files)
6968
.set({
7069
name: file.originalname,
7170
mimeType: file.mimetype,
72-
sizeBytes: file.size
71+
sizeBytes: file.size,
7372
})
7473
.where(eq(files.storageKey, key))
7574
.returning()
@@ -80,7 +79,7 @@ export class FilesService {
8079
async delete(key: string) {
8180
await this.s3Service.deleteObject({
8281
bucketName: this.storageConfig.bucketName,
83-
key
82+
key,
8483
});
8584
await this.txHost.tx.delete(files).where(eq(files.storageKey, key));
8685
}

apps/api/src/users/users.controller.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Controller,
3-
UseInterceptors,
4-
UploadedFile,
5-
Body,
6-
Patch,
7-
} from '@nestjs/common';
1+
import { Controller, UseInterceptors, UploadedFile, Body, Patch } from '@nestjs/common';
82
import { UsersService } from './users.service';
93
import { FileInterceptor } from '@nestjs/platform-express';
104
import { ApiConsumes } from '@nestjs/swagger';

apps/api/src/utils/openapi.ts

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { OpenAPIObject } from "@nestjs/swagger";
2-
import chalk from "chalk";
3-
import * as fsSync from "node:fs";
4-
import * as fs from "node:fs/promises";
5-
import openapiTS from "openapi-typescript";
6-
import * as ts from "typescript";
1+
import { OpenAPIObject } from '@nestjs/swagger';
2+
import chalk from 'chalk';
3+
import * as fsSync from 'node:fs';
4+
import * as fs from 'node:fs/promises';
5+
import openapiTS from 'openapi-typescript';
6+
import * as ts from 'typescript';
77

8-
const DEFAULT_OUTPUT_DIR = "./generated";
9-
const DEFAULT_FILENAME = "openapi.d.ts";
8+
const DEFAULT_OUTPUT_DIR = './generated';
9+
const DEFAULT_FILENAME = 'openapi.d.ts';
1010

1111
interface OpenApiSpec {
1212
document: OpenAPIObject;
@@ -18,79 +18,64 @@ type TransformableSchema = {
1818
nullable?: boolean;
1919
};
2020

21-
export async function generateOpenApiSpecs(
22-
specs: OpenApiSpec[]
23-
): Promise<void> {
21+
export async function generateOpenApiSpecs(specs: OpenApiSpec[]): Promise<void> {
2422
if (specs.length === 0) {
25-
console.log(chalk.yellow("⚠️ No OpenAPI specs provided"));
23+
console.log(chalk.yellow('⚠️ No OpenAPI specs provided'));
2624
return;
2725
}
2826

2927
console.log(chalk.blue(`🔄 Generating ${specs.length} OpenAPI spec(s)...`));
3028

3129
// Generate all specs in parallel
32-
const results = await Promise.allSettled(
33-
specs.map(spec => generateSingleSpec(spec))
34-
);
30+
const results = await Promise.allSettled(specs.map((spec) => generateSingleSpec(spec)));
3531

3632
// Process results
37-
const successful = results.filter(
38-
result => result.status === "fulfilled"
39-
).length;
40-
const failed = results.filter(result => result.status === "rejected").length;
33+
const successful = results.filter((result) => result.status === 'fulfilled').length;
34+
const failed = results.filter((result) => result.status === 'rejected').length;
4135

4236
if (failed > 0) {
4337
console.log(chalk.yellow(`⚠️ ${failed} spec(s) failed to generate`));
4438
results.forEach((result, index) => {
45-
if (result.status === "rejected") {
39+
if (result.status === 'rejected') {
4640
console.error(
4741
chalk.red(
48-
`❌ Spec ${index + 1} (${specs[index]?.fileName || DEFAULT_FILENAME}): ${result.reason}`
49-
)
42+
`❌ Spec ${index + 1} (${specs[index]?.fileName || DEFAULT_FILENAME}): ${result.reason}`,
43+
),
5044
);
5145
}
5246
});
5347
}
5448

5549
if (successful > 0) {
56-
console.log(
57-
chalk.green(`✅ ${successful} OpenAPI spec(s) generated successfully`)
58-
);
50+
console.log(chalk.green(`✅ ${successful} OpenAPI spec(s) generated successfully`));
5951
}
6052

6153
if (failed === specs.length) {
62-
throw new Error("All OpenAPI specs failed to generate");
54+
throw new Error('All OpenAPI specs failed to generate');
6355
}
6456
}
6557

6658
async function generateSingleSpec(spec: OpenApiSpec): Promise<void> {
6759
const fileName = spec.fileName || DEFAULT_FILENAME;
6860
const filePath = `${DEFAULT_OUTPUT_DIR}/${fileName}`;
6961

70-
const BLOB = ts.factory.createTypeReferenceNode(
71-
ts.factory.createIdentifier("Blob")
72-
); // `Blob`
62+
const BLOB = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Blob')); // `Blob`
7363
const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull()); // `null`
7464

7565
try {
7666
// Generate new OpenAPI types content
77-
const ast = await openapiTS(
78-
spec.document as Parameters<typeof openapiTS>[0],
79-
{
80-
transform(schemaObject: TransformableSchema) {
81-
if (schemaObject.format === "binary") {
82-
return schemaObject.nullable
83-
? ts.factory.createUnionTypeNode([BLOB, NULL])
84-
: BLOB;
85-
}
86-
return undefined; // Use default transformation for other schema objects
67+
const ast = await openapiTS(spec.document as Parameters<typeof openapiTS>[0], {
68+
transform(schemaObject: TransformableSchema) {
69+
if (schemaObject.format === 'binary') {
70+
return schemaObject.nullable ? ts.factory.createUnionTypeNode([BLOB, NULL]) : BLOB;
8771
}
88-
}
89-
);
72+
return undefined; // Use default transformation for other schema objects
73+
},
74+
});
9075
const sourceFile = ts.factory.createSourceFile(
9176
ast as ts.Statement[],
9277
ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
93-
ts.NodeFlags.None
78+
ts.NodeFlags.None,
9479
);
9580
const newContents = ts
9681
.createPrinter({ newLine: ts.NewLineKind.LineFeed })
@@ -107,36 +92,30 @@ async function generateSingleSpec(spec: OpenApiSpec): Promise<void> {
10792
} catch (error) {
10893
const errorMessage = error instanceof Error ? error.message : String(error);
10994
throw new Error(`Failed to generate ${fileName}: ${errorMessage}`, {
110-
cause: error
95+
cause: error,
11196
});
11297
}
11398
}
11499

115-
async function hasContentChanged(
116-
filePath: string,
117-
newContents: string
118-
): Promise<boolean> {
100+
async function hasContentChanged(filePath: string, newContents: string): Promise<boolean> {
119101
if (!fsSync.existsSync(filePath)) {
120102
return true;
121103
}
122104

123105
try {
124-
const existingContents = await fs.readFile(filePath, "utf8");
106+
const existingContents = await fs.readFile(filePath, 'utf8');
125107
return existingContents !== newContents;
126108
} catch {
127109
return true;
128110
}
129111
}
130112

131-
async function writeOpenApiFile(
132-
filePath: string,
133-
contents: string
134-
): Promise<void> {
113+
async function writeOpenApiFile(filePath: string, contents: string): Promise<void> {
135114
// Ensure directory exists
136115
await fs.mkdir(DEFAULT_OUTPUT_DIR, { recursive: true });
137116

138117
// Write file
139-
await fs.writeFile(filePath, contents, "utf8");
118+
await fs.writeFile(filePath, contents, 'utf8');
140119
}
141120

142121
// Convenience function for single spec (backward compatibility)

apps/web/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"build": "vite build",
88
"preview": "vite preview",
99
"test": "vitest run",
10-
"lint": "oxlint",
11-
"typecheck": "tsc --noEmit"
10+
"lint": "oxlint --type-aware --type-check .",
11+
"lint:fix": "oxlint --fix --fix-suggestions --fix-dangerously .",
12+
"typecheck": "tsc --noEmit",
13+
"format": "oxfmt"
1214
},
1315
"dependencies": {
1416
"@base-ui/react": "^1.2.0",

apps/web/src/lib/devtools/drizzle-studio-devtools.panel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export function DrizzleStudioDevtoolsPanel() {
22
return (
33
// eslint-disable-next-line react/iframe-missing-sandbox -- Dev-only tool, needs full access
44
<iframe
5-
src="https://local.drizzle.studio/"
6-
title="Drizzle Studio"
7-
style={{ width: "100%", height: "100%", border: "none" }}
5+
src='https://local.drizzle.studio/'
6+
title='Drizzle Studio'
7+
style={{ width: '100%', height: '100%', border: 'none' }}
88
/>
99
);
1010
}

0 commit comments

Comments
 (0)