Replace String() calls with .toString()/.toLocaleString() per ast-grep rule
- Add formatError() helper in CLI to safely handle unknown error types - Add uniqueTestId() helper for generating unique test identifiers - Replace String(id) with id.toString() for database ID conversions - Replace String(n) with n.toLocaleString() for user-facing number formatting - Fix TypeScript errors in test files (undefined checks, unused variables) - Update lint commands to include ast-grep scanning Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -95,11 +95,11 @@ export function formatRelativeDate(
|
||||
return "Yesterday";
|
||||
}
|
||||
if (diffDays < 7) {
|
||||
return `${String(diffDays)} days ago`;
|
||||
return `${diffDays.toLocaleString()} days ago`;
|
||||
}
|
||||
if (diffDays < 30) {
|
||||
const weeks = Math.floor(diffDays / 7);
|
||||
return weeks === 1 ? "1 week ago" : `${String(weeks)} weeks ago`;
|
||||
return weeks === 1 ? "1 week ago" : `${weeks.toLocaleString()} weeks ago`;
|
||||
}
|
||||
|
||||
// For older dates, show the actual date
|
||||
|
||||
@@ -16,3 +16,4 @@ export {
|
||||
truncateAllTables,
|
||||
} from "./test-db.js";
|
||||
export { withTestTransaction } from "./test-transaction.js";
|
||||
export { uniqueTestId } from "./test-utils.js";
|
||||
|
||||
@@ -9,6 +9,7 @@ import { join } from "node:path";
|
||||
import { createDb } from "@reviq/db";
|
||||
import { sql } from "kysely";
|
||||
import pg from "pg";
|
||||
import { uniqueTestId } from "./test-utils.js";
|
||||
|
||||
const { Client } = pg;
|
||||
|
||||
@@ -192,7 +193,7 @@ export async function runMigrations(): Promise<void> {
|
||||
if (exitCode !== 0) {
|
||||
const stderr = await new Response(proc.stderr).text();
|
||||
throw new Error(
|
||||
`Migration failed with code ${String(exitCode)}: ${stderr}`,
|
||||
`Migration failed with code ${exitCode.toString()}: ${stderr}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -224,7 +225,7 @@ export async function createTestUser(
|
||||
isSuperuser: boolean;
|
||||
}> = {},
|
||||
): Promise<{ id: number; email: string }> {
|
||||
const email = overrides.email ?? `test-${String(Date.now())}@example.com`;
|
||||
const email = overrides.email ?? `test-${uniqueTestId()}@example.com`;
|
||||
|
||||
const result = await db
|
||||
.insertInto("users")
|
||||
|
||||
15
packages/testing/test-helpers/src/test-utils.ts
Normal file
15
packages/testing/test-helpers/src/test-utils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Test utility functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates a unique test ID using timestamp and random string.
|
||||
* Useful for creating unique emails, slugs, tokens, etc. in tests.
|
||||
*
|
||||
* @example
|
||||
* const email = `user-${uniqueTestId()}@example.com`
|
||||
* const slug = `org-${uniqueTestId()}`
|
||||
*/
|
||||
export function uniqueTestId(): string {
|
||||
return `${Date.now().toString()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ export const hashPassword = async (password: string): Promise<string> => {
|
||||
const saltB64 = toBase64(salt.buffer);
|
||||
const hashB64 = toBase64(derivedBits);
|
||||
|
||||
return `$${ALGORITHM}$${String(ITERATIONS)}$${saltB64}$${hashB64}`;
|
||||
return `$${ALGORITHM}$${ITERATIONS.toString()}$${saltB64}$${hashB64}`;
|
||||
};
|
||||
|
||||
export const verifyPassword = async (
|
||||
|
||||
Reference in New Issue
Block a user